fix UCI memo with games from position

This commit is contained in:
Thibault Duplessis 2013-10-02 10:46:59 +02:00
parent b35446c8ae
commit 97149e2e50
3 changed files with 8 additions and 7 deletions

View file

@ -12,7 +12,7 @@ trait Ai {
for {
fen game.variant.exotic ?? { GameRepo initialFen game.id }
pgn PgnRepo get game.id
uciMoves uciMemo.get(game) map (_ mkString " ")
uciMoves uciMemo.get(game, pgn) map (_ mkString " ")
moveStr move(uciMoves, fen, level)
uciMove (UciMove(moveStr) toValid "Wrong bestmove: " + moveStr).future
result (game.toChess withPgnMoves pgn)(uciMove.orig, uciMove.dest).future

@ -1 +1 @@
Subproject commit 01ffb2ba6fea914327e69364e0730157047237cc
Subproject commit 702e909163cd9f6f79b5a44f5def0a6ebd1a55ba

View file

@ -20,10 +20,12 @@ final class UciMemo(ttl: Duration) {
memo.put(game.id, uciMoves.toVector)
}
def get(game: Game): Fu[Vector[String]] =
Option(memo getIfPresent game.id).filter(_.size == game.turns) match {
def get(game: Game, pgn: String): Fu[Vector[String]] =
Option(memo getIfPresent game.id) filter { moves
moves.size == (pgn.count(' '==) + 1)
} match {
case Some(moves) fuccess(moves)
case _ compute(game) addEffect { set(game, _) }
case _ compute(game, pgn) addEffect { set(game, _) }
}
def drop(game: Game, nb: Int) {
@ -31,9 +33,8 @@ final class UciMemo(ttl: Duration) {
memo.put(game.id, current.take(current.size - nb))
}
private def compute(game: Game): Fu[Vector[String]] = for {
private def compute(game: Game, pgn: String): Fu[Vector[String]] = for {
fen game.variant.exotic ?? { GameRepo initialFen game.id }
pgn PgnRepo get game.id
uciMoves UciDump(pgn, fen, game.variant).future
} yield uciMoves.toVector
}