- for (unsigned i = 0; i < ClusterSize; i++, tte++)
- {
- if (!tte->key() || tte->key() == key32) // Empty or overwrite old
+
+/// 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. The replace value of an entry is calculated as its depth
+/// minus 8 times its relative age. TTEntry t1 is considered more valuable than
+/// TTEntry t2 if its replace value is greater than that of t2.
+
+TTEntry* TranspositionTable::probe(const Key key, bool& found) const {
+
+ TTEntry* const tte = first_entry(key);
+ const uint16_t key16 = (uint16_t)key; // Use the low 16 bits as key inside the cluster
+
+ for (int i = 0; i < ClusterSize; ++i)
+ if (tte[i].key16 == key16 || !tte[i].depth8)