Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Detecting stalemate with a pseudo-legal movegenerator?

Author: Uri Blass

Date: 17:42:08 11/11/05

Go up one level in this thread


On November 11, 2005 at 20:14:21, Frederik Tack wrote:

>On November 11, 2005 at 19:50:18, Ryan B. wrote:
>
>>On November 11, 2005 at 19:13:06, Frederik Tack wrote:
>>
>>>A few months ago, i started writing a chess engine in Delphi. I chose to use a
>>>pseudo-legal movegenerator for performance reasons. In order to detect a
>>>checkmate, i just check if the king is captured and this works fine. I'm now
>>>trying to figure out how to detect a stalemate, but i haven't found an easy way
>>>to do this yet. The problem is that when the king is captured, the program is
>>>already two plies deeper in the search tree then the node where a possible
>>>stalemate could have happened.
>>>So far, the best idea i have come up with is the following : In opening or
>>>mid-game positions, the chances of a stalemate are pretty much non-existing. So
>>>for opening and mid-game, i can use the pseudo-legal move generator without a
>>>problem. For end-games, i could switch to a legal move generator. The only
>>>difficulty here is to find to best moment in game to switch to the legal move
>>>generator.
>>>I wonder if any1 else has had the same problem and found an easy way to detect
>>>stalemates with a pseudo-legal move generator? If so, any suggestion would be
>>>most welcome.
>>
>>I do not think thing waiting until king capture is a good way to detect CM.  I
>>am sure it will help a lot later to have an incheck function and it is a good
>>idea to know how many legal moves you have.  if (incheck && legal_moves == 0) CM
>>else if (legal_moves == 0) draw.
>
>I already have an 'incheck' function. I use it to check if it is allowed to
>castle for example. The problem is that when i use 'incheck' to produce legal
>moves instead of pseudo-legal moves, i get a 30% performance decrease. That's a
>lot for detecting a simple stalemate. Especially since a stalemate can only
>happen in endgame positions. I haven't encountered any other problems that would
>require legal move generation to get resolved. So i really would like to keep on
>using pseudo-legal moves. Tx for the reply anyway.


In this case you may try to improve the speed of your incheck function.
Note that you need to use it only after making moves and not after generating
the list of pseudo-legal moves.

knowing if the king is under threat is important and it is not expensive because
you only need to check for every new move if it threats check based on the from
square and the to square(for example you know that a2-a3 does not threat check
if the opponent black king is at e8 and it is also easy to find that it is legal
in case that the white king is at e1 because the only way it can be illegal is
if the king is in check or a2 is pinned and checking that a2 is not pinned to e1
is easy and I assume that you know that the king is not under threat when you
generate a2-a3).

Note that you should have a special function to generate moves when the king is
under threat.

Note that I have a legal move generator but I have other reasons for it and not
speed and what I suggest can be done with pseudo move generator when you have
legal move generator only when the king is under threat.

Note also that
I think that 30% performance is not very important at the weak level of most
engines.

The difference between Fruit2.1 and Fruit2.2 is clearly more than 30% speed
improvement so my opinion is that as long as your program is weaker than
fruit2.1 you should not care much about optimizations that can give you only 30%
speed improvement.

Uri



This page took 0.01 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.