Skip to content

Commit

Permalink
switch clock color on move even if not started
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Mar 23, 2016
1 parent 55f4b88 commit a3cc878
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions src/main/scala/Game.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,11 @@ case class Game(
}

def apply(move: Move): Game = {
val newTurns = turns + 1
val newGame = copy(
board = move.finalizeAfter,
player = !player,
turns = newTurns,
clock = clock map {
case c: RunningClock => c step move.lag
case c: PausedClock if (newTurns - startedAtTurn) == 2 => c.start.switch
case c => c
}
turns = turns + 1,
clock = applyClock(move.lag)
)
val pgnMove = pgn.Dumper(situation, move, newGame.situation)
newGame.copy(pgnMoves = pgnMoves.isEmpty.fold(
Expand All @@ -45,23 +40,24 @@ case class Game(
}

def applyDrop(drop: Drop): Game = {
val newTurns = turns + 1
val newGame = copy(
board = drop.finalizeAfter,
player = !player,
turns = newTurns,
clock = clock map {
case c: RunningClock => c step drop.lag
case c: PausedClock if (newTurns - startedAtTurn) == 2 => c.start.switch
case c => c
}
turns = turns + 1,
clock = applyClock(drop.lag)
)
val pgnMove = pgn.Dumper(situation, drop, newGame.situation)
newGame.copy(pgnMoves = pgnMoves.isEmpty.fold(
List(pgnMove),
pgnMoves :+ pgnMove))
}

private def applyClock(lag: FiniteDuration) = clock map {
case c: RunningClock => c step lag
case c: PausedClock if (turns - startedAtTurn) == 1 => c.start.switch
case c => c.switch
}

def apply(uci: Uci.Move): Valid[(Game, Move)] = apply(uci.orig, uci.dest, uci.promotion)
def apply(uci: Uci.Drop): Valid[(Game, Drop)] = drop(uci.role, uci.pos)
def apply(uci: Uci): Valid[(Game, MoveOrDrop)] = uci match {
Expand Down

0 comments on commit a3cc878

Please sign in to comment.