Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Comment on solving illegal moves, plz!

Author: James Swafford

Date: 17:10:23 02/11/01

Go up one level in this thread


On February 11, 2001 at 18:20:57, Pham Minh Tri wrote:

>Hi,
>I know there are three ways to deal with illegal moves (side to move is in check
>after taking those moves):
>1) Generate legal moves only.
>2) Check and cut off illegal moves before taking a move.
>3) Take a move without checking it and let program captures the king in the next
>ply (if it is an illegal move).
>
>I am wondering which one is better (faster). Is there any other way?
>Any comments would be appreciated.
>
>Pham

Generating only legal moves obviously requires more code, and therefore
takes more time.  On the other hand, you don't have to do a post-move test
for a "king attack".

I think most folks do the latter - just gen "pseudolegal" moves and do a
post-move test for an attacked king.  (If you just moved, but your king
is in check, your move was illegal.)

There may be cases where generating strictly legal moves will save
a bit of time.  At one time Bob did this when in check.  His reasoning
was that when in check, most moves will be illegal, so using a subroutine
designed specifically for generating check evasions would be more
efficient than generating a lot of illegal moves, cycling through most
of them, and "kicking back a ply" after the post-move test revealed
the move wasn't legal. I assume he still does this, but I'm not sure.

As usual, there is one way full proof way for you to find out for sure
what works best with your code. :-)

Out of curiousity, what type of move generation are you using?
(i.e. 0x88,  bitboards, ...?)

--
James






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.