1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-05-01 01:03:09 +00:00

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 <mcostalba@gmail.com>
This commit is contained in:
Marco Costalba 2009-09-20 07:04:22 +01:00
parent 7c55b0e880
commit c5f44ef45b
2 changed files with 11 additions and 20 deletions

View file

@ -704,7 +704,7 @@ void Position::do_move(Move m, StateInfo& newSt, Bitboard dcCandidates) {
struct ReducedStateInfo { struct ReducedStateInfo {
Key key, pawnKey, materialKey; Key key, pawnKey, materialKey;
int castleRights, rule50; int castleRights, rule50;
Square epSquare; Square kingSquare[2], epSquare;
Value mgValue, egValue; Value mgValue, egValue;
Value npMaterial[2]; 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 the moving piece was a king, update the king square
if (pt == KING) if (pt == KING)
kingSquare[us] = to; st->kingSquare[us] = to;
// Update piece lists, note that index[from] is not updated and // Update piece lists, note that index[from] is not updated and
// becomes stale. This works as long as index[] is accessed just // 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 // Update hash key
key ^= zobrist[them][capture][capsq]; 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 // Update incremental scores
st->mgValue -= pst<MidGame>(them, capture, capsq); st->mgValue -= pst<MidGame>(them, capture, capsq);
st->egValue -= pst<EndGame>(them, capture, capsq); st->egValue -= pst<EndGame>(them, capture, capsq);
// Update material // If the captured piece was a pawn, update pawn hash key,
if (capture != PAWN) // otherwise update non-pawn material.
if (capture == PAWN)
st->pawnKey ^= zobrist[them][PAWN][capsq];
else
st->npMaterial[them] -= piece_value_midgame(capture); st->npMaterial[them] -= piece_value_midgame(capture);
// Update material hash key // Update material hash key
@ -1007,7 +1006,7 @@ void Position::do_castle_move(Move m) {
board[rto] = rook; board[rto] = rook;
// Update king square // Update king square
kingSquare[us] = kto; st->kingSquare[us] = kto;
// Update piece lists // Update piece lists
pieceList[us][KING][index[kfrom]] = kto; 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[from] = piece_of_color_and_type(us, pt);
board[to] = EMPTY; board[to] = EMPTY;
// If the moving piece was a king, update the king square
if (pt == KING)
kingSquare[us] = from;
// Update piece list // Update piece list
index[from] = index[to]; index[from] = index[to];
pieceList[us][pt][index[from]] = from; 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[rfrom] = piece_of_color_and_type(us, ROOK);
board[kfrom] = piece_of_color_and_type(us, KING); board[kfrom] = piece_of_color_and_type(us, KING);
// Update king square
kingSquare[us] = kfrom;
// Update piece lists // Update piece lists
pieceList[us][KING][index[kto]] = kfrom; pieceList[us][KING][index[kto]] = kfrom;
pieceList[us][ROOK][index[rto]] = rfrom; pieceList[us][ROOK][index[rto]] = rfrom;
@ -1529,7 +1521,7 @@ void Position::put_piece(Piece p, Square s) {
pieceCount[c][pt]++; pieceCount[c][pt]++;
if (pt == KING) if (pt == KING)
kingSquare[c] = s; st->kingSquare[c] = s;
} }

View file

@ -89,7 +89,7 @@ enum Phase {
struct StateInfo { struct StateInfo {
Key key, pawnKey, materialKey; Key key, pawnKey, materialKey;
int castleRights, rule50; int castleRights, rule50;
Square epSquare; Square kingSquare[2], epSquare;
Value mgValue, egValue; Value mgValue, egValue;
Value npMaterial[2]; Value npMaterial[2];
@ -326,7 +326,6 @@ private:
int index[64]; // [square] int index[64]; // [square]
// Other info // Other info
Square kingSquare[2];
Color sideToMove; Color sideToMove;
int gamePly; int gamePly;
Key history[MaxGameLength]; Key history[MaxGameLength];
@ -423,7 +422,7 @@ inline Square Position::ep_square() const {
} }
inline Square Position::king_square(Color c) 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 { inline bool Position::can_castle_kingside(Color side) const {