public HashEntry(UInt64 key, Move move, int score, int searchDepth, HashEntryTypes type) { HashKey = key; Move = move; Score = score; SearchDepth = searchDepth; Type = type; IsStale = false; }
public HashEntryTypes LookupPosition(Board board, int desiredDepth, int currentPly, Sides currentSide, ref int alpha, ref int beta) { UInt64 hashKey = currentSide == Sides.White ? board.HashKey : ~board.HashKey; HashEntryTypes result = LookupPosition(_GlobalTable, hashKey, desiredDepth, currentPly, currentSide, ref alpha, ref beta); if (result == HashEntryTypes.Junk) { result = LookupPosition(_LocalTable, hashKey, desiredDepth, currentPly, currentSide, ref alpha, ref beta); } return(result); }
public void AddPosition(Board board, Move bestMove, int score, int searchDepth, int currentPly, Sides currentSide, HashEntryTypes type) { score = StaticEvaluator.RemovePlyDependence(score); UInt64 hashKey = currentSide == Sides.White ? board.HashKey : ~board.HashKey; UInt64 globalTableIndex = hashKey % (UInt64)_GlobalTable.Length; UInt64 localTableIndex = hashKey % (UInt64)_LocalTable.Length; HashEntry globalEntry = _GlobalTable[globalTableIndex]; if (globalEntry.IsStale) { _GlobalTable[globalTableIndex] = new HashEntry(hashKey, bestMove, score, searchDepth, type); } else { bool isMoreValuable = searchDepth > globalEntry.SearchDepth || searchDepth == globalEntry.SearchDepth && type == HashEntryTypes.Exact; if (globalEntry.HashKey == hashKey) { bool improvesBound = searchDepth == globalEntry.SearchDepth && (type == HashEntryTypes.LowerBound && globalEntry.Type == HashEntryTypes.LowerBound && score > globalEntry.Score || type == HashEntryTypes.UpperBound && globalEntry.Type == HashEntryTypes.LowerBound && score < globalEntry.Score); if (isMoreValuable || improvesBound) { _GlobalTable[globalTableIndex] = new HashEntry(hashKey, bestMove, score, searchDepth, type); } } else { if (isMoreValuable) { _GlobalTable[globalTableIndex] = new HashEntry(hashKey, bestMove, score, searchDepth, type); _LocalTable[localTableIndex] = globalEntry; } else { _LocalTable[localTableIndex] = new HashEntry(hashKey, bestMove, score, searchDepth, type); } } } }