1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-05-01 01:03:09 +00:00

Document why is safe ttValue == VALUE_NONE

We can have ttValue == VALUE_NONE when we use a TT
slot to just save a position static evaluation, but
in this case we also save DEPTH_NONE so to avoid
using the ttValue in search. This happens to work,
but due to a number of lucky and tricky cases that
we now documnet through a bunch of asserts and a
little change to value_from_tt() that has no real
effect but clarifing the code.

No functional change.
This commit is contained in:
Marco Costalba 2012-10-14 12:36:05 +02:00
parent 6a75291ab1
commit 3aa2d6db18

View file

@ -557,6 +557,8 @@ namespace {
: ttValue >= beta ? (tte->type() & BOUND_LOWER) : ttValue >= beta ? (tte->type() & BOUND_LOWER)
: (tte->type() & BOUND_UPPER))) : (tte->type() & BOUND_UPPER)))
{ {
assert(ttValue != VALUE_NONE); // Due to depth > DEPTH_NONE
TT.refresh(tte); TT.refresh(tte);
ss->currentMove = ttMove; // Can be MOVE_NONE ss->currentMove = ttMove; // Can be MOVE_NONE
@ -574,6 +576,7 @@ namespace {
// Step 5. Evaluate the position statically and update parent's gain statistics // Step 5. Evaluate the position statically and update parent's gain statistics
if (inCheck) if (inCheck)
ss->eval = ss->evalMargin = refinedValue = VALUE_NONE; ss->eval = ss->evalMargin = refinedValue = VALUE_NONE;
else if (tte) else if (tte)
{ {
assert(tte->static_value() != VALUE_NONE); assert(tte->static_value() != VALUE_NONE);
@ -818,6 +821,8 @@ split_point_start: // At split points actual search starts from here
&& pos.pl_move_is_legal(move, ci.pinned) && pos.pl_move_is_legal(move, ci.pinned)
&& abs(ttValue) < VALUE_KNOWN_WIN) && abs(ttValue) < VALUE_KNOWN_WIN)
{ {
assert(ttValue != VALUE_NONE);
Value rBeta = ttValue - int(depth); Value rBeta = ttValue - int(depth);
ss->excludedMove = move; ss->excludedMove = move;
ss->skipNullMove = true; ss->skipNullMove = true;
@ -1111,6 +1116,8 @@ split_point_start: // At split points actual search starts from here
: ttValue >= beta ? (tte->type() & BOUND_LOWER) : ttValue >= beta ? (tte->type() & BOUND_LOWER)
: (tte->type() & BOUND_UPPER))) : (tte->type() & BOUND_UPPER)))
{ {
assert(ttValue != VALUE_NONE); // Due to ttDepth > DEPTH_NONE
ss->currentMove = ttMove; // Can be MOVE_NONE ss->currentMove = ttMove; // Can be MOVE_NONE
return ttValue; return ttValue;
} }
@ -1368,13 +1375,10 @@ split_point_start: // At split points actual search starts from here
Value value_to_tt(Value v, int ply) { Value value_to_tt(Value v, int ply) {
if (v >= VALUE_MATE_IN_MAX_PLY) assert(v != VALUE_NONE);
return v + ply;
if (v <= VALUE_MATED_IN_MAX_PLY) return v >= VALUE_MATE_IN_MAX_PLY ? v + ply
return v - ply; : v <= VALUE_MATED_IN_MAX_PLY ? v - ply : v;
return v;
} }
@ -1384,13 +1388,9 @@ split_point_start: // At split points actual search starts from here
Value value_from_tt(Value v, int ply) { Value value_from_tt(Value v, int ply) {
if (v >= VALUE_MATE_IN_MAX_PLY) return v == VALUE_NONE ? VALUE_NONE
return v - ply; : v >= VALUE_MATE_IN_MAX_PLY ? v - ply
: v <= VALUE_MATED_IN_MAX_PLY ? v + ply : v;
if (v <= VALUE_MATED_IN_MAX_PLY)
return v + ply;
return v;
} }
@ -1435,11 +1435,13 @@ split_point_start: // At split points actual search starts from here
// refine_eval() returns the transposition table score if possible, otherwise // refine_eval() returns the transposition table score if possible, otherwise
// falls back on static position evaluation. // falls back on static position evaluation. Note that we never return VALUE_NONE
// even if v == VALUE_NONE.
Value refine_eval(const TTEntry* tte, Value v, Value defaultEval) { Value refine_eval(const TTEntry* tte, Value v, Value defaultEval) {
assert(tte); assert(tte);
assert(v != VALUE_NONE || !tte->type());
if ( ((tte->type() & BOUND_LOWER) && v >= defaultEval) if ( ((tte->type() & BOUND_LOWER) && v >= defaultEval)
|| ((tte->type() & BOUND_UPPER) && v < defaultEval)) || ((tte->type() & BOUND_UPPER) && v < defaultEval))