update for game pgn extraction - wip

pull/83/head
Thibault Duplessis 2012-10-13 01:05:57 +02:00
parent f2ac385890
commit c07fddfd42
4 changed files with 35 additions and 32 deletions

View File

@ -116,7 +116,7 @@ case class DbGame(
def update(
game: Game,
move: Move,
blur: Boolean = false): Progress = {
blur: Boolean = false): (Progress, String) = {
val (history, situation) = (game.board.history, game.situation)
val events =
Event.possibleMoves(game.situation, White) ::
@ -167,7 +167,7 @@ case class DbGame(
)).fold(Color.all map Event.ReloadTable, Nil)
}
Progress(this, updated, finalEvents)
Progress(this, updated, finalEvents) -> game.pgnMoves
}
def updatePlayer(color: Color, f: DbPlayer DbPlayer) = color match {

View File

@ -43,35 +43,38 @@ final class Hand(
newChessGameAndMove g2.toChess(orig, dest, promotion, lag)
(newChessGame, move) = newChessGameAndMove
} yield g2.update(newChessGame, move, blur)).prefixFailuresWith(povRef + " - ").fold(
e Future(failure(e)),
progress if (progress.game.finished) (for {
_ gameRepo save progress
finishEvents finisher.moveFinish(progress.game, color)
events = progress.events ::: finishEvents
} yield playResult(events, progress)).toFuture
else if (progress.game.player.isAi && progress.game.playable) for {
initialFen progress.game.variant.standard.fold(
io(none[String]),
gameRepo initialFen progress.game.id).toFuture
pgnString (pgnRepo get povRef.gameId).toFuture
aiResult ai().play(progress.game, pgnString, initialFen)
eventsAndFen aiResult.fold(
err Future(failure(err)), {
case (newChessGame, move) (for {
progress2 io {
progress flatMap { _.update(newChessGame, move) }
e Future(failure(e)), {
case (progress, pgn) if (progress.game.finished) (for {
_ gameRepo save progress
_ pgnRepo.save(povRef.gameId, pgn)
finishEvents finisher.moveFinish(progress.game, color)
events = progress.events ::: finishEvents
} yield playResult(events, progress)).toFuture
else if (progress.game.player.isAi && progress.game.playable) for {
initialFen progress.game.variant.standard.fold(
io(none[String]),
gameRepo initialFen progress.game.id).toFuture
aiResult ai().play(progress.game, pgn.pp, initialFen)
eventsAndFen aiResult.fold(
err Future(failure(err)), {
case (newChessGame, move) {
val (prog2, pgn2) = progress.game.update(newChessGame, move)
val progress2 = progress flatMap { _ prog2 }
(for {
_ gameRepo save progress2
_ pgnRepo.save(povRef.gameId, pgn2)
finishEvents finisher.moveFinish(progress2.game, !color)
events = progress2.events ::: finishEvents
} yield playResult(events, progress2)).toFuture
}
_ gameRepo save progress2
finishEvents finisher.moveFinish(progress2.game, !color)
events = progress2.events ::: finishEvents
} yield playResult(events, progress2)).toFuture
}): PlayResult
} yield eventsAndFen
else (for {
_ gameRepo save progress
events = progress.events
} yield playResult(events, progress)).toFuture
)
}): PlayResult
} yield eventsAndFen
else (for {
_ gameRepo save progress
_ pgnRepo.save(povRef.gameId, pgn)
events = progress.events
} yield playResult(events, progress)).toFuture
})
}
private def playResult(events: List[Event], progress: Progress) = success((

View File

@ -42,8 +42,9 @@ final class Processor(
pgnString pgnRepo get game.id
aiResult { ai().play(game, pgnString, initialFen) map (_.err) }.toIo
(newChessGame, move) = aiResult
progress = game.update(newChessGame, move)
(progress, pgn) = game.update(newChessGame, move)
_ gameRepo save progress
_ pgnRepo.save(game.id, pgn)
} yield pov withGame progress.game
)
} yield pov2

1
todo
View File

@ -51,5 +51,4 @@ not possible to copy the link URL invite when using a iOS device. Can this be ea
search bug http://en.lichess.org/games/search?players.a=&players.b=&players.winner=&eloMin=&eloMax=&hasAi=&aiLevelMin=&aiLevelMax=&variant=&mode=1&opening=&turnsMin=&turnsMax=&durationMin=&durationMax=&status=35&dateMin=&dateMax=&sort.field=tu&sort.order=asc
==== deploy
remove space in lastMove
upgrade to game3