1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-04-30 16:53: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)
: (tte->type() & BOUND_UPPER)))
{
assert(ttValue != VALUE_NONE); // Due to depth > DEPTH_NONE
TT.refresh(tte);
ss->currentMove = ttMove; // Can be MOVE_NONE
@ -574,6 +576,7 @@ namespace {
// Step 5. Evaluate the position statically and update parent's gain statistics
if (inCheck)
ss->eval = ss->evalMargin = refinedValue = VALUE_NONE;
else if (tte)
{
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)
&& abs(ttValue) < VALUE_KNOWN_WIN)
{
assert(ttValue != VALUE_NONE);
Value rBeta = ttValue - int(depth);
ss->excludedMove = move;
ss->skipNullMove = true;
@ -1111,6 +1116,8 @@ split_point_start: // At split points actual search starts from here
: ttValue >= beta ? (tte->type() & BOUND_LOWER)
: (tte->type() & BOUND_UPPER)))
{
assert(ttValue != VALUE_NONE); // Due to ttDepth > DEPTH_NONE
ss->currentMove = ttMove; // Can be MOVE_NONE
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) {
if (v >= VALUE_MATE_IN_MAX_PLY)
return v + ply;
assert(v != VALUE_NONE);
if (v <= VALUE_MATED_IN_MAX_PLY)
return v - ply;
return v;
return v >= VALUE_MATE_IN_MAX_PLY ? v + ply
: v <= VALUE_MATED_IN_MAX_PLY ? v - ply : v;
}
@ -1384,13 +1388,9 @@ split_point_start: // At split points actual search starts from here
Value value_from_tt(Value v, int ply) {
if (v >= VALUE_MATE_IN_MAX_PLY)
return v - ply;
if (v <= VALUE_MATED_IN_MAX_PLY)
return v + ply;
return v;
return v == VALUE_NONE ? VALUE_NONE
: v >= VALUE_MATE_IN_MAX_PLY ? v - ply
: v <= VALUE_MATED_IN_MAX_PLY ? v + ply : 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
// 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) {
assert(tte);
assert(v != VALUE_NONE || !tte->type());
if ( ((tte->type() & BOUND_LOWER) && v >= defaultEval)
|| ((tte->type() & BOUND_UPPER) && v < defaultEval))