From c5f44ef45bd9929f5e2f1f4c25c5edd11202546e Mon Sep 17 00:00:00 2001 From: Marco Costalba Date: Sun, 20 Sep 2009 07:04:22 +0100 Subject: [PATCH] Move kingSquare[] array to StateInfo This avoids to reverting back when undoing the move. No functional change. No performance change. Signed-off-by: Marco Costalba --- src/position.cpp | 26 +++++++++----------------- src/position.h | 5 ++--- 2 files changed, 11 insertions(+), 20 deletions(-) diff --git a/src/position.cpp b/src/position.cpp index 462088e0..46daf8f3 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -704,7 +704,7 @@ void Position::do_move(Move m, StateInfo& newSt, Bitboard dcCandidates) { struct ReducedStateInfo { Key key, pawnKey, materialKey; int castleRights, rule50; - Square epSquare; + Square kingSquare[2], epSquare; Value mgValue, egValue; Value npMaterial[2]; }; @@ -786,7 +786,7 @@ void Position::do_move(Move m, StateInfo& newSt, Bitboard dcCandidates) { // If the moving piece was a king, update the king square if (pt == KING) - kingSquare[us] = to; + st->kingSquare[us] = to; // Update piece lists, note that index[from] is not updated and // becomes stale. This works as long as index[] is accessed just @@ -920,16 +920,15 @@ void Position::do_capture_move(Bitboard& key, PieceType capture, Color them, Squ // Update hash key key ^= zobrist[them][capture][capsq]; - // If the captured piece was a pawn, update pawn hash key - if (capture == PAWN) - st->pawnKey ^= zobrist[them][PAWN][capsq]; - // Update incremental scores st->mgValue -= pst(them, capture, capsq); st->egValue -= pst(them, capture, capsq); - // Update material - if (capture != PAWN) + // If the captured piece was a pawn, update pawn hash key, + // otherwise update non-pawn material. + if (capture == PAWN) + st->pawnKey ^= zobrist[them][PAWN][capsq]; + else st->npMaterial[them] -= piece_value_midgame(capture); // Update material hash key @@ -1007,7 +1006,7 @@ void Position::do_castle_move(Move m) { board[rto] = rook; // Update king square - kingSquare[us] = kto; + st->kingSquare[us] = kto; // Update piece lists pieceList[us][KING][index[kfrom]] = kto; @@ -1120,10 +1119,6 @@ void Position::undo_move(Move m) { board[from] = piece_of_color_and_type(us, pt); board[to] = EMPTY; - // If the moving piece was a king, update the king square - if (pt == KING) - kingSquare[us] = from; - // Update piece list index[from] = index[to]; pieceList[us][pt][index[from]] = from; @@ -1209,9 +1204,6 @@ void Position::undo_castle_move(Move m) { board[rfrom] = piece_of_color_and_type(us, ROOK); board[kfrom] = piece_of_color_and_type(us, KING); - // Update king square - kingSquare[us] = kfrom; - // Update piece lists pieceList[us][KING][index[kto]] = kfrom; pieceList[us][ROOK][index[rto]] = rfrom; @@ -1529,7 +1521,7 @@ void Position::put_piece(Piece p, Square s) { pieceCount[c][pt]++; if (pt == KING) - kingSquare[c] = s; + st->kingSquare[c] = s; } diff --git a/src/position.h b/src/position.h index 11cdc132..8e6fa938 100644 --- a/src/position.h +++ b/src/position.h @@ -89,7 +89,7 @@ enum Phase { struct StateInfo { Key key, pawnKey, materialKey; int castleRights, rule50; - Square epSquare; + Square kingSquare[2], epSquare; Value mgValue, egValue; Value npMaterial[2]; @@ -326,7 +326,6 @@ private: int index[64]; // [square] // Other info - Square kingSquare[2]; Color sideToMove; int gamePly; Key history[MaxGameLength]; @@ -423,7 +422,7 @@ inline Square Position::ep_square() const { } inline Square Position::king_square(Color c) const { - return kingSquare[c]; + return st->kingSquare[c]; } inline bool Position::can_castle_kingside(Color side) const { -- 2.39.2