mirror of
https://github.com/sockspls/badfish
synced 2025-07-11 19:49:14 +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:
parent
fbec55e52e
commit
693b38a5e7
2 changed files with 18 additions and 12 deletions
|
@ -710,7 +710,6 @@ void Position::do_move(Move m, StateInfo& newSt, Bitboard dcCandidates) {
|
||||||
};
|
};
|
||||||
|
|
||||||
memcpy(&newSt, st, sizeof(ReducedStateInfo));
|
memcpy(&newSt, st, sizeof(ReducedStateInfo));
|
||||||
newSt.capture = NO_PIECE_TYPE;
|
|
||||||
newSt.previous = st;
|
newSt.previous = st;
|
||||||
st = &newSt;
|
st = &newSt;
|
||||||
|
|
||||||
|
@ -788,9 +787,11 @@ void Position::do_move(Move m, StateInfo& newSt, Bitboard dcCandidates) {
|
||||||
if (pt == KING)
|
if (pt == KING)
|
||||||
kingSquare[us] = to;
|
kingSquare[us] = to;
|
||||||
|
|
||||||
// Update piece lists
|
// Update piece lists, note that index[from] is not updated and
|
||||||
pieceList[us][pt][index[from]] = to;
|
// becomes stale. This works as long as index[] is accessed just
|
||||||
|
// by known occupied squares.
|
||||||
index[to] = index[from];
|
index[to] = index[from];
|
||||||
|
pieceList[us][pt][index[to]] = to;
|
||||||
|
|
||||||
// If the moving piece was a pawn do some special extra work
|
// If the moving piece was a pawn do some special extra work
|
||||||
if (pt == PAWN)
|
if (pt == PAWN)
|
||||||
|
@ -832,11 +833,13 @@ void Position::do_move(Move m, StateInfo& newSt, Bitboard dcCandidates) {
|
||||||
pieceCount[us][PAWN]--;
|
pieceCount[us][PAWN]--;
|
||||||
pieceCount[us][promotion]++;
|
pieceCount[us][promotion]++;
|
||||||
|
|
||||||
// Update piece lists
|
// Update piece lists, move the last pawn at index[to] position
|
||||||
pieceList[us][PAWN][index[from]] = pieceList[us][PAWN][pieceCount[us][PAWN]];
|
// and shrink the list. Add a new promotion piece to the list.
|
||||||
index[pieceList[us][PAWN][index[from]]] = index[from];
|
Square lastPawnSquare = pieceList[us][PAWN][pieceCount[us][PAWN]];
|
||||||
pieceList[us][promotion][pieceCount[us][promotion] - 1] = to;
|
index[lastPawnSquare] = index[to];
|
||||||
|
pieceList[us][PAWN][index[lastPawnSquare]] = lastPawnSquare;
|
||||||
index[to] = pieceCount[us][promotion] - 1;
|
index[to] = pieceCount[us][promotion] - 1;
|
||||||
|
pieceList[us][promotion][index[to]] = to;
|
||||||
|
|
||||||
// Partially revert hash keys update
|
// Partially revert hash keys update
|
||||||
key ^= zobrist[us][PAWN][to] ^ zobrist[us][promotion][to];
|
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(to == st->epSquare);
|
||||||
assert(relative_rank(opposite_color(them), to) == RANK_6);
|
assert(relative_rank(opposite_color(them), to) == RANK_6);
|
||||||
assert(piece_on(to) == EMPTY);
|
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));
|
assert(piece_on(capsq) == piece_of_color_and_type(them, PAWN));
|
||||||
|
|
||||||
board[capsq] = EMPTY;
|
board[capsq] = EMPTY;
|
||||||
|
@ -934,9 +936,10 @@ void Position::do_capture_move(Bitboard& key, PieceType capture, Color them, Squ
|
||||||
// Update piece count
|
// Update piece count
|
||||||
pieceCount[them][capture]--;
|
pieceCount[them][capture]--;
|
||||||
|
|
||||||
// Update piece list
|
// Update piece list, move the last piece at index[capsq] position
|
||||||
pieceList[them][capture][index[capsq]] = pieceList[them][capture][pieceCount[them][capture]];
|
Square lastPieceSquare = pieceList[them][capture][pieceCount[them][capture]];
|
||||||
index[pieceList[them][capture][index[capsq]]] = index[capsq];
|
index[lastPieceSquare] = index[capsq];
|
||||||
|
pieceList[them][capture][index[lastPieceSquare]] = lastPieceSquare;
|
||||||
|
|
||||||
// Reset rule 50 counter
|
// Reset rule 50 counter
|
||||||
st->rule50 = 0;
|
st->rule50 = 0;
|
||||||
|
@ -957,6 +960,9 @@ void Position::do_castle_move(Move m) {
|
||||||
Color us = side_to_move();
|
Color us = side_to_move();
|
||||||
Color them = opposite_color(us);
|
Color them = opposite_color(us);
|
||||||
|
|
||||||
|
// Reset capture field
|
||||||
|
st->capture = NO_PIECE_TYPE;
|
||||||
|
|
||||||
// Find source squares for king and rook
|
// Find source squares for king and rook
|
||||||
Square kfrom = move_from(m);
|
Square kfrom = move_from(m);
|
||||||
Square rfrom = move_to(m); // HACK: See comment at beginning of function
|
Square rfrom = move_to(m); // HACK: See comment at beginning of function
|
||||||
|
|
|
@ -342,7 +342,7 @@ private:
|
||||||
|
|
||||||
// Piece lists
|
// Piece lists
|
||||||
Square pieceList[2][8][16]; // [color][pieceType][index]
|
Square pieceList[2][8][16]; // [color][pieceType][index]
|
||||||
int index[64];
|
int index[64]; // [square]
|
||||||
|
|
||||||
// Other info
|
// Other info
|
||||||
Square kingSquare[2];
|
Square kingSquare[2];
|
||||||
|
|
Loading…
Add table
Reference in a new issue