mirror of
https://github.com/sockspls/badfish
synced 2025-07-11 19:49:14 +00:00
Retire undo_null_move()
Use a templetized do_null_move() to do/undo the null move. No functional change. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
parent
e896368496
commit
08abe8b4a3
3 changed files with 33 additions and 47 deletions
|
@ -1204,61 +1204,48 @@ void Position::undo_move(Move m) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Position::do_null_move makes() a "null move": It switches the side to move
|
/// Position::do_null_move() is used to do/undo a "null move": It flips the side
|
||||||
/// and updates the hash key without executing any move on the board.
|
/// to move and updates the hash key without executing any move on the board.
|
||||||
|
template<bool Do>
|
||||||
void Position::do_null_move(StateInfo& backupSt) {
|
void Position::do_null_move(StateInfo& backupSt) {
|
||||||
|
|
||||||
assert(!in_check());
|
assert(!in_check());
|
||||||
|
|
||||||
// Back up the information necessary to undo the null move to the supplied
|
// Back up the information necessary to undo the null move to the supplied
|
||||||
// StateInfo object.
|
// StateInfo object. Note that differently from normal case here backupSt
|
||||||
// Note that differently from normal case here backupSt is actually used as
|
// is actually used as a backup storage not as the new state. This reduces
|
||||||
// a backup storage not as a new state to be used.
|
// the number of fields to be copied.
|
||||||
backupSt.key = st->key;
|
StateInfo* src = Do ? st : &backupSt;
|
||||||
backupSt.epSquare = st->epSquare;
|
StateInfo* dst = Do ? &backupSt : st;
|
||||||
backupSt.value = st->value;
|
|
||||||
backupSt.previous = st->previous;
|
|
||||||
backupSt.pliesFromNull = st->pliesFromNull;
|
|
||||||
st->previous = &backupSt;
|
|
||||||
|
|
||||||
// Update the necessary information
|
dst->key = src->key;
|
||||||
if (st->epSquare != SQ_NONE)
|
dst->epSquare = src->epSquare;
|
||||||
st->key ^= zobEp[st->epSquare];
|
dst->value = src->value;
|
||||||
|
dst->rule50 = src->rule50;
|
||||||
st->key ^= zobSideToMove;
|
dst->pliesFromNull = src->pliesFromNull;
|
||||||
prefetch((char*)TT.first_entry(st->key));
|
|
||||||
|
|
||||||
sideToMove = flip(sideToMove);
|
sideToMove = flip(sideToMove);
|
||||||
st->epSquare = SQ_NONE;
|
|
||||||
st->rule50++;
|
if (Do)
|
||||||
st->pliesFromNull = 0;
|
{
|
||||||
st->value += (sideToMove == WHITE) ? TempoValue : -TempoValue;
|
if (st->epSquare != SQ_NONE)
|
||||||
|
st->key ^= zobEp[st->epSquare];
|
||||||
|
|
||||||
|
st->key ^= zobSideToMove;
|
||||||
|
prefetch((char*)TT.first_entry(st->key));
|
||||||
|
|
||||||
|
st->epSquare = SQ_NONE;
|
||||||
|
st->rule50++;
|
||||||
|
st->pliesFromNull = 0;
|
||||||
|
st->value += (sideToMove == WHITE) ? TempoValue : -TempoValue;
|
||||||
|
}
|
||||||
|
|
||||||
assert(pos_is_ok());
|
assert(pos_is_ok());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Explicit template instantiations
|
||||||
/// Position::undo_null_move() unmakes a "null move".
|
template void Position::do_null_move<false>(StateInfo& backupSt);
|
||||||
|
template void Position::do_null_move<true>(StateInfo& backupSt);
|
||||||
void Position::undo_null_move() {
|
|
||||||
|
|
||||||
assert(!in_check());
|
|
||||||
|
|
||||||
// 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;
|
|
||||||
|
|
||||||
// Update the necessary information
|
|
||||||
sideToMove = flip(sideToMove);
|
|
||||||
st->rule50--;
|
|
||||||
|
|
||||||
assert(pos_is_ok());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// Position::see() is a static exchange evaluator: It tries to estimate the
|
/// Position::see() is a static exchange evaluator: It tries to estimate the
|
||||||
|
|
|
@ -166,8 +166,7 @@ public:
|
||||||
void do_move(Move m, StateInfo& st);
|
void do_move(Move m, StateInfo& st);
|
||||||
void do_move(Move m, StateInfo& st, const CheckInfo& ci, bool moveIsCheck);
|
void do_move(Move m, StateInfo& st, const CheckInfo& ci, bool moveIsCheck);
|
||||||
void undo_move(Move m);
|
void undo_move(Move m);
|
||||||
void do_null_move(StateInfo& st);
|
template<bool Do> void do_null_move(StateInfo& st);
|
||||||
void undo_null_move();
|
|
||||||
|
|
||||||
// Static exchange evaluation
|
// Static exchange evaluation
|
||||||
int see(Move m) const;
|
int see(Move m) const;
|
||||||
|
|
|
@ -870,12 +870,12 @@ namespace {
|
||||||
if (refinedValue - PawnValueMidgame > beta)
|
if (refinedValue - PawnValueMidgame > beta)
|
||||||
R++;
|
R++;
|
||||||
|
|
||||||
pos.do_null_move(st);
|
pos.do_null_move<true>(st);
|
||||||
(ss+1)->skipNullMove = true;
|
(ss+1)->skipNullMove = true;
|
||||||
nullValue = depth-R*ONE_PLY < ONE_PLY ? -qsearch<NonPV>(pos, ss+1, -beta, -alpha, DEPTH_ZERO)
|
nullValue = depth-R*ONE_PLY < ONE_PLY ? -qsearch<NonPV>(pos, ss+1, -beta, -alpha, DEPTH_ZERO)
|
||||||
: - search<NonPV>(pos, ss+1, -beta, -alpha, depth-R*ONE_PLY);
|
: - search<NonPV>(pos, ss+1, -beta, -alpha, depth-R*ONE_PLY);
|
||||||
(ss+1)->skipNullMove = false;
|
(ss+1)->skipNullMove = false;
|
||||||
pos.undo_null_move();
|
pos.do_null_move<false>(st);
|
||||||
|
|
||||||
if (nullValue >= beta)
|
if (nullValue >= beta)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Reference in a new issue