Author: Scott Gasch
Date: 11:03:26 01/16/03
Go up one level in this thread
On January 16, 2003 at 09:53:08, Ricardo Gibert wrote:
>Message http://www.talkchess.com/forums/1/message.html?277508 brought to mind
>the following question:
>
>What is the simplest and/or most compact move generator possible for chess with
>little regard to efficiency?
>
>The general tendency is to put great weight on efficiency, but it occurs to me
>that for both pedgogical and debugging purposes, the question is a worthwhile
>one.
0x88 style is both simple to read/write and pretty efficient. Apologies for any
typos/bugs below:
void
GenerateKnightMoves(POSITION *pos, COORD c)
{
static int iDelta[9] =
{ -33, -31, -18, -14, +14, +18, +31, +33, 0 };
COORD cTo;
unsigned u = 0;
do
{
cTo = c + iDelta[u];
AddMove(c, cTo);
u++;
}
while(iDelta[u] != 0);
}
void
GenerateBishopMoves(POSITION *pos, COORD c)
{
COORD cTo;
PIECE pBish = pos->pSquare[c];
PIECE p;
unsigned u = 0;
static int iDelta[5] = { -17, -15, +15, +17, 0 };
do
{
cTo = c + iDelta[u];
while (ONBOARD(cTo))
{
p = pos->pSquare[cTo];
if (IS_EMPTY(p))
{
AddMove(c, cTo);
}
else
{
if (COLOR(p) != COLOR(pBish)) AddMove(c, cTo);
break;
}
cTo += iDelta[u];
}
u++;
}
while(iDelta[u] != 0);
}
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.