Computer Chess Club Archives




Subject: Re: Parallel algorithms in chess programming

Author: Gian-Carlo Pascutto

Date: 08:01:07 04/18/01

Go up one level in this thread

On April 18, 2001 at 09:32:57, Josť Carlos wrote:
>Mmm, I was talking about this (checking legal moves) from the beginning.
>Actually the biggest problems occur when you are already in check, and have to
>decide if the move you've just done eliminates the check.
>But I'm begining to suspect I'm missing something anywhere. I'll rethink all
>of this.

What you are missing is that you only have to optimize 90% of your program.
Ignoring the 'difficult' 10% can be done until you get payed to work on
it, which isn't true for many of us.

This is what I did in Sjeng, after I had same problem as you have:

For InCheck (this lets us know if a move was a check):

when making a move, check if it could put the king in check. This can
happen either via a direct check or a discovered one. For a direct
check, the worst than can happen is that you have to scan from the
source to the destination field. In many cases you have to do nothing,
for example because the piece moved was a bishop and it is not on same
diagonal as the king.
For a discovered check, the king has to be on the same rank, file or
diagonal as the source field. If so, you have to trace behind the source
field. (In Sjeng I trace starting from king...only just now realized
that isnt needed :)

Optimizations are possible here by for example noting that a non-capture
pawn move can never discover a file check. Or that if a bishop is on same
diagonal as king, and it moves along that diagonal, then it can't be a
discovered check either.

For CheckLegalMove (tests if we are in check after moving):

if we were in check before the move, do an expensive full incheck test.
I suspect that is what you are using now. You can optimize this case
by figuring out which moves can't possible have stopped the check, though
I don't do this yet.
if we were not in check, check if we could have put ourselves in check.
This is only possible via a discovered check or a king move. For the king
moves I just use the full incheck test again. The others work similar to
the InCheck routine.


This page took 0.16 seconds to execute

Last modified: Thu, 07 Jul 11 08:48:38 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.