Did someone mention the GNUChess move Generator?
Posted: Mon Nov 12, 2007 7:35 pm
Yep!
Since the GNUChess move generator was mentioned, here it is,
translated to the 'Crafty' type philosophy.
The upside is only two do-loops rather than three.
The downside is it requires a lot more data to drive it.
Unlike the GNUChess rendition, this version uses a 128
element board so some 0x88 tricks may be used elsewhere.
The board pointed at by *tblPtr stores next-squares in the left half
and the next-square for the next direction is in the right half.
To get from the left half to the right half just add 8 to the
to-square before getting the next to-square.
Once again, this is the entire move generator for all the pieces
(remember, non captures non promotions, only) including castling.
Edit: Rather than adding 8 to the to-square you can have two pointers, but that would increase register pressure and you might not need it anyway
And it is very, very fast!
Since the GNUChess move generator was mentioned, here it is,
translated to the 'Crafty' type philosophy.
The upside is only two do-loops rather than three.
The downside is it requires a lot more data to drive it.
Unlike the GNUChess rendition, this version uses a 128
element board so some 0x88 tricks may be used elsewhere.
The board pointed at by *tblPtr stores next-squares in the left half
and the next-square for the next direction is in the right half.
To get from the left half to the right half just add 8 to the
to-square before getting the next to-square.
Code: Select all
// Non Promotion Moves only, No Captures - a la Crafty
// NOT BITBOARD
void GenMoves() {
s32 fs, ts, type, vic;
u32 *tblPtr;
u64 pieces;
pieces = picesOfColor[wtm];
do {
fs = FirstBit64(pieces);
pieces &= clrBit64(fs);
type = board[fs];
tblPtr = tblPtrs[type][fs];
ts = *(tblPtr + fs);
do {
vic = board[ts];
if(vic) ts += 8;
else Link(type, fs, ts);
} while((ts = *(tblPtr + ts)) != STOP);
} while (pieces);
}
Once again, this is the entire move generator for all the pieces
(remember, non captures non promotions, only) including castling.
Edit: Rather than adding 8 to the to-square you can have two pointers, but that would increase register pressure and you might not need it anyway
And it is very, very fast!