Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: How have you implemented In-check-function?

Author: Bas Hamstra

Date: 13:21:12 11/25/99

Go up one level in this thread


On November 25, 1999 at 08:09:49, Jari Huikari wrote:

>On November 24, 1999 at 16:54:36, Dan Newman wrote:
>
>>The first chess program I wrote (about 4 years ago) generated only legal
>>moves.  Initially 80% of the cpu time was taken by the in-check detection
>>code.
>
>1. When in-check not used and illegal move tried:
>Program sees that king will be captured, and king-capture gives penalty
>of 10000 points? Or what?

If in-check detection is costly for your datastructures, cheapest way is to
ignore illegal moves and watch for every capture if the king is captured. If so,
you return simply mate. Same for search and qsearch.

To prevent illegal moves actually being played in the game, you do the costly in
check detection only at the root: check for every move if it leaves the king in
check. If so, skip that move. If at the root there are no moves left it's either
mate (when king is in check) or draw (stalemate).

>2. Is in-check necessarily so slow? How do you detect it? I do this
>still very crudely, but I think there is many helping rules, that one
>can conclude that certain moves can't be illegal.

That all depends on your datastructures. For most programs it is not cheap. You
simply have to know all attacks to the kingsquare. So you have to do some
looping stuff. Unless you keep your attacks up to date every move anyway.

Regards,
Bas Hamstra.








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.