Author: Russell Reagan
Date: 20:12:59 01/26/04
Go up one level in this thread
On January 26, 2004 at 01:10:12, Mathieu Pagé wrote: >Hi, > >I always thought that it was not necessary to check for check after each moves. >My supposition was that if the search visit a node were the side that has just >move is still in check the opposite side will take the king and this will lead >to a so bad position (king captured) that the search (minimax, AB things) would >just reject that move. > >But this causes my engines to play illegal moves in the end of the games when he >is losing. When he see that is king will be captured whatever he do (mate in X) >he will sometimes play moves that leaves him in check. > >I know how to correct that problem at the root. I just have to check for check >after each root move and if it leaves my engines king in check I just reject >that move. But if I do this at every moves of the search, this will slow down >the process. > >Can I avoid calling this at every nodes ? It is possible to create a very efficient illegal move detection routine. If you use a board representation like 0x88 (or any system where there are unique square relationships), you can cut out all of the work most of the time. Consider this position: [D]4k3/8/8/8/8/3N4/8/4K3 w - - 0 1 Using well known 0x88 tricks, you can quickly determine that the a piece moving from d3 could never be pinned to the king on e1, so you can assume that the move was legal. [D]4k3/8/8/8/8/2N5/8/4K3 w - - 0 1 Now if the knight was on c3 (above), then it is possible that the knight might be pinned, so you will have to do a search. Luckily, the 0x88 tricks come in handy here as well. You can figure out which direction you need to scan with one table lookup, then you just scan from c3 to b4 and a5 and see if there is a black bishop or queen pinning the knight. So at most you will never have to scan more than 6 squares. That is the general case, and you will still have to be careful with the special cases, such as en passant moves and castling moves. For instance: Black just played f7f5, so white would normally be able to capture the black pawn en passant. [D]3k4/8/8/2r1Pp1K/8/8/8/8 w - - 0 1 But white cannot capture the black pawn because that would leave white in check. So you have to watch out for things like that.
This page took 0 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.