Skip to content

Commit

Permalink
update for game pgn extraction - wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Oct 12, 2012
1 parent f2ac385 commit c07fddf
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 32 deletions.
4 changes: 2 additions & 2 deletions app/game/DbGame.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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) ::
Expand Down Expand Up @@ -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 {
Expand Down
59 changes: 31 additions & 28 deletions app/round/Hand.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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((
Expand Down
3 changes: 2 additions & 1 deletion app/setup/Processor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion todo
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,4 @@ not possible to copy the link URL invite when using a iOS device. Can this be ea
search bug http:https://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

0 comments on commit c07fddf

Please sign in to comment.