simplifying chess engine minimax by allowing king captures
Hi,
While I was designing the minimax function for my chess engine, I thought about an easier way to determine game states (checkmated, stalemate) and move validation (move into check) - by simply giving the king a high material value, and allow capturing kings. Since the kings are valued so highly, an alpha or beta cutoff will probably occur when king captures happen. Has anyone tried something like this? How well would it work.
Thank you very much
My chess engine Ruy-Lopez does something similar: Moves are not checked for legality (I mean, we don't check if they leave your own king in check), but the move generator will return a special code if a king capture is possible. In that case, the search is stopped and a value of +Infinity is returned. The calling code will convert that to a -Infinity for the other side (the side that played the illegal move). Adding illegal moves with a score of -Infinity doesn't change the game.
Detecting stalemate is a little trickier. You basically need to keep track of whether there has been a legal move or not. If you finish the search and all the moves have returned -Infinity (a variable keeping the maximum value returned so far would do), then you don't have legal moves, and you should return a final score: Draw if you are not in check and -Mate if you are in check.
Notice that for this to work well, you need to pick a value to represent Infinity that is larger that the value that represents Mate (I use 32500 and 32000, because I use 16-bit scores).
Just giving the king a very large material score is not good enough because you can get to a situation where both kings are captured. You need to detect these things during the search, so the first side to mate wins.
Detecting stalemate is a little trickier. You basically need to keep track of whether there has been a legal move or not. If you finish the search and all the moves have returned -Infinity (a variable keeping the maximum value returned so far would do), then you don't have legal moves, and you should return a final score: Draw if you are not in check and -Mate if you are in check.
Notice that for this to work well, you need to pick a value to represent Infinity that is larger that the value that represents Mate (I use 32500 and 32000, because I use 16-bit scores).
Just giving the king a very large material score is not good enough because you can get to a situation where both kings are captured. You need to detect these things during the search, so the first side to mate wins.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement