1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-07-11 11:39:15 +00:00

Better clarify how pieceList[] and index[] work

Rearrange the code a bit to be more self-documenting.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
Marco Costalba 2009-08-17 23:12:38 +01:00
parent fbec55e52e
commit 693b38a5e7
2 changed files with 18 additions and 12 deletions

View file

@ -710,7 +710,6 @@ void Position::do_move(Move m, StateInfo& newSt, Bitboard dcCandidates) {
};
memcpy(&newSt, st, sizeof(ReducedStateInfo));
newSt.capture = NO_PIECE_TYPE;
newSt.previous = st;
st = &newSt;
@ -788,9 +787,11 @@ void Position::do_move(Move m, StateInfo& newSt, Bitboard dcCandidates) {
if (pt == KING)
kingSquare[us] = to;
// Update piece lists
pieceList[us][pt][index[from]] = to;
// Update piece lists, note that index[from] is not updated and
// becomes stale. This works as long as index[] is accessed just
// by known occupied squares.
index[to] = index[from];
pieceList[us][pt][index[to]] = to;
// If the moving piece was a pawn do some special extra work
if (pt == PAWN)
@ -832,11 +833,13 @@ void Position::do_move(Move m, StateInfo& newSt, Bitboard dcCandidates) {
pieceCount[us][PAWN]--;
pieceCount[us][promotion]++;
// Update piece lists
pieceList[us][PAWN][index[from]] = pieceList[us][PAWN][pieceCount[us][PAWN]];
index[pieceList[us][PAWN][index[from]]] = index[from];
pieceList[us][promotion][pieceCount[us][promotion] - 1] = to;
// Update piece lists, move the last pawn at index[to] position
// and shrink the list. Add a new promotion piece to the list.
Square lastPawnSquare = pieceList[us][PAWN][pieceCount[us][PAWN]];
index[lastPawnSquare] = index[to];
pieceList[us][PAWN][index[lastPawnSquare]] = lastPawnSquare;
index[to] = pieceCount[us][promotion] - 1;
pieceList[us][promotion][index[to]] = to;
// Partially revert hash keys update
key ^= zobrist[us][PAWN][to] ^ zobrist[us][promotion][to];
@ -902,7 +905,6 @@ void Position::do_capture_move(Bitboard& key, PieceType capture, Color them, Squ
assert(to == st->epSquare);
assert(relative_rank(opposite_color(them), to) == RANK_6);
assert(piece_on(to) == EMPTY);
assert(piece_on(from) == piece_of_color_and_type(opposite_color(them), PAWN));
assert(piece_on(capsq) == piece_of_color_and_type(them, PAWN));
board[capsq] = EMPTY;
@ -934,9 +936,10 @@ void Position::do_capture_move(Bitboard& key, PieceType capture, Color them, Squ
// Update piece count
pieceCount[them][capture]--;
// Update piece list
pieceList[them][capture][index[capsq]] = pieceList[them][capture][pieceCount[them][capture]];
index[pieceList[them][capture][index[capsq]]] = index[capsq];
// Update piece list, move the last piece at index[capsq] position
Square lastPieceSquare = pieceList[them][capture][pieceCount[them][capture]];
index[lastPieceSquare] = index[capsq];
pieceList[them][capture][index[lastPieceSquare]] = lastPieceSquare;
// Reset rule 50 counter
st->rule50 = 0;
@ -957,6 +960,9 @@ void Position::do_castle_move(Move m) {
Color us = side_to_move();
Color them = opposite_color(us);
// Reset capture field
st->capture = NO_PIECE_TYPE;
// Find source squares for king and rook
Square kfrom = move_from(m);
Square rfrom = move_to(m); // HACK: See comment at beginning of function

View file

@ -342,7 +342,7 @@ private:
// Piece lists
Square pieceList[2][8][16]; // [color][pieceType][index]
int index[64];
int index[64]; // [square]
// Other info
Square kingSquare[2];