undo method

void undo()

Undo the last move and restore the previous state.

Implementation

void undo() {
  if (history.isNotEmpty) {
    String currentFEN = toFEN();
    // If the last state in history is identical to the current state,
    // remove it so that we actually restore a different state.
    if (history.last == currentFEN) {
      history.removeLast();
      return;
    }
    redoHistory.add(currentFEN);
    initFEN(history.removeLast());
  }
}