Set clock on rewind

pull/2701/head
Isaac Levy 2017-03-27 12:13:21 -04:00
parent 41778f9053
commit 7e539780ae
3 changed files with 11 additions and 2 deletions

@ -1 +1 @@
Subproject commit da5e5f17421d44f7712ffb74a5c02a9084e58573
Subproject commit 7925f518b7173cd5bc3496a309cb9b3f6940ef8e

View File

@ -740,6 +740,8 @@ case class ClockHistory(
def get(color: Color): Vector[Centis] =
if (color.white) white else black
def last(color: Color) = get(color).lastOption
// first state is of the color that moved first.
def bothClockStates(firstMoveBy: Color): Vector[Centis] =
Sequence.interleave(

View File

@ -21,6 +21,13 @@ object Rewind {
val rewindedHistory = rewindedGame.board.history
val rewindedSituation = rewindedGame.situation
val rewindedPlayedTurns = rewindedGame.turns - game.startedAtTurn
val newClock = game.clock map (_.takeback) map { clk =>
game.clockHistory.fold(clk)(history => {
Color.all.foldLeft(clk) { (clk, color) =>
history.last(color).fold(clk)(t => clk.setRemainingCentis(color, t.value))
}
})
}
def rewindPlayer(player: Player) = player.copy(proposeTakebackAt = 0)
def rewindedPlayerMoves(color: Color) = {
if (color == game.startColor) (rewindedPlayedTurns + 1) / 2
@ -51,7 +58,7 @@ object Rewind {
)),
crazyData = rewindedSituation.board.crazyData,
status = game.status,
clock = game.clock map (_.takeback)
clock = newClock
)
Progress(game, newGame, List(
newGame.clock.map(Event.Clock.apply),