It's very trivial to incrementally update a table of counts for each piece type, but I'm not having luck thinking of a way to incrementally update a fast lookup map of piece positions.
I ask because I'm doing profiling on a new experimental 0x88 engine I'm tinkering on and it's showing really high cost in the top level move generation function, which does nothing but scan the board for pieces of the desired color and then calls individual generators for each piece type. The profiler I'm using (valgrind) does not include the cost of sub calls in the reported cost of a given function so it's just the board scan that's killing it
Here's some pseudo C code:
Code: Select all
int pieces = pieceCount[color];
for (int sqr = A1; (pieces > 0) && (sqr <= H8); ++sqr) {
if (sqr & 0x88) {
sqr += 7;
}
else switch (board[sqr]) {
case (color|Pawn): --pieces; generatePawnMoves(sqr); break;
case (color|Knight): --pieces; generateKnightMoves(sqr); break;
case (color|Bishop): --pieces; generateBishopMoves(sqr); break;
case (color|Rook): --pieces; generateRookMoves(sqr); break;
case (color|Queen): --pieces; generateQueenMoves(sqr); break;
case (color|King): --pieces; generateKingMoves(sqr); break;
}
}