Count legal moves
Moderators: hgm, Rebel, chrisw
-
- Posts: 344
- Joined: Wed Sep 23, 2009 5:56 pm
- Location: Germany
Count legal moves
Can I (with a mailbox board representation) count the number of legal moves without generating them?
-
- Posts: 344
- Joined: Wed Sep 23, 2009 5:56 pm
- Location: Germany
Re: Count legal moves
Sorry, I meant the number of legal moves if the king is in check, which is of course an important difference.
-
- Posts: 4052
- Joined: Thu May 15, 2008 9:57 pm
- Location: Berlin, Germany
- Full name: Sven Schüle
Re: Count legal moves
metax wrote:Can I (with a mailbox board representation) count the number of legal moves without generating them?
It depends upon which other information you have besides knowing that the king is in check. For instance, if you also knowmetax wrote:Sorry, I meant the number of legal moves if the king is in check, which is of course an important difference.
- whether it is double check or not,
- the location of the checking piece (in case of single check), and
- the location(s) of all friendly pieces being pinned to your king,
then you can implement such a counting algorithm. For instance:
a) In case of double check, count all squares adjacent to friendly king that are not occupied by a friendly piece and not attacked by an enemy piece. For this kind of "is attacked" check, consider the friendly king as "transparent".
b) In case of single check, do the same as a) but add:
b1) the number of moves that can capture the checking piece with a piece that is not pinned (don't forget e.p. capture, and think twice when deciding about legality of e.p. capture move!);
b2) if the checking piece is a slider: the number of moves that block the line between checking piece and friendly king, provided the blocking piece is currently not pinned.
Hope that helps a little bit.
Sven