Skip to content

Commit

Permalink
eagerly compute new game clock history
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Feb 7, 2018
1 parent ea8ded9 commit 0efd785
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions modules/game/src/main/Game.scala
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,13 @@ case class Game(
)
else player

// This must be computed eagerly
// because it depends on the current time
val newClockHistory = for {
clk <- game.clock
ch <- clockHistory
} yield ch.record(turnColor, clk)

val updated = copy(
whitePlayer = copyPlayer(whitePlayer),
blackPlayer = copyPlayer(blackPlayer),
Expand All @@ -183,10 +190,7 @@ case class Game(
} :+ Centis(nowCentis - movedAt.getCentis).nonNeg
}
},
loadClockHistory = () => for {
clk <- game.clock
ch <- clockHistory
} yield ch.record(turnColor, clk),
loadClockHistory = () => newClockHistory,
status = game.situation.status | status,
movedAt = DateTime.now
)
Expand Down

0 comments on commit 0efd785

Please sign in to comment.