Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Are there any programs that do NOT check for legality after the fact?

Author: KarinsDad

Date: 15:43:01 07/07/00

Go up one level in this thread


On July 07, 2000 at 15:25:45, Robert Hyatt wrote:

>On July 07, 2000 at 12:25:10, KarinsDad wrote:
>
>>Other than mine?
>>
>>One of the bugs having my program play itself on Winboad discovered was that the
>>king would move out of check into a square that was not originally covered by
>>check, but is now an illegal square due to the checking piece now attacking it.
>>For example:
>>
>>[D]1Q4k1/6pp/8/8/8/8/8/6K1 b
>>
>>In this position, white just played Qb8+. Black then plays the illegal move Kh8
>>since it determines which squares are not attacked by white using the
>>PieceAttacks structure (which is just a set of bits indicating which squares are
>>attacked by which piece in a given position).
>>
>>Now, I am adding code to avoid this problem, but without generating ALL moves
>>ahead of time and checking for legality after illegal moves have been generated,
>>does anyone else have a program which does this up front? And if so, is there a
>>slick way of doing it (my method is kind of clumsy)?
>>
>>KarinsDad :)
>
>
>With bitmaps this is easy to do...  just make sure you move the king in any
>direction _but_ the direction the check comes from.  Then Kh8 would not be
>generated at all...


This is basically what I am doing to correct it, but I put the correction into
the PieceAttacks creation routine as opposed to the Move Generation routine.

I added variables for two illegal squares to my Position Information structure.
When the PieceAttacks structure gets created, the code determines whether there
are any sliding pieces attacking the king and then creates an illegal square
behind the king in that direction. The reason for 2 such squares is that a
double discovered check could result in a rook and a bishop/queen checking the
king simultaneously (and eliminating 2 squares).

The reason I did not like this solution is that I had to put about 12 lines of
code into about a dozen places to set these squares (I hardwired it since a
macro or function would have required about 5 variables passed in, I might have
to bite the bullet and create a macro after all) and I had to then check these
squares in my move generator. I was hoping there was an easier way.

I initially thought about doing it in the Move Generation routine, but realized
that some of the temporary data that I already create in the PieceAttacks
creation routine would then have to be re-created in Move Generation and I
didn't want to do that.

KarinsDad :)



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.