drop UCI moves on takebacks
This commit is contained in:
parent
4e6b45dc90
commit
c72a21b249
|
@ -26,9 +26,9 @@ final class UciMemo(ttl: Duration) {
|
|||
case _ ⇒ compute(game) addEffect { set(game, _) }
|
||||
}
|
||||
|
||||
def delete(game: Game) {
|
||||
// TODO figure out a best way
|
||||
memo.put(game.id, Vector.empty)
|
||||
def drop(game: Game, nb: Int) {
|
||||
val current = Option(memo getIfPresent game.id) | Vector.empty
|
||||
memo.put(game.id, current.take(current.size - nb))
|
||||
}
|
||||
|
||||
private def compute(game: Game): Fu[Vector[String]] = for {
|
||||
|
|
|
@ -144,7 +144,8 @@ final class Env(
|
|||
private lazy val hijack = new Hijack(HijackTimeout)
|
||||
|
||||
private lazy val takebacker = new Takebacker(
|
||||
messenger = messenger)
|
||||
messenger = messenger,
|
||||
uciMemo = uciMemo)
|
||||
|
||||
private def notifyMove(gameId: String, fen: String, lastMove: Option[String]) {
|
||||
hub.socket.hub ! lila.socket.actorApi.Fen(gameId, fen, lastMove)
|
||||
|
|
|
@ -31,9 +31,8 @@ private[round] final class Player(
|
|||
} yield game.update(newChessGame, move, blur) -> move).prefixFailuresWith(playerId + " - ").future flatMap {
|
||||
case ((progress, pgn), move) ⇒
|
||||
(GameRepo save progress) >>
|
||||
PgnRepo.save(pov.gameId, pgn) >>- {
|
||||
if (pov.game.hasAi) uciMemo.add(pov.game, move)
|
||||
} >>-
|
||||
PgnRepo.save(pov.gameId, pgn) >>-
|
||||
(pov.game.hasAi ! uciMemo.add(pov.game, move)) >>-
|
||||
notifyProgress(progress) >>
|
||||
progress.game.finished.fold(
|
||||
moveFinish(progress.game, color) map { progress.events ::: _ }, {
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
package lila.round
|
||||
|
||||
import lila.game.{ GameRepo, Game, PgnRepo, Pov, Rewind, Event, Progress }
|
||||
import lila.game.{ GameRepo, Game, PgnRepo, UciMemo, Pov, Rewind, Event, Progress }
|
||||
|
||||
private[round] final class Takebacker(messenger: Messenger) {
|
||||
private[round] final class Takebacker(
|
||||
messenger: Messenger,
|
||||
uciMemo: UciMemo) {
|
||||
|
||||
def yes(pov: Pov): Fu[Events] = pov match {
|
||||
case Pov(game, _) if pov.opponent.isProposingTakeback ⇒ single(game)
|
||||
|
@ -39,7 +41,10 @@ private[round] final class Takebacker(messenger: Messenger) {
|
|||
|
||||
private def single(game: Game): Fu[Events] = extras(game.id) flatMap {
|
||||
case (fen, pgn) ⇒ Rewind(game, pgn, fen).future flatMap {
|
||||
case (progress, newPgn) ⇒ PgnRepo.save(game.id, newPgn) >> save(progress)
|
||||
case (progress, newPgn) ⇒
|
||||
PgnRepo.save(game.id, newPgn) >>-
|
||||
uciMemo.drop(game, 1)
|
||||
save(progress)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -51,7 +56,7 @@ private[round] final class Takebacker(messenger: Messenger) {
|
|||
case (progress, newPgn) ⇒ (prog1 withGame progress.game, newPgn)
|
||||
}
|
||||
(prog2, pgn2) = second
|
||||
_ ← PgnRepo.save(game.id, pgn2)
|
||||
_ ← PgnRepo.save(game.id, pgn2) >>- uciMemo.drop(game, 2)
|
||||
events ← save(prog2)
|
||||
} yield events
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue