From d5f3071733b00ce9379432d9a7f0c41efedf7d84 Mon Sep 17 00:00:00 2001 From: nocturn9x Date: Thu, 2 May 2024 19:08:30 +0200 Subject: [PATCH] Remove useTT compile time flag --- Chess/nimfish/nimfishpkg/search.nim | 35 +++++++++++++---------------- Chess/nimfish/nimfishpkg/uci.nim | 9 ++++---- 2 files changed, 20 insertions(+), 24 deletions(-) diff --git a/Chess/nimfish/nimfishpkg/search.nim b/Chess/nimfish/nimfishpkg/search.nim index 3e4adbe..0e497e7 100644 --- a/Chess/nimfish/nimfishpkg/search.nim +++ b/Chess/nimfish/nimfishpkg/search.nim @@ -73,10 +73,9 @@ proc getEstimatedMoveScore(self: SearchManager, move: Move): Score = nonSideToMove = sideToMove.opposite() if self.previousBestMove != nullMove() and move == self.previousBestMove: return highestEval() + 1 - when defined(useTT): - let query = self.transpositionTable.get(self.board.position.zobristKey) - if query.success and query.entry.bestMove != nullMove() and query.entry.bestMove == move: - return highestEval() + 1 + let query = self.transpositionTable.get(self.board.position.zobristKey) + if query.success and query.entry.bestMove != nullMove() and query.entry.bestMove == move: + return highestEval() + 1 if move.isCapture(): # Implementation of MVVLVA: Most Valuable Victim Least Valuable Attacker # We prioritize moves that capture the most valuable pieces, and as a @@ -223,19 +222,18 @@ proc search(self: SearchManager, depth, ply: int, alpha, beta: Score): Score {.d # one because then we wouldn't have a move to return. # In practice this should not be a problem return - when defined(useTT): - if ply > 0: - let query = self.transpositionTable.get(self.board.position.zobristKey, depth.uint8) - if query.success: - case query.entry.flag: - of Exact: + if ply > 0: + let query = self.transpositionTable.get(self.board.position.zobristKey, depth.uint8) + if query.success: + case query.entry.flag: + of Exact: + return query.entry.score + of LowerBound: + if query.entry.score >= beta: + return query.entry.score + of UpperBound: + if query.entry.score <= alpha: return query.entry.score - of LowerBound: - if query.entry.score >= beta: - return query.entry.score - of UpperBound: - if query.entry.score <= alpha: - return query.entry.score if self.board.drawnByRepetition(): return Score(0) if depth == 0: @@ -299,9 +297,8 @@ proc search(self: SearchManager, depth, ply: int, alpha, beta: Score): Score {.d if ply == 0: self.bestMoveRoot = move self.bestRootScore = bestScore - when defined(useTT): - let nodeType = if bestScore >= beta: LowerBound elif bestScore <= alpha: UpperBound else: Exact - self.transpositionTable.store(depth.uint8, bestScore, self.board.position.zobristKey, bestMove, nodeType) + let nodeType = if bestScore >= beta: LowerBound elif bestScore <= alpha: UpperBound else: Exact + self.transpositionTable.store(depth.uint8, bestScore, self.board.position.zobristKey, bestMove, nodeType) return bestScore diff --git a/Chess/nimfish/nimfishpkg/uci.nim b/Chess/nimfish/nimfishpkg/uci.nim index 490079e..5e86519 100644 --- a/Chess/nimfish/nimfishpkg/uci.nim +++ b/Chess/nimfish/nimfishpkg/uci.nim @@ -353,11 +353,10 @@ proc startUCISession* = of NewGame: session.board = newDefaultChessboard() of Go: - when defined(useTT): - if session.transpositionTable.isNil() or session.transpositionTable.size() == 0: - session.transpositionTable = newTranspositionTable(session.hashTableSize * 1024 * 1024) - if session.debug: - echo &"info string created {session.hashTableSize} MiB TT" + if session.transpositionTable.isNil() or session.transpositionTable.size() == 0: + session.transpositionTable = newTranspositionTable(session.hashTableSize * 1024 * 1024) + if session.debug: + echo &"info string created {session.hashTableSize} MiB TT" session.searchThread = new Thread[tuple[session: UCISession, command: UCICommand]] createThread(session.searchThread[], bestMove, (session, cmd)) if session.debug: