Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: inCheck moveGen

Author: Russell Reagan

Date: 12:53:19 12/05/03

Go up one level in this thread


On December 05, 2003 at 15:20:58, Dieter Buerssner wrote:

>I cannot answer your concrete question. But a similar problem can be an
>Incheck-routine. To detect, if you are in check, two approaches can be: a) Loop
>over the opponent pieces, and see, if one checks my K; b) "Generate" (reverse)
>moves for the king square, assuming it can be any sort of piece, and see, if it
>will hit an opponent piece of the right kind. With a full board, b) can be
>faster, while with an empty board a) can be faster. I change between those two
>alternatives depending on material on board (also, at root I do some more
>heuristics, like seeing if the K has a "good" pawn shield in front of him -
>which will favor b). For my engine, this was a bit faster in general, than just
>using one method all the time. The engine decides about the method to use for
>Incheck() after each root move (by setting a function pointer).

I'm sure you know this, but it is worth mentioning that you can save a lot of
the work most of the time by using an 0x88-style attack detection. A lot of
times you can tell right away that the previous move could not possibly have
been illegal by comparing the offset of the king square with the 'from' square
of the move and using that in your attack lookup table. Even then, if you have
to loop, you only have to loop in one direction. This is for checking that a
pseudo-legal move was not illegal after making the move. I guess you could do
similar things for an in-check routine. Like if you know that the king wasn't in
check, then you can use the move squares to determine if it is possible that he
came into check and avoid looping altogether.

Also, using a function pointer also adds some extra overhead (I think as much as
a mispredicted branch, or maybe a little more). But you said it is faster
overall so I guess it is worth it.



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.