Advertisement

Chess move generation

Started by July 07, 2014 04:04 AM
0 comments, last by alvaro 10 years, 4 months ago

I'm creating a chess engine using bitboards and I have a question about legal move generation. Here is what I came up with so far:

- Check if the king is in check

- If not, then generate all possible moves for all pieces

-Check each king move/en-passant/castling/absolute pin (if they result in check after the move is made, remove from list of legal moves)

-If no legal moves, then stalemate

-If in check, generate king moves, captures of piece giving check, or blocks

-Check each move (if they result in check after the move is made, remove from the list of legal moves)

-If no legal moves, then checkmate

I have 2 questions:

1) Is this an efficient way to generate a list of legal moves, or is there a better way?

2) Right now I plan to see if the white king is in check by seeing if the result of (white_king & black_attacks) is 0 or not. Is there a more efficient way to do this?

Thanks!

I don't use legal move generation myself, but I think you should be able to check if a move is legal without making it, at least in most cases. For instance, if you recognize what pieces are pinned, moving a non-pinned piece should always be legal (if you are not in check, of course). Since that is by far the most common case, you should be able to save a lot of time with that rule.

You should have an automated perft test, to make sure you don't introduce bugs.

This topic is closed to new replies.

Advertisement