move method

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', <- where the 'move' is a move object (additional to :'h8', fields are ignored) promotion: 'q', }) 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(move) {
  Move? move_obj;
  final moves = generate_moves();

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

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

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

  make_move(move_obj);

  return true;
}