Skip to content

Commit

Permalink
Tweak game resume code
Browse files Browse the repository at this point in the history
  • Loading branch information
WandererXII committed Mar 11, 2024
1 parent 00e89aa commit 7d78e17
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions modules/game/src/main/Game.scala
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,9 @@ case class Game(
def resume =
if (!paused) this
else {
val newShogi = sealedUsi.flatMap(u => shogi(u).toOption).getOrElse(shogi)
val sealedUsiApplied =
newShogi.usis.lastOption.exists(_.some == sealedUsi && plies < newShogi.plies)
val pSeconds = (nowSeconds - movedAt.getSeconds).toInt atLeast 0
val shogiAfterSealedUsi = sealedUsi.flatMap(u => shogi(u).toOption)
val newShogi = shogiAfterSealedUsi.getOrElse(shogi)
val pSeconds = (nowSeconds - movedAt.getSeconds).toInt atLeast 0
val resumed = copy(
// clock was already updated, make sure proper color is set
shogi = newShogi.copy(clock = clock.map(_.copy(color = newShogi.situation.color).start)),
Expand All @@ -199,7 +198,7 @@ case class Game(
movedAt = DateTime.now
)

if (sealedUsiApplied) resumed
if (shogiAfterSealedUsi.isDefined) resumed
else
resumed.copy(
binaryMoveTimes = binaryMoveTimes.map { binary =>
Expand Down

0 comments on commit 7d78e17

Please sign in to comment.