Move pv[MAX_PLY+1], quietsSearched[64];
StateInfo st;
TTEntry* tte;
- bool ttHit;
SplitPoint* splitPoint;
Key posKey;
Move ttMove, move, excludedMove, bestMove;
Depth extension, newDepth, predictedDepth;
Value bestValue, value, ttValue, eval, nullValue, futilityValue;
- bool inCheck, givesCheck, singularExtensionNode, improving;
+ bool ttHit, inCheck, givesCheck, singularExtensionNode, improving;
bool captureOrPromotion, dangerous, doFullDepthSearch;
int moveCount, quietCount;
tte->save(posKey, value_to_tt(value, ss->ply), BOUND_EXACT,
std::min(DEPTH_MAX - ONE_PLY, depth + 6 * ONE_PLY),
- MOVE_NONE, VALUE_NONE, TT.get_generation());
+ MOVE_NONE, VALUE_NONE, TT.generation());
return value;
}
eval = ss->staticEval =
(ss-1)->currentMove != MOVE_NULL ? evaluate(pos) : -(ss-1)->staticEval + 2 * Eval::Tempo;
- tte->save(posKey, VALUE_NONE, BOUND_NONE, DEPTH_NONE, MOVE_NONE, ss->staticEval, TT.get_generation());
+ tte->save(posKey, VALUE_NONE, BOUND_NONE, DEPTH_NONE, MOVE_NONE, ss->staticEval, TT.generation());
}
if (ss->skipEarlyPruning)
tte->save(posKey, value_to_tt(bestValue, ss->ply),
bestValue >= beta ? BOUND_LOWER :
PvNode && bestMove ? BOUND_EXACT : BOUND_UPPER,
- depth, bestMove, ss->staticEval, TT.get_generation());
+ depth, bestMove, ss->staticEval, TT.generation());
assert(bestValue > -VALUE_INFINITE && bestValue < VALUE_INFINITE);
Move pv[MAX_PLY+1];
StateInfo st;
TTEntry* tte;
- bool ttHit;
Key posKey;
Move ttMove, move, bestMove;
Value bestValue, value, ttValue, futilityValue, futilityBase, oldAlpha;
- bool givesCheck, evasionPrunable;
+ bool ttHit, givesCheck, evasionPrunable;
Depth ttDepth;
if (PvNode)
{
if (!ttHit)
tte->save(pos.key(), value_to_tt(bestValue, ss->ply), BOUND_LOWER,
- DEPTH_NONE, MOVE_NONE, ss->staticEval, TT.get_generation());
+ DEPTH_NONE, MOVE_NONE, ss->staticEval, TT.generation());
return bestValue;
}
else // Fail high
{
tte->save(posKey, value_to_tt(value, ss->ply), BOUND_LOWER,
- ttDepth, move, ss->staticEval, TT.get_generation());
+ ttDepth, move, ss->staticEval, TT.generation());
return value;
}
tte->save(posKey, value_to_tt(bestValue, ss->ply),
PvNode && bestValue > oldAlpha ? BOUND_EXACT : BOUND_UPPER,
- ttDepth, bestMove, ss->staticEval, TT.get_generation());
+ ttDepth, bestMove, ss->staticEval, TT.generation());
assert(bestValue > -VALUE_INFINITE && bestValue < VALUE_INFINITE);
TTEntry* tte = TT.probe(pos.key(), ttHit);
if (!ttHit || tte->move() != pv[idx]) // Don't overwrite correct entries
- tte->save(pos.key(), VALUE_NONE, BOUND_NONE, DEPTH_NONE, pv[idx], VALUE_NONE, TT.get_generation());
+ tte->save(pos.key(), VALUE_NONE, BOUND_NONE, DEPTH_NONE, pv[idx], VALUE_NONE, TT.generation());
assert(MoveList<LEGAL>(pos).contains(pv[idx]));
}
-/// TranspositionTable::probe() looks up the current position in the
-/// transposition table. It returns true and a pointer to the TTEntry if
-/// the position is found. Otherwise, it returns false and a pointer to an empty or
-/// least valuable TTEntry to be replaced later. A TTEntry t1 is considered
-/// to be more valuable than a TTEntry t2 if t1 is from the current search and t2
-/// is from a previous search, or if the depth of t1 is bigger than the depth of t2.
+/// TranspositionTable::probe() looks up the current position in the transposition
+/// table. It returns true and a pointer to the TTEntry if the position is found.
+/// Otherwise, it returns false and a pointer to an empty or least valuable TTEntry
+/// to be replaced later. A TTEntry t1 is considered to be more valuable than a
+/// TTEntry t2 if t1 is from the current search and t2 is from a previous search,
+/// or if the depth of t1 is bigger than the depth of t2.
TTEntry* TranspositionTable::probe(const Key key, bool& found) const {
if (!tte[i].key16 || tte[i].key16 == key16)
{
if (tte[i].key16)
- tte[i].genBound8 = uint8_t(generation | tte[i].bound()); // Refresh
+ tte[i].genBound8 = uint8_t(generation8 | tte[i].bound()); // Refresh
- found = (bool)tte[i].key16;
- return &tte[i];
+ return found = (bool)tte[i].key16, &tte[i];
}
// Find an entry to be replaced according to the replacement strategy
TTEntry* replace = tte;
for (unsigned i = 1; i < TTClusterSize; ++i)
- if ( (( tte[i].genBound8 & 0xFC) == generation || tte[i].bound() == BOUND_EXACT)
- - ((replace->genBound8 & 0xFC) == generation)
+ if ( (( tte[i].genBound8 & 0xFC) == generation8 || tte[i].bound() == BOUND_EXACT)
+ - ((replace->genBound8 & 0xFC) == generation8)
- (tte[i].depth8 < replace->depth8) < 0)
replace = &tte[i];
- found = false;
- return replace;
+ return found = false, replace;
}
void save(Key k, Value v, Bound b, Depth d, Move m, Value ev, uint8_t g) {
- k >>= 48;
- if (m || k != key16) // preserve any existing ttMove
+ if (m || (k >> 48) != key16) // Preserve any existing move for the same position
move16 = (uint16_t)m;
- key16 = (uint16_t)k;
+
+ key16 = (uint16_t)(k >> 48);
value16 = (int16_t)v;
evalValue = (int16_t)ev;
genBound8 = (uint8_t)(g | b);
public:
~TranspositionTable() { free(mem); }
- void new_search() { generation += 4; } // Lower 2 bits are used by Bound
- uint8_t get_generation() const { return generation; }
+ void new_search() { generation8 += 4; } // Lower 2 bits are used by Bound
+ uint8_t generation() const { return generation8; }
TTEntry* probe(const Key key, bool& found) const;
TTEntry* first_entry(const Key key) const;
void resize(size_t mbSize);
size_t clusterCount;
TTCluster* table;
void* mem;
- uint8_t generation; // Size must be not bigger than TTEntry::genBound8
+ uint8_t generation8; // Size must be not bigger than TTEntry::genBound8
};
extern TranspositionTable TT;