// Transposition table lookup. At PV nodes, we don't use the TT for
// pruning, but only for move ordering.
- const TTEntry* tte = TT.retrieve(pos);
+ const TTEntry* tte = TT.retrieve(pos.get_key());
Move ttMove = (tte ? tte->move() : MOVE_NONE);
// Go with internal iterative deepening if we don't have a TT move
return bestValue;
if (bestValue <= oldAlpha)
- TT.store(pos, value_to_tt(bestValue, ply), VALUE_TYPE_UPPER, depth, MOVE_NONE);
+ TT.store(pos.get_key(), value_to_tt(bestValue, ply), VALUE_TYPE_UPPER, depth, MOVE_NONE);
else if (bestValue >= beta)
{
update_history(pos, m, depth, movesSearched, moveCount);
update_killers(m, ss[ply]);
}
- TT.store(pos, value_to_tt(bestValue, ply), VALUE_TYPE_LOWER, depth, m);
+ TT.store(pos.get_key(), value_to_tt(bestValue, ply), VALUE_TYPE_LOWER, depth, m);
}
else
- TT.store(pos, value_to_tt(bestValue, ply), VALUE_TYPE_EXACT, depth, ss[ply].pv[ply]);
+ TT.store(pos.get_key(), value_to_tt(bestValue, ply), VALUE_TYPE_EXACT, depth, ss[ply].pv[ply]);
return bestValue;
}
return beta - 1;
// Transposition table lookup
- const TTEntry* tte = TT.retrieve(pos);
+ const TTEntry* tte = TT.retrieve(pos.get_key());
Move ttMove = (tte ? tte->move() : MOVE_NONE);
if (tte && ok_to_use_TT(tte, depth, beta, ply))
return bestValue;
if (bestValue < beta)
- TT.store(pos, value_to_tt(bestValue, ply), VALUE_TYPE_UPPER, depth, MOVE_NONE);
+ TT.store(pos.get_key(), value_to_tt(bestValue, ply), VALUE_TYPE_UPPER, depth, MOVE_NONE);
else
{
BetaCounter.add(pos.side_to_move(), depth, threadID);
update_history(pos, m, depth, movesSearched, moveCount);
update_killers(m, ss[ply]);
}
- TT.store(pos, value_to_tt(bestValue, ply), VALUE_TYPE_LOWER, depth, m);
+ TT.store(pos.get_key(), value_to_tt(bestValue, ply), VALUE_TYPE_LOWER, depth, m);
}
assert(bestValue > -VALUE_INFINITE && bestValue < VALUE_INFINITE);
bool pvNode = (beta - alpha != 1);
if (!pvNode)
{
- tte = TT.retrieve(pos);
+ tte = TT.retrieve(pos.get_key());
if (tte && ok_to_use_TT(tte, depth, beta, ply))
{
assert(tte->type() != VALUE_TYPE_EVAL);
{
// Store the score to avoid a future costly evaluation() call
if (!isCheck && !tte && ei.futilityMargin == 0)
- TT.store(pos, value_to_tt(bestValue, ply), VALUE_TYPE_EVAL, Depth(-127*OnePly), MOVE_NONE);
+ TT.store(pos.get_key(), value_to_tt(bestValue, ply), VALUE_TYPE_EVAL, Depth(-127*OnePly), MOVE_NONE);
return bestValue;
}
{
Depth d = (depth == Depth(0) ? Depth(0) : Depth(-1));
if (bestValue < beta)
- TT.store(pos, value_to_tt(bestValue, ply), VALUE_TYPE_UPPER, d, MOVE_NONE);
+ TT.store(pos.get_key(), value_to_tt(bestValue, ply), VALUE_TYPE_UPPER, d, MOVE_NONE);
else
- TT.store(pos, value_to_tt(bestValue, ply), VALUE_TYPE_LOWER, d, m);
+ TT.store(pos.get_key(), value_to_tt(bestValue, ply), VALUE_TYPE_LOWER, d, m);
}
// Update killers only for good check moves
/// is bigger than the depth of t2. A TTEntry of type VALUE_TYPE_EVAL
/// never replaces another entry for the same position.
-void TranspositionTable::store(const Position& p, Value v, ValueType t, Depth d, Move m) {
+void TranspositionTable::store(const Key posKey, Value v, ValueType t, Depth d, Move m) {
TTEntry *tte, *replace;
- tte = replace = first_entry(p);
+ tte = replace = first_entry(posKey);
for (int i = 0; i < 4; i++, tte++)
{
- if (!tte->key() || tte->key() == p.get_key()) // empty or overwrite old
+ if (!tte->key() || tte->key() == posKey) // empty or overwrite old
{
// Do not overwrite when new type is VALUE_TYPE_EVAL
if (tte->key() && t == VALUE_TYPE_EVAL)
if (m == MOVE_NONE)
m = tte->move();
- *tte = TTEntry(p.get_key(), v, t, d, m, generation);
+ *tte = TTEntry(posKey, v, t, d, m, generation);
return;
}
else if (i == 0) // replace would be a no-op in this common case
if (c1 + c2 + c3 > 0)
replace = tte;
}
- *replace = TTEntry(p.get_key(), v, t, d, m, generation);
+ *replace = TTEntry(posKey, v, t, d, m, generation);
writes++;
}
/// transposition table. Returns a pointer to the TTEntry or NULL
/// if position is not found.
-TTEntry* TranspositionTable::retrieve(const Position& pos) const {
+TTEntry* TranspositionTable::retrieve(const Key posKey) const {
- TTEntry *tte = first_entry(pos);
+ TTEntry *tte = first_entry(posKey);
for (int i = 0; i < 4; i++, tte++)
- if (tte->key() == pos.get_key())
+ if (tte->key() == posKey)
return tte;
return NULL;
/// TranspositionTable::first_entry returns a pointer to the first
/// entry of a cluster given a position.
-inline TTEntry* TranspositionTable::first_entry(const Position& pos) const {
+inline TTEntry* TranspositionTable::first_entry(const Key posKey) const {
- return entries + (int(pos.get_key() & (size - 1)) << 2);
+ return entries + (int(posKey & (size - 1)) << 2);
}
/// TranspositionTable::new_search() is called at the beginning of every new
for (int i = 0; pv[i] != MOVE_NONE; i++)
{
- store(p, VALUE_NONE, VALUE_TYPE_NONE, Depth(-127*OnePly), pv[i]);
+ store(p.get_key(), VALUE_NONE, VALUE_TYPE_NONE, Depth(-127*OnePly), pv[i]);
p.do_move(pv[i], st);
}
}