From: Marco Costalba Date: Sat, 29 Oct 2011 16:49:20 +0000 (+0100) Subject: Retire undo_null_move() X-Git-Url: https://git.sesse.net/?p=stockfish;a=commitdiff_plain;h=08abe8b4a33ab409f5b61ebcb9216ddf8a605e95 Retire undo_null_move() Use a templetized do_null_move() to do/undo the null move. No functional change. Signed-off-by: Marco Costalba --- diff --git a/src/position.cpp b/src/position.cpp index 4935a2c6..a1823c12 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -1204,62 +1204,49 @@ void Position::undo_move(Move m) { } -/// Position::do_null_move makes() a "null move": It switches the side to move -/// and updates the hash key without executing any move on the board. - +/// Position::do_null_move() is used to do/undo a "null move": It flips the side +/// to move and updates the hash key without executing any move on the board. +template void Position::do_null_move(StateInfo& backupSt) { assert(!in_check()); // Back up the information necessary to undo the null move to the supplied - // StateInfo object. - // Note that differently from normal case here backupSt is actually used as - // a backup storage not as a new state to be used. - backupSt.key = st->key; - backupSt.epSquare = st->epSquare; - backupSt.value = st->value; - backupSt.previous = st->previous; - backupSt.pliesFromNull = st->pliesFromNull; - st->previous = &backupSt; - - // Update the necessary information - if (st->epSquare != SQ_NONE) - st->key ^= zobEp[st->epSquare]; - - st->key ^= zobSideToMove; - prefetch((char*)TT.first_entry(st->key)); + // StateInfo object. Note that differently from normal case here backupSt + // is actually used as a backup storage not as the new state. This reduces + // the number of fields to be copied. + StateInfo* src = Do ? st : &backupSt; + StateInfo* dst = Do ? &backupSt : st; + + dst->key = src->key; + dst->epSquare = src->epSquare; + dst->value = src->value; + dst->rule50 = src->rule50; + dst->pliesFromNull = src->pliesFromNull; sideToMove = flip(sideToMove); - st->epSquare = SQ_NONE; - st->rule50++; - st->pliesFromNull = 0; - st->value += (sideToMove == WHITE) ? TempoValue : -TempoValue; - - assert(pos_is_ok()); -} - - -/// Position::undo_null_move() unmakes a "null move". -void Position::undo_null_move() { - - assert(!in_check()); + if (Do) + { + if (st->epSquare != SQ_NONE) + st->key ^= zobEp[st->epSquare]; - // Restore information from the our backup StateInfo object - StateInfo* backupSt = st->previous; - st->key = backupSt->key; - st->epSquare = backupSt->epSquare; - st->value = backupSt->value; - st->previous = backupSt->previous; - st->pliesFromNull = backupSt->pliesFromNull; + st->key ^= zobSideToMove; + prefetch((char*)TT.first_entry(st->key)); - // Update the necessary information - sideToMove = flip(sideToMove); - st->rule50--; + st->epSquare = SQ_NONE; + st->rule50++; + st->pliesFromNull = 0; + st->value += (sideToMove == WHITE) ? TempoValue : -TempoValue; + } assert(pos_is_ok()); } +// Explicit template instantiations +template void Position::do_null_move(StateInfo& backupSt); +template void Position::do_null_move(StateInfo& backupSt); + /// Position::see() is a static exchange evaluator: It tries to estimate the /// material gain or loss resulting from a move. There are three versions of diff --git a/src/position.h b/src/position.h index 4cfa34f6..1bb2e388 100644 --- a/src/position.h +++ b/src/position.h @@ -166,8 +166,7 @@ public: void do_move(Move m, StateInfo& st); void do_move(Move m, StateInfo& st, const CheckInfo& ci, bool moveIsCheck); void undo_move(Move m); - void do_null_move(StateInfo& st); - void undo_null_move(); + template void do_null_move(StateInfo& st); // Static exchange evaluation int see(Move m) const; diff --git a/src/search.cpp b/src/search.cpp index da95877c..25a3984d 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -870,12 +870,12 @@ namespace { if (refinedValue - PawnValueMidgame > beta) R++; - pos.do_null_move(st); + pos.do_null_move(st); (ss+1)->skipNullMove = true; nullValue = depth-R*ONE_PLY < ONE_PLY ? -qsearch(pos, ss+1, -beta, -alpha, DEPTH_ZERO) : - search(pos, ss+1, -beta, -alpha, depth-R*ONE_PLY); (ss+1)->skipNullMove = false; - pos.undo_null_move(); + pos.do_null_move(st); if (nullValue >= beta) {