update for game pgn extraction - wip
This commit is contained in:
parent
f2ac385890
commit
c07fddfd42
|
@ -116,7 +116,7 @@ case class DbGame(
|
||||||
def update(
|
def update(
|
||||||
game: Game,
|
game: Game,
|
||||||
move: Move,
|
move: Move,
|
||||||
blur: Boolean = false): Progress = {
|
blur: Boolean = false): (Progress, String) = {
|
||||||
val (history, situation) = (game.board.history, game.situation)
|
val (history, situation) = (game.board.history, game.situation)
|
||||||
val events =
|
val events =
|
||||||
Event.possibleMoves(game.situation, White) ::
|
Event.possibleMoves(game.situation, White) ::
|
||||||
|
@ -167,7 +167,7 @@ case class DbGame(
|
||||||
)).fold(Color.all map Event.ReloadTable, Nil)
|
)).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 {
|
def updatePlayer(color: Color, f: DbPlayer ⇒ DbPlayer) = color match {
|
||||||
|
|
|
@ -43,35 +43,38 @@ final class Hand(
|
||||||
newChessGameAndMove ← g2.toChess(orig, dest, promotion, lag)
|
newChessGameAndMove ← g2.toChess(orig, dest, promotion, lag)
|
||||||
(newChessGame, move) = newChessGameAndMove
|
(newChessGame, move) = newChessGameAndMove
|
||||||
} yield g2.update(newChessGame, move, blur)).prefixFailuresWith(povRef + " - ").fold(
|
} yield g2.update(newChessGame, move, blur)).prefixFailuresWith(povRef + " - ").fold(
|
||||||
e ⇒ Future(failure(e)),
|
e ⇒ Future(failure(e)), {
|
||||||
progress ⇒ if (progress.game.finished) (for {
|
case (progress, pgn) ⇒ if (progress.game.finished) (for {
|
||||||
_ ← gameRepo save progress
|
_ ← gameRepo save progress
|
||||||
finishEvents ← finisher.moveFinish(progress.game, color)
|
_ ← pgnRepo.save(povRef.gameId, pgn)
|
||||||
events = progress.events ::: finishEvents
|
finishEvents ← finisher.moveFinish(progress.game, color)
|
||||||
} yield playResult(events, progress)).toFuture
|
events = progress.events ::: finishEvents
|
||||||
else if (progress.game.player.isAi && progress.game.playable) for {
|
} yield playResult(events, progress)).toFuture
|
||||||
initialFen ← progress.game.variant.standard.fold(
|
else if (progress.game.player.isAi && progress.game.playable) for {
|
||||||
io(none[String]),
|
initialFen ← progress.game.variant.standard.fold(
|
||||||
gameRepo initialFen progress.game.id).toFuture
|
io(none[String]),
|
||||||
pgnString ← (pgnRepo get povRef.gameId).toFuture
|
gameRepo initialFen progress.game.id).toFuture
|
||||||
aiResult ← ai().play(progress.game, pgnString, initialFen)
|
aiResult ← ai().play(progress.game, pgn.pp, initialFen)
|
||||||
eventsAndFen ← aiResult.fold(
|
eventsAndFen ← aiResult.fold(
|
||||||
err ⇒ Future(failure(err)), {
|
err ⇒ Future(failure(err)), {
|
||||||
case (newChessGame, move) ⇒ (for {
|
case (newChessGame, move) ⇒ {
|
||||||
progress2 ← io {
|
val (prog2, pgn2) = progress.game.update(newChessGame, move)
|
||||||
progress flatMap { _.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
|
}): PlayResult
|
||||||
finishEvents ← finisher.moveFinish(progress2.game, !color)
|
} yield eventsAndFen
|
||||||
events = progress2.events ::: finishEvents
|
else (for {
|
||||||
} yield playResult(events, progress2)).toFuture
|
_ ← gameRepo save progress
|
||||||
}): PlayResult
|
_ ← pgnRepo.save(povRef.gameId, pgn)
|
||||||
} yield eventsAndFen
|
events = progress.events
|
||||||
else (for {
|
} yield playResult(events, progress)).toFuture
|
||||||
_ ← gameRepo save progress
|
})
|
||||||
events = progress.events
|
|
||||||
} yield playResult(events, progress)).toFuture
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private def playResult(events: List[Event], progress: Progress) = success((
|
private def playResult(events: List[Event], progress: Progress) = success((
|
||||||
|
|
|
@ -42,8 +42,9 @@ final class Processor(
|
||||||
pgnString ← pgnRepo get game.id
|
pgnString ← pgnRepo get game.id
|
||||||
aiResult ← { ai().play(game, pgnString, initialFen) map (_.err) }.toIo
|
aiResult ← { ai().play(game, pgnString, initialFen) map (_.err) }.toIo
|
||||||
(newChessGame, move) = aiResult
|
(newChessGame, move) = aiResult
|
||||||
progress = game.update(newChessGame, move)
|
(progress, pgn) = game.update(newChessGame, move)
|
||||||
_ ← gameRepo save progress
|
_ ← gameRepo save progress
|
||||||
|
_ ← pgnRepo.save(game.id, pgn)
|
||||||
} yield pov withGame progress.game
|
} yield pov withGame progress.game
|
||||||
)
|
)
|
||||||
} yield pov2
|
} yield pov2
|
||||||
|
|
1
todo
1
todo
|
@ -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
|
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
|
==== deploy
|
||||||
remove space in lastMove
|
|
||||||
upgrade to game3
|
upgrade to game3
|
||||||
|
|
Loading…
Reference in a new issue