Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: (pseudo)code for legal-movegenerator

Author: Landon Rabern

Date: 08:54:29 04/14/03

Go up one level in this thread


On April 14, 2003 at 02:40:13, Tim Foden wrote:

>On April 13, 2003 at 18:38:03, Landon Rabern wrote:
>
>>On April 13, 2003 at 12:22:15, Martin Bauer wrote:
>>
>>>Hi all,
>>>
>>>I am looking for an easy to understand code how to generate only legal moves
>>>when king is in check. I think there must be many optimizations when king is in
>>>check...
>>>
>>>Language C, Pascal or Basic like or psedocode. I want to see the principles of
>>>generating legal moves.
>>>
>>>Bye
>>>
>>>Martin
>>
>>This is what I do currently in Betsy when in check to generate moves.
>>
>>First find all the squares the king can move to that are not occupied by your
>>own pieces.  This is quick with bitBoards, just:
>>
>>bitBoard escapeSquares=kingMoves[board->blackKing]&(~board->blackPieces);
>>
>>now see which of these squares are attacked by the enemy, store in bitBoard
>>attacked.
>>
>>Then the legal king moves are:
>>
>>toMap=escapeSquares&(~attacked);
>>
>>If there was more than one enemey checking the king, then these are the only
>>legal moves and we are done.
>
>Just a quick question... What about the square opposite of the direction from a
>sliding attacker?
>
>For instance...
>
>[d]8/8/k7/8/8/R7/3K4/8 b - - 0 1
>Do you generate a king move to a7, or not?  :)
>
>Cheers, Tim.

I I think I forgot to say.  When I do:
>>now see which of these squares are attacked by the enemy, store in bitBoard
>>attacked.

I remove the king before calculating which squares are attacked.

Regards,

Landon



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.