updateTime method

void updateTime(
  1. Duration timeSpentForMove,
  2. PieceColor player
)

Deducts timeSpentForMove from remaining time of the player and adds timeControl.incrementPerMove to it.

Additionally, the timesSpentPerMove and timeOfLastMove are also updated.

Implementation

void updateTime(Duration timeSpentForMove, insanichess.PieceColor player) {
  timesSpentPerMove.add(timeSpentForMove);

  if (player == insanichess.PieceColor.white) {
    remainingTimeWhite =
        remainingTimeWhite - timeSpentForMove + timeControl.incrementPerMove;
  } else {
    remainingTimeBlack =
        remainingTimeBlack - timeSpentForMove + timeControl.incrementPerMove;
  }

  timeOfLastMove = DateTime.now();
}