Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Legal moves generation

Author: Russell Reagan

Date: 15:12:56 04/28/02

Go up one level in this thread


If it must be done in a scripting language, then it can certainly be done. It
will be a little slower, but still not a problem. You need to write a
pseudo-legal move generator (one that will generate moves for pieces that are
pinned and can't move and one that will generate moves that move the king into
check), and then you need to write a function to determine if a square is
attacked. Use the function that determines if a square is attacked by the
opposing side to write a function that tells if the king is in check (just see
if the square the king is on is attacked). Then you need a make move and an undo
move function, then you need to try all of the moves, make them, see if the king
is in check, if the king is in check, it's an illegal move so you need to remove
it from the list.

The other option is to write a function that generates legal moves that are 100%
legal. For example, you would have to write a function that determine if a piece
is pinned or not. If the piece is pinned then you don't generate any moves for
it. Sometimes a piece can be partially pinned. For example:

[D]8/8/5k2/2q5/8/4B3/8/6K1 w - - 0 1

In this position the bishop cannot move along the c1-h6 diagonal, but it can
move along the g1-a7 diagonal. I've never written a function to determine if a
piece is pinned, but it wouldn't be that much harder. Just more special cases.
If you used this method you would also need to write the function to determine
if a square was attacked and make sure that the king didn't move into check, so
you would basically have to do this check anyway, so the first way is probably
better.

Russell



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.