Move Generation (Pseudo-Legal)
Strategy
The MoveGen module generates “pseudo-legal” moves. A move is pseudo-legal if:
- The piece can physically reach the destination square according to its move pattern.
- The destination is either empty or occupied by an enemy piece.
- The move does not pass through other pieces (except for the Knight).
Note: King safety is handled in the Legality layer.
Stepwise Logic
- Iterate: Find all pieces belonging to the current color.
- Scan: For each piece, calculate all possible target squares.
- Leaping (Knight/King): Static offsets.
- Sliding (Rook/Bishop/Queen): Incremental steps until blocked.
- Pawn: Conditional steps (push, double-push, capture, en-passant).
- Filter: Remove moves that target
OFF_BOARDsquares (corners in 14x14). - Collect: Return a list of
Moveobjects.
Optimization: The Piece List
Instead of scanning all 196 squares on the 14x14 board, the engine maintains a Piece List. This is an array of square indices containing active pieces. This allows the generator to skip 80% of empty squares on every turn.