internal static bool probe(Key posKey, ref UInt32 ttePos, out TTEntry entry) { UInt32 posKey32 = (UInt32)(posKey >> 32); UInt32 offset = (((UInt32)posKey) & sizeMask) << 2; for (UInt32 i = offset; i < (Constants.ClusterSize + offset); i++) { if (entries[i].key == posKey32) { ttePos = i; entry = entries[i]; return(true); } } entry = StaticEntry; return(false); }
/// TranspositionTable::store() writes a new entry containing position key and /// valuable information of current position. The lowest order bits of position /// key are used to decide on which cluster the position will be placed. /// When a new entry is written and there are no empty entries available in cluster, /// it replaces the least valuable of entries. 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. internal static void store(Key posKey, Value v, Bound t, Depth d, Move m, Value statV, Value kingD) { UInt32 posKey32 = (UInt32)(posKey >> 32); // Use the high 32 bits as key inside the cluster UInt32 ttePos = 0; UInt32 replacePos = 0; ttePos = replacePos = (((UInt32)posKey) & sizeMask) << 2; for (UInt32 i = 0; i < Constants.ClusterSize; i++) { TTEntry tte = entries[ttePos]; if ((tte.key == 0) || tte.key == posKey32) // Empty or overwrite old { // Preserve any existing ttMove if (m == MoveC.MOVE_NONE) { m = (Move)tte.move16; } entries[ttePos].save(posKey32, v, t, d, m, generation, statV, kingD); return; } // Implement replace strategy //if ((entries[replacePos].generation8 == generation ? 2 : 0) + (tte.generation8 == generation || tte.bound == 3/*Bound.BOUND_EXACT*/ ? -2 : 0) + (tte.depth16 < entries[replacePos].depth16 ? 1 : 0) > 0) //{ // replacePos = ttePos; //} if (entries[replacePos].generation8 == generation) { // +2 if (tte.generation8 == generation || tte.bound == 3 /*Bound.BOUND_EXACT*/) { // 0 if (tte.depth16 < entries[replacePos].depth16) { // +1 replacePos = ttePos; } } else { // +2 replacePos = ttePos; } } else { // 0 if ((!(tte.generation8 == generation || tte.bound == 3 /*Bound.BOUND_EXACT*/)) && (tte.depth16 < entries[replacePos].depth16)) { // +1 replacePos = ttePos; } } ttePos++; } entries[replacePos].save(posKey32, v, t, d, m, generation, statV, kingD); }