perft method Null safety

dynamic perft(
  1. int depth
)

Implementation

perft(int depth) {
  List<Move> moves = generateMoves({'legal': false});
  var nodes = 0;
  var color = turn;

  for (var i = 0, len = moves.length; i < len; i++) {
    makeMove(moves[i]);
    if (!kingAttacked(color)) {
      if (depth - 1 > 0) {
        int child_nodes = perft(depth - 1);
        nodes += child_nodes;
      } else {
        nodes++;
      }
    }
    undoMove();
  }
  return nodes;
}