move method Null safety

bool move(
  1. dynamic move
)

The move function can be called with in the following parameters: .move('Nxb7') where 'move' is a case-sensitive SAN string .move({ from: 'h7', to :'h8', promotion: 'q', }) where the 'move' is a move object or it can be called with a Move object It returns true if the move was made, or false if it could not be.

Implementation

bool move(dynamic move) {
  Move? moveObj;
  List<Move> moves = generateMoves();

  if (move is String) {
    /* convert the move string to a move object */
    for (int i = 0; i < moves.length; i++) {
      if (move == moveToSan(moves[i])) {
        moveObj = moves[i];
        break;
      }
    }
  } else if (move is Map) {
    /* convert the pretty move object to an ugly move object */
    for (int i = 0; i < moves.length; i++) {
      if (move['from'] == moves[i].fromAlgebraic &&
          move['to'] == moves[i].toAlgebraic &&
          moves[i].promotion == null) {
        moveObj = moves[i];
        break;
      } else if (move['from'] == moves[i].fromAlgebraic &&
          move['to'] == moves[i].toAlgebraic &&
          move['promotion'] == moves[i].promotion!.name) {
        moveObj = moves[i];
        break;
      }
    }
  } else if (move is Move) {
    moveObj = move;
  }

  /* failed to find move */
  if (moveObj == null) {
    return false;
  }

  /* need to make a copy of move because we can't generate SAN after the
     * move is made
     */

  makeMove(moveObj);

  return true;
}