Jump to content
  • Advertisement
Sign in to follow this  
lazyguy123

Chess move generation

This topic is 1475 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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!

 

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!