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

Use a local copy of tte->value()

This should avoid some aliasing issues
with TT table access.

After 3913 games at 10"+0.05
Mod vs Orig 662 - 651 - 2600  ELO +0 (+- 6.4)

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
Marco Costalba 2012-03-20 11:45:27 +01:00
parent d4c9abb967
commit e26d13bb31

View file

@ -136,9 +136,9 @@ namespace {
bool connected_moves(const Position& pos, Move m1, Move m2); bool connected_moves(const Position& pos, Move m1, Move m2);
Value value_to_tt(Value v, int ply); Value value_to_tt(Value v, int ply);
Value value_from_tt(Value v, int ply); Value value_from_tt(Value v, int ply);
bool can_return_tt(const TTEntry* tte, Depth depth, Value beta, int ply); bool can_return_tt(const TTEntry* tte, Depth depth, Value ttValue, Value beta);
bool connected_threat(const Position& pos, Move m, Move threat); bool connected_threat(const Position& pos, Move m, Move threat);
Value refine_eval(const TTEntry* tte, Value defaultEval, int ply); Value refine_eval(const TTEntry* tte, Value ttValue, Value defaultEval);
Move do_skill_level(); Move do_skill_level();
string score_to_uci(Value v, Value alpha = -VALUE_INFINITE, Value beta = VALUE_INFINITE); string score_to_uci(Value v, Value alpha = -VALUE_INFINITE, Value beta = VALUE_INFINITE);
void pv_info_to_log(Position& pos, int depth, Value score, int time, Move pv[]); void pv_info_to_log(Position& pos, int depth, Value score, int time, Move pv[]);
@ -542,7 +542,7 @@ namespace {
Move ttMove, move, excludedMove, bestMove, threatMove; Move ttMove, move, excludedMove, bestMove, threatMove;
Depth ext, newDepth; Depth ext, newDepth;
Bound bt; Bound bt;
Value bestValue, value, oldAlpha; Value bestValue, value, oldAlpha, ttValue;
Value refinedValue, nullValue, futilityBase, futilityValue; Value refinedValue, nullValue, futilityBase, futilityValue;
bool isPvMove, inCheck, singularExtensionNode, givesCheck; bool isPvMove, inCheck, singularExtensionNode, givesCheck;
bool captureOrPromotion, dangerous, doFullDepthSearch; bool captureOrPromotion, dangerous, doFullDepthSearch;
@ -613,19 +613,19 @@ namespace {
posKey = excludedMove ? pos.exclusion_key() : pos.key(); posKey = excludedMove ? pos.exclusion_key() : pos.key();
tte = TT.probe(posKey); tte = TT.probe(posKey);
ttMove = RootNode ? RootMoves[PVIdx].pv[0] : tte ? tte->move() : MOVE_NONE; ttMove = RootNode ? RootMoves[PVIdx].pv[0] : tte ? tte->move() : MOVE_NONE;
ttValue = tte ? value_from_tt(tte->value(), ss->ply) : VALUE_ZERO;
// At PV nodes we check for exact scores, while at non-PV nodes we check for // At PV nodes we check for exact scores, while at non-PV nodes we check for
// a fail high/low. Biggest advantage at probing at PV nodes is to have a // a fail high/low. Biggest advantage at probing at PV nodes is to have a
// smooth experience in analysis mode. We don't probe at Root nodes otherwise // smooth experience in analysis mode. We don't probe at Root nodes otherwise
// we should also update RootMoveList to avoid bogus output. // we should also update RootMoveList to avoid bogus output.
if (!RootNode && tte && (PvNode ? tte->depth() >= depth && tte->type() == BOUND_EXACT if (!RootNode && tte && (PvNode ? tte->depth() >= depth && tte->type() == BOUND_EXACT
: can_return_tt(tte, depth, beta, ss->ply))) : can_return_tt(tte, depth, ttValue, beta)))
{ {
TT.refresh(tte); TT.refresh(tte);
ss->currentMove = ttMove; // Can be MOVE_NONE ss->currentMove = ttMove; // Can be MOVE_NONE
value = value_from_tt(tte->value(), ss->ply);
if ( value >= beta if ( ttValue >= beta
&& ttMove && ttMove
&& !pos.is_capture_or_promotion(ttMove) && !pos.is_capture_or_promotion(ttMove)
&& ttMove != ss->killers[0]) && ttMove != ss->killers[0])
@ -633,7 +633,7 @@ namespace {
ss->killers[1] = ss->killers[0]; ss->killers[1] = ss->killers[0];
ss->killers[0] = ttMove; ss->killers[0] = ttMove;
} }
return value; return ttValue;
} }
// Step 5. Evaluate the position statically and update parent's gain statistics // Step 5. Evaluate the position statically and update parent's gain statistics
@ -645,7 +645,7 @@ namespace {
ss->eval = tte->static_value(); ss->eval = tte->static_value();
ss->evalMargin = tte->static_value_margin(); ss->evalMargin = tte->static_value_margin();
refinedValue = refine_eval(tte, ss->eval, ss->ply); refinedValue = refine_eval(tte, ttValue, ss->eval);
} }
else else
{ {
@ -878,8 +878,6 @@ split_point_start: // At split points actual search starts from here
&& move == ttMove && move == ttMove
&& pos.pl_move_is_legal(move, ci.pinned)) && pos.pl_move_is_legal(move, ci.pinned))
{ {
Value ttValue = value_from_tt(tte->value(), ss->ply);
if (abs(ttValue) < VALUE_KNOWN_WIN) if (abs(ttValue) < VALUE_KNOWN_WIN)
{ {
Value rBeta = ttValue - int(depth); Value rBeta = ttValue - int(depth);
@ -1139,7 +1137,7 @@ split_point_start: // At split points actual search starts from here
StateInfo st; StateInfo st;
Move ttMove, move, bestMove; Move ttMove, move, bestMove;
Value bestValue, value, evalMargin, futilityValue, futilityBase; Value ttValue, bestValue, value, evalMargin, futilityValue, futilityBase;
bool inCheck, enoughMaterial, givesCheck, evasionPrunable; bool inCheck, enoughMaterial, givesCheck, evasionPrunable;
const TTEntry* tte; const TTEntry* tte;
Depth ttDepth; Depth ttDepth;
@ -1163,11 +1161,12 @@ split_point_start: // At split points actual search starts from here
// pruning, but only for move ordering. // pruning, but only for move ordering.
tte = TT.probe(pos.key()); tte = TT.probe(pos.key());
ttMove = (tte ? tte->move() : MOVE_NONE); ttMove = (tte ? tte->move() : MOVE_NONE);
ttValue = tte ? value_from_tt(tte->value(),ss->ply) : VALUE_ZERO;
if (!PvNode && tte && can_return_tt(tte, ttDepth, beta, ss->ply)) if (!PvNode && tte && can_return_tt(tte, ttDepth, ttValue, beta))
{ {
ss->currentMove = ttMove; // Can be MOVE_NONE ss->currentMove = ttMove; // Can be MOVE_NONE
return value_from_tt(tte->value(), ss->ply); return ttValue;
} }
// Evaluate the position statically // Evaluate the position statically
@ -1485,9 +1484,7 @@ split_point_start: // At split points actual search starts from here
// can_return_tt() returns true if a transposition table score can be used to // can_return_tt() returns true if a transposition table score can be used to
// cut-off at a given point in search. // cut-off at a given point in search.
bool can_return_tt(const TTEntry* tte, Depth depth, Value beta, int ply) { bool can_return_tt(const TTEntry* tte, Depth depth, Value v, Value beta) {
Value v = value_from_tt(tte->value(), ply);
return ( tte->depth() >= depth return ( tte->depth() >= depth
|| v >= std::max(VALUE_MATE_IN_MAX_PLY, beta) || v >= std::max(VALUE_MATE_IN_MAX_PLY, beta)
@ -1501,12 +1498,10 @@ 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.
Value refine_eval(const TTEntry* tte, Value defaultEval, int ply) { Value refine_eval(const TTEntry* tte, Value v, Value defaultEval) {
assert(tte); assert(tte);
Value v = value_from_tt(tte->value(), ply);
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))
return v; return v;