Move Generation
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:
But what about the opponents bishop on b8? After capturing the knight on d6, we put ourselves in check.
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:
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
Coming soon...
Validation & Test Positions
1. Perft
Coming soon...
2. Test Positions
Coming soon...