Move Generation

31st March 2026

1. King

As described from the previous page, we can utilize our custom bitwise operations to calculate legal moves from static pieces using pieceLegalMoves & ~ourPieces. Here is an example:

A white chess king surrounded by 2 black pieces and 1 white piece

But what about the opponents bishop on b8? After capturing the knight on d6, we put ourselves in check.

An illegal chess position where the white king is in check after taking the opponents knight

We need to see if the move from the king is in check after we move it. To do this, I applied the easist method: Copy the board position and make the move. If the king is in check, the move is illegal, revert the board position back to its original state:

An illegal chess position where the white king is in check after taking the opponents knight

The image above is the correct solution to solving king attacks. For Pseudo-legal move generation which my Chess Engine uses, moves follow piece rules but may leave the king in check, thus needs extra validation after making the move.

There is a slightly faster way to do this via Attack and Defend Maps and pinned pieces map. By keeping an incremental track of where each piece is, what squares it attacks, and pinned pieces, we can reduce move generation time by a lot. For instance, if our rook is absolutely pinned to our king, we cannot move it, so why bother calculating moves when we know they will all put the king in check, thus being illegal.

2. Pawns

Coming soon...

Adjustments For Speed

N/Ath N/A 2026

Coming soon...

Validation & Test Positions

N/Ath N/A 2026

1. Perft

Coming soon...

2. Test Positions

Coming soon...