Jump to content

  • Log In with Google      Sign In   
  • Create Account

Chess move generation


Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
1 reply to this topic

#1   Members   

130
Like
0Likes
Like

Posted 06 July 2014 - 10:04 PM

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!

 



#2   Members   

20256
Like
0Likes
Like

Posted 07 July 2014 - 01:18 AM

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.




Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.