mirror of
https://github.com/sockspls/badfish
synced 2025-04-30 16:53: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:
parent
7c55b0e880
commit
c5f44ef45b
2 changed files with 11 additions and 20 deletions
|
@ -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<MidGame>(them, capture, capsq);
|
||||
st->egValue -= pst<EndGame>(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;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Add table
Reference in a new issue