mirror of
https://github.com/sockspls/badfish
synced 2025-04-29 08:13:08 +00:00
(Re)introduce DEPTH_ZERO to replace Depth(0)
No functional changes. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
parent
ea2b8a93eb
commit
4f28e19fc0
3 changed files with 22 additions and 20 deletions
|
@ -28,6 +28,8 @@
|
||||||
enum Depth {
|
enum Depth {
|
||||||
|
|
||||||
ONE_PLY = 2,
|
ONE_PLY = 2,
|
||||||
|
|
||||||
|
DEPTH_ZERO = 0,
|
||||||
DEPTH_NONE = -127 * ONE_PLY
|
DEPTH_NONE = -127 * ONE_PLY
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -90,7 +90,7 @@ MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const History& h,
|
||||||
|
|
||||||
if (p.is_check())
|
if (p.is_check())
|
||||||
phasePtr = EvasionsPhaseTable;
|
phasePtr = EvasionsPhaseTable;
|
||||||
else if (d > Depth(0))
|
else if (d > DEPTH_ZERO)
|
||||||
{
|
{
|
||||||
// Consider sligtly negative captures as good if at low
|
// Consider sligtly negative captures as good if at low
|
||||||
// depth and far from beta.
|
// depth and far from beta.
|
||||||
|
@ -99,7 +99,7 @@ MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const History& h,
|
||||||
|
|
||||||
phasePtr = MainSearchPhaseTable;
|
phasePtr = MainSearchPhaseTable;
|
||||||
}
|
}
|
||||||
else if (d == Depth(0))
|
else if (d == DEPTH_ZERO)
|
||||||
phasePtr = QsearchWithChecksPhaseTable;
|
phasePtr = QsearchWithChecksPhaseTable;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -824,7 +824,7 @@ namespace {
|
||||||
value = -search<NonPV>(pos, ss+1, -(alpha+1), -alpha, newDepth-ss->reduction, 1);
|
value = -search<NonPV>(pos, ss+1, -(alpha+1), -alpha, newDepth-ss->reduction, 1);
|
||||||
doFullDepthSearch = (value > alpha);
|
doFullDepthSearch = (value > alpha);
|
||||||
}
|
}
|
||||||
ss->reduction = Depth(0); // Restore original reduction
|
ss->reduction = DEPTH_ZERO; // Restore original reduction
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 15. Full depth search
|
// Step 15. Full depth search
|
||||||
|
@ -1067,7 +1067,7 @@ namespace {
|
||||||
&& !pos.has_pawn_on_7th(pos.side_to_move()))
|
&& !pos.has_pawn_on_7th(pos.side_to_move()))
|
||||||
{
|
{
|
||||||
Value rbeta = beta - razor_margin(depth);
|
Value rbeta = beta - razor_margin(depth);
|
||||||
Value v = qsearch<NonPV>(pos, ss, rbeta-1, rbeta, Depth(0), ply);
|
Value v = qsearch<NonPV>(pos, ss, rbeta-1, rbeta, DEPTH_ZERO, ply);
|
||||||
if (v < rbeta)
|
if (v < rbeta)
|
||||||
// Logically we should return (v + razor_margin(depth)), but
|
// Logically we should return (v + razor_margin(depth)), but
|
||||||
// surprisingly this did slightly weaker in tests.
|
// surprisingly this did slightly weaker in tests.
|
||||||
|
@ -1110,7 +1110,7 @@ namespace {
|
||||||
pos.do_null_move(st);
|
pos.do_null_move(st);
|
||||||
(ss+1)->skipNullMove = true;
|
(ss+1)->skipNullMove = true;
|
||||||
|
|
||||||
nullValue = depth-R*ONE_PLY < ONE_PLY ? -qsearch<NonPV>(pos, ss+1, -beta, -alpha, Depth(0), ply+1)
|
nullValue = depth-R*ONE_PLY < ONE_PLY ? -qsearch<NonPV>(pos, ss+1, -beta, -alpha, DEPTH_ZERO, ply+1)
|
||||||
: - search<NonPV>(pos, ss+1, -beta, -alpha, depth-R*ONE_PLY, ply+1);
|
: - search<NonPV>(pos, ss+1, -beta, -alpha, depth-R*ONE_PLY, ply+1);
|
||||||
(ss+1)->skipNullMove = false;
|
(ss+1)->skipNullMove = false;
|
||||||
pos.undo_null_move();
|
pos.undo_null_move();
|
||||||
|
@ -1263,7 +1263,7 @@ namespace {
|
||||||
// Step extra. pv search (only in PV nodes)
|
// Step extra. pv search (only in PV nodes)
|
||||||
// The first move in list is the expected PV
|
// The first move in list is the expected PV
|
||||||
if (PvNode && moveCount == 1)
|
if (PvNode && moveCount == 1)
|
||||||
value = newDepth < ONE_PLY ? -qsearch<PV>(pos, ss+1, -beta, -alpha, Depth(0), ply+1)
|
value = newDepth < ONE_PLY ? -qsearch<PV>(pos, ss+1, -beta, -alpha, DEPTH_ZERO, ply+1)
|
||||||
: - search<PV>(pos, ss+1, -beta, -alpha, newDepth, ply+1);
|
: - search<PV>(pos, ss+1, -beta, -alpha, newDepth, ply+1);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1281,7 +1281,7 @@ namespace {
|
||||||
if (ss->reduction)
|
if (ss->reduction)
|
||||||
{
|
{
|
||||||
Depth d = newDepth - ss->reduction;
|
Depth d = newDepth - ss->reduction;
|
||||||
value = d < ONE_PLY ? -qsearch<NonPV>(pos, ss+1, -(alpha+1), -alpha, Depth(0), ply+1)
|
value = d < ONE_PLY ? -qsearch<NonPV>(pos, ss+1, -(alpha+1), -alpha, DEPTH_ZERO, ply+1)
|
||||||
: - search<NonPV>(pos, ss+1, -(alpha+1), -alpha, d, ply+1);
|
: - search<NonPV>(pos, ss+1, -(alpha+1), -alpha, d, ply+1);
|
||||||
|
|
||||||
doFullDepthSearch = (value > alpha);
|
doFullDepthSearch = (value > alpha);
|
||||||
|
@ -1298,20 +1298,20 @@ namespace {
|
||||||
value = -search<NonPV>(pos, ss+1, -(alpha+1), -alpha, newDepth-ss->reduction, ply+1);
|
value = -search<NonPV>(pos, ss+1, -(alpha+1), -alpha, newDepth-ss->reduction, ply+1);
|
||||||
doFullDepthSearch = (value > alpha);
|
doFullDepthSearch = (value > alpha);
|
||||||
}
|
}
|
||||||
ss->reduction = Depth(0); // Restore original reduction
|
ss->reduction = DEPTH_ZERO; // Restore original reduction
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 15. Full depth search
|
// Step 15. Full depth search
|
||||||
if (doFullDepthSearch)
|
if (doFullDepthSearch)
|
||||||
{
|
{
|
||||||
value = newDepth < ONE_PLY ? -qsearch<NonPV>(pos, ss+1, -(alpha+1), -alpha, Depth(0), ply+1)
|
value = newDepth < ONE_PLY ? -qsearch<NonPV>(pos, ss+1, -(alpha+1), -alpha, DEPTH_ZERO, ply+1)
|
||||||
: - search<NonPV>(pos, ss+1, -(alpha+1), -alpha, newDepth, ply+1);
|
: - search<NonPV>(pos, ss+1, -(alpha+1), -alpha, newDepth, ply+1);
|
||||||
|
|
||||||
// Step extra. pv search (only in PV nodes)
|
// Step extra. pv search (only in PV nodes)
|
||||||
// Search only for possible new PV nodes, if instead value >= beta then
|
// Search only for possible new PV nodes, if instead value >= beta then
|
||||||
// parent node fails low with value <= alpha and tries another move.
|
// parent node fails low with value <= alpha and tries another move.
|
||||||
if (PvNode && value > alpha && value < beta)
|
if (PvNode && value > alpha && value < beta)
|
||||||
value = newDepth < ONE_PLY ? -qsearch<PV>(pos, ss+1, -beta, -alpha, Depth(0), ply+1)
|
value = newDepth < ONE_PLY ? -qsearch<PV>(pos, ss+1, -beta, -alpha, DEPTH_ZERO, ply+1)
|
||||||
: - search<PV>(pos, ss+1, -beta, -alpha, newDepth, ply+1);
|
: - search<PV>(pos, ss+1, -beta, -alpha, newDepth, ply+1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1471,7 +1471,7 @@ namespace {
|
||||||
// to search the moves. Because the depth is <= 0 here, only captures,
|
// to search the moves. Because the depth is <= 0 here, only captures,
|
||||||
// queen promotions and checks (only if depth == 0 or depth == -ONE_PLY
|
// queen promotions and checks (only if depth == 0 or depth == -ONE_PLY
|
||||||
// and we are near beta) will be generated.
|
// and we are near beta) will be generated.
|
||||||
MovePicker mp = MovePicker(pos, ttMove, deepChecks ? Depth(0) : depth, H);
|
MovePicker mp = MovePicker(pos, ttMove, deepChecks ? DEPTH_ZERO : depth, H);
|
||||||
CheckInfo ci(pos);
|
CheckInfo ci(pos);
|
||||||
|
|
||||||
// Loop through the moves until no moves remain or a beta cutoff occurs
|
// Loop through the moves until no moves remain or a beta cutoff occurs
|
||||||
|
@ -1546,7 +1546,7 @@ namespace {
|
||||||
return value_mated_in(ply);
|
return value_mated_in(ply);
|
||||||
|
|
||||||
// Update transposition table
|
// Update transposition table
|
||||||
Depth d = (depth == Depth(0) ? Depth(0) : Depth(-1));
|
Depth d = (depth == DEPTH_ZERO ? DEPTH_ZERO : Depth(-1));
|
||||||
ValueType vt = (bestValue <= oldAlpha ? VALUE_TYPE_UPPER : bestValue >= beta ? VALUE_TYPE_LOWER : VALUE_TYPE_EXACT);
|
ValueType vt = (bestValue <= oldAlpha ? VALUE_TYPE_UPPER : bestValue >= beta ? VALUE_TYPE_LOWER : VALUE_TYPE_EXACT);
|
||||||
TT.store(pos.get_key(), value_to_tt(bestValue, ply), vt, d, ss->bestMove, ss->eval, ei.kingDanger[pos.side_to_move()]);
|
TT.store(pos.get_key(), value_to_tt(bestValue, ply), vt, d, ss->bestMove, ss->eval, ei.kingDanger[pos.side_to_move()]);
|
||||||
|
|
||||||
|
@ -1660,7 +1660,7 @@ namespace {
|
||||||
{
|
{
|
||||||
Value localAlpha = sp->alpha;
|
Value localAlpha = sp->alpha;
|
||||||
Depth d = newDepth - ss->reduction;
|
Depth d = newDepth - ss->reduction;
|
||||||
value = d < ONE_PLY ? -qsearch<NonPV>(pos, ss+1, -(localAlpha+1), -localAlpha, Depth(0), sp->ply+1)
|
value = d < ONE_PLY ? -qsearch<NonPV>(pos, ss+1, -(localAlpha+1), -localAlpha, DEPTH_ZERO, sp->ply+1)
|
||||||
: - search<NonPV>(pos, ss+1, -(localAlpha+1), -localAlpha, d, sp->ply+1);
|
: - search<NonPV>(pos, ss+1, -(localAlpha+1), -localAlpha, d, sp->ply+1);
|
||||||
|
|
||||||
doFullDepthSearch = (value > localAlpha);
|
doFullDepthSearch = (value > localAlpha);
|
||||||
|
@ -1678,21 +1678,21 @@ namespace {
|
||||||
value = -search<NonPV>(pos, ss+1, -(localAlpha+1), -localAlpha, newDepth-ss->reduction, sp->ply+1);
|
value = -search<NonPV>(pos, ss+1, -(localAlpha+1), -localAlpha, newDepth-ss->reduction, sp->ply+1);
|
||||||
doFullDepthSearch = (value > localAlpha);
|
doFullDepthSearch = (value > localAlpha);
|
||||||
}
|
}
|
||||||
ss->reduction = Depth(0); // Restore original reduction
|
ss->reduction = DEPTH_ZERO; // Restore original reduction
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 15. Full depth search
|
// Step 15. Full depth search
|
||||||
if (doFullDepthSearch)
|
if (doFullDepthSearch)
|
||||||
{
|
{
|
||||||
Value localAlpha = sp->alpha;
|
Value localAlpha = sp->alpha;
|
||||||
value = newDepth < ONE_PLY ? -qsearch<NonPV>(pos, ss+1, -(localAlpha+1), -localAlpha, Depth(0), sp->ply+1)
|
value = newDepth < ONE_PLY ? -qsearch<NonPV>(pos, ss+1, -(localAlpha+1), -localAlpha, DEPTH_ZERO, sp->ply+1)
|
||||||
: - search<NonPV>(pos, ss+1, -(localAlpha+1), -localAlpha, newDepth, sp->ply+1);
|
: - search<NonPV>(pos, ss+1, -(localAlpha+1), -localAlpha, newDepth, sp->ply+1);
|
||||||
|
|
||||||
// Step extra. pv search (only in PV nodes)
|
// Step extra. pv search (only in PV nodes)
|
||||||
// Search only for possible new PV nodes, if instead value >= beta then
|
// Search only for possible new PV nodes, if instead value >= beta then
|
||||||
// parent node fails low with value <= alpha and tries another move.
|
// parent node fails low with value <= alpha and tries another move.
|
||||||
if (PvNode && value > localAlpha && value < sp->beta)
|
if (PvNode && value > localAlpha && value < sp->beta)
|
||||||
value = newDepth < ONE_PLY ? -qsearch<PV>(pos, ss+1, -sp->beta, -sp->alpha, Depth(0), sp->ply+1)
|
value = newDepth < ONE_PLY ? -qsearch<PV>(pos, ss+1, -sp->beta, -sp->alpha, DEPTH_ZERO, sp->ply+1)
|
||||||
: - search<PV>(pos, ss+1, -sp->beta, -sp->alpha, newDepth, sp->ply+1);
|
: - search<PV>(pos, ss+1, -sp->beta, -sp->alpha, newDepth, sp->ply+1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1851,7 +1851,7 @@ namespace {
|
||||||
|
|
||||||
assert(m != MOVE_NONE);
|
assert(m != MOVE_NONE);
|
||||||
|
|
||||||
Depth result = Depth(0);
|
Depth result = DEPTH_ZERO;
|
||||||
*dangerous = moveIsCheck | singleEvasion | mateThreat;
|
*dangerous = moveIsCheck | singleEvasion | mateThreat;
|
||||||
|
|
||||||
if (*dangerous)
|
if (*dangerous)
|
||||||
|
@ -2165,7 +2165,7 @@ namespace {
|
||||||
{
|
{
|
||||||
ss->excludedMove = MOVE_NONE;
|
ss->excludedMove = MOVE_NONE;
|
||||||
ss->skipNullMove = false;
|
ss->skipNullMove = false;
|
||||||
ss->reduction = Depth(0);
|
ss->reduction = DEPTH_ZERO;
|
||||||
|
|
||||||
if (i < 3)
|
if (i < 3)
|
||||||
ss->killers[0] = ss->killers[1] = ss->mateKiller = MOVE_NONE;
|
ss->killers[0] = ss->killers[1] = ss->mateKiller = MOVE_NONE;
|
||||||
|
@ -2603,7 +2603,7 @@ namespace {
|
||||||
assert(*bestValue <= *alpha);
|
assert(*bestValue <= *alpha);
|
||||||
assert(*alpha < beta);
|
assert(*alpha < beta);
|
||||||
assert(beta <= VALUE_INFINITE);
|
assert(beta <= VALUE_INFINITE);
|
||||||
assert(depth > Depth(0));
|
assert(depth > DEPTH_ZERO);
|
||||||
assert(p.thread() >= 0 && p.thread() < ActiveThreads);
|
assert(p.thread() >= 0 && p.thread() < ActiveThreads);
|
||||||
assert(ActiveThreads > 1);
|
assert(ActiveThreads > 1);
|
||||||
|
|
||||||
|
@ -2767,7 +2767,7 @@ namespace {
|
||||||
pos.do_move(cur->move, st);
|
pos.do_move(cur->move, st);
|
||||||
ss[0].currentMove = cur->move;
|
ss[0].currentMove = cur->move;
|
||||||
moves[count].move = cur->move;
|
moves[count].move = cur->move;
|
||||||
moves[count].score = -qsearch<PV>(pos, ss+1, -VALUE_INFINITE, VALUE_INFINITE, Depth(0), 1);
|
moves[count].score = -qsearch<PV>(pos, ss+1, -VALUE_INFINITE, VALUE_INFINITE, DEPTH_ZERO, 1);
|
||||||
moves[count].pv[0] = cur->move;
|
moves[count].pv[0] = cur->move;
|
||||||
moves[count].pv[1] = MOVE_NONE;
|
moves[count].pv[1] = MOVE_NONE;
|
||||||
pos.undo_move(cur->move);
|
pos.undo_move(cur->move);
|
||||||
|
|
Loading…
Add table
Reference in a new issue