From 0e54688853e1be9f6da11bde17e1820252b69f97 Mon Sep 17 00:00:00 2001 From: Calcitem Date: Thu, 1 Oct 2020 11:04:15 +0800 Subject: [PATCH] =?UTF-8?q?Zobrist:=20=E6=AF=8F=E6=AC=A1=E6=8D=A2=E8=BE=B9?= =?UTF-8?q?=E6=97=B6=E5=BC=82=E6=88=96=20side=20=E8=80=8C=E4=B8=8D?= =?UTF-8?q?=E7=94=A8=20Key=20=E7=9A=84=E7=89=B9=E5=AE=9A=E4=BD=8D=E6=A0=87?= =?UTF-8?q?=E8=AE=B0=E8=BD=AE=E5=88=B0=E8=B0=81=E8=B5=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 自对弈棋谱不变。 --- src/position.cpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/position.cpp b/src/position.cpp index 5c1ab5b0..7b7ca5e3 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -39,6 +39,7 @@ using std::string; namespace Zobrist { Key psq[PIECE_TYPE_NB][SQUARE_NB]; +Key side; } namespace @@ -153,6 +154,8 @@ void Position::init() for (Square s = SQ_0; s < SQUARE_NB; ++s) Zobrist::psq[pt][s] = rng.rand(); + Zobrist::side = rng.rand(); + // Prepare the cuckoo tables std::memset(cuckoo, 0, sizeof(cuckoo)); std::memset(cuckooMove, 0, sizeof(cuckooMove)); @@ -1226,6 +1229,7 @@ inline void Position::set_side_to_move(Color c) inline void Position::change_side_to_move() { set_side_to_move(~sideToMove); + st->key ^= Zobrist::side; } inline Key Position::update_key(Square s) @@ -1255,9 +1259,11 @@ Key Position::update_key_misc() st->key = st->key << KEY_MISC_BIT >> KEY_MISC_BIT; Key hi = 0; +#if 0 if (sideToMove == WHITE) { hi |= 1U; } +#endif if (action == ACTION_REMOVE) { hi |= 1U << 1; @@ -1278,23 +1284,25 @@ Key Position::next_primary_key(Move m) MoveType mt = type_of(m); if (mt == MOVETYPE_REMOVE) { - int pieceType = ~sideToMove; - npKey ^= Zobrist::psq[pieceType][s]; + npKey ^= Zobrist::psq[~sideToMove][s]; if (rule.hasBannedLocations && phase == PHASE_PLACING) { npKey ^= Zobrist::psq[BAN][s]; } - return npKey; + goto out; } - int pieceType = sideToMove; - npKey ^= Zobrist::psq[pieceType][s]; + npKey ^= Zobrist::psq[sideToMove][s]; if (mt == MOVETYPE_MOVE) { - npKey ^= Zobrist::psq[pieceType][from_sq(m)]; + npKey ^= Zobrist::psq[sideToMove][from_sq(m)]; } +out: + // Note: Guess only, maybe side is not changed actually + npKey ^= Zobrist::side; + return npKey; }