undo method

  1. @override
PlayedMove? undo()

Undoes the move on the board, removes last element of timesSpentPerMove and updated either remainingTimeWhite or remainingTimeBlack accordingly.

Implementation

@override
insanichess.PlayedMove? undo() {
  insanichess.PlayedMove? undoneMove = super.undo();

  if (undoneMove != null) {
    final Duration lastMoveDuration = timesSpentPerMove.removeLast();
    if (playerOnTurn == insanichess.PieceColor.white) {
      remainingTimeWhite = remainingTimeWhite +
          lastMoveDuration -
          timeControl.incrementPerMove;
    } else {
      remainingTimeBlack = remainingTimeBlack +
          lastMoveDuration -
          timeControl.incrementPerMove;
    }
  }

  return undoneMove;
}