Author: Russell Reagan
Date: 01:49:20 10/30/02
Without using a squares array (ex. int squares[64]), is there any way to find
out what piece is on a square more efficiently using bitboards?
I'm experimenting with using only bitboards and no square array at all, and I'm
wondering if the instructions saved in not having to do the upkeep on the
squares array is enough to make up for this slower routine.
For empty squares and pawns (which accounts for most of the board) it seems like
it would be pretty fast (unless branch misprediction kills it). If you've
experimented with this before I'd like to know your results.
int PieceOnSquare (int square) {
bitboard m = mask[square];
if (whitePieces & m) {
if (whitePawns & m) return WHITE_PAWN;
if (whiteKnights & m) return WHITE_KNIGHT;
if (whiteBishops & m) return WHITE_BISHOP;
if (whiteRooks & m) return WHITE_ROOK;
if (whiteQueens & m) return WHITE_QUEENS;
if (whiteKing & m) return WHITE_KING;
}
if (blackPieces & m) {
if (blackPawns & m) return BLACK_PAWN;
if (blackKnights & m) return BLACK_KNIGHT;
if (blackBishops & m) return BLACK_BISHOP;
if (blackRooks & m) return BLACK_ROOK;
if (blackQueens & m) return BLACK_QUEENS;
if (blackKing & m) return BLACK_KING;
}
return EMPTY;
}
Of course if you're using a square array, this can be as simple as...
#define PieceOnSquare(n) (squares[n])
...just like in Crafty.
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.