I am building a chess engine and I want the engine to directly generate legal moves (instead of pseudo legal + validation).
For this, I am keeping in the chess board structure a bitboard of all attacked squares, all checker squares, all pinned squares by the player who last made the move. Sort of like this'
struct ChessBoard {
Bitboard attacked, checkers, pinned;
...
};
Now I plan for the architecture for this engine to be relatively simple, a function which fill a moves list with legal moves for a chess board, a move maker function, and a search function (well, it's more complex than that). Like the following
void legal_moves(ChessBoard* board, MoveList* list);
void make_move(ChessBoard* board, Move move);
Move search(ChessBoard* board);
// search will call legal_moves() and make_move()
Now the question is, should legal_moves()
update the attacked, checkers, pinned
members or should make_move()
? It should be more performant to let legal_moves()
handle that since it gets the attacks for any piece any way, but my problem with this is that the search function may call legal_moves()
but then not call make_move()
for each move?
Writing this I am leaning towards legal_moves()
but it's kinda complex and I would appreciate input on this.
legal_moves()
. What would you be updating exactly? Do the attackers generated duringlegal_moves()
correspond to the current position or the next? If it is the current, why was this information not up to date? If it is the latter, what legal move do the attackers correspond to?