generateGatingMoves method
Generates a move for each gating possibility for the base
move.
Doesn't include the option where a piece is not gated.
Implementation
List<GatingMove> generateGatingMoves(StandardMove base) {
if (state.gates == null || state.gates!.isEmpty) return [];
int gFile = size.file(base.from);
Square piece = board[base.from];
Colour colour = piece.colour;
if (piece.isEmpty) return [];
if (!(state.virginFiles[colour].contains(gFile))) return [];
List<GatingMove> moves = [];
void addGatingMove(int p) {
moves.add(GatingMove(child: base, dropPiece: p));
if (base.castling) {
moves.add(
GatingMove(child: base, dropPiece: p, dropOnRookSquare: true),
);
}
}
if (variant.gatingMode == GatingMode.flex) {
for (int p in state.gates![colour]) {
addGatingMove(p);
}
} else if (variant.gatingMode == GatingMode.fixed) {
int p = state.gates![colour][gFile];
if (p != 0) {
addGatingMove(p);
}
}
return moves;
}