From 17a0d70db0b52c2bba717b2a28e63a1f0c5daf7b Mon Sep 17 00:00:00 2001 From: rektdie Date: Sun, 2 Mar 2025 05:04:56 +0100 Subject: [PATCH] ordering TT moves first --- source/search.cpp | 9 +++++++-- source/tt.cpp | 5 +++-- source/tt.h | 3 ++- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/source/search.cpp b/source/search.cpp index f8fb4cf..491b25c 100644 --- a/source/search.cpp +++ b/source/search.cpp @@ -18,6 +18,11 @@ static int ScoreMove(Board &board, Move &move) { const int attackerType = board.GetPieceType(move.MoveFrom()); const int targetType = board.GetPieceType(move.MoveTo()); + TTEntry *current = &TTable[board.hashKey % hashSize]; + if (current->bestMove == move) { + return 50000; + } + if (move.IsCapture()) { return moveScoreTable[attackerType][targetType] + 10000; } @@ -182,7 +187,7 @@ SearchResults PVS(Board board, int depth, int alpha, int beta) { } if (score >= beta) { - WriteEntry(board.hashKey, depth, beta, CutNode); + WriteEntry(board.hashKey, depth, beta, CutNode, Move()); return beta; } @@ -195,7 +200,7 @@ SearchResults PVS(Board board, int depth, int alpha, int beta) { results.score = alpha; - WriteEntry(board.hashKey, depth, results.score, nodeType); + WriteEntry(board.hashKey, depth, results.score, nodeType, results.bestMove); return results; } diff --git a/source/tt.cpp b/source/tt.cpp index 65610bf..b19461f 100644 --- a/source/tt.cpp +++ b/source/tt.cpp @@ -85,7 +85,7 @@ SearchResults ReadEntry(U64 &hashKey, int depth, int alpha, int beta) { if (current->hashKey == hashKey) { if (current->depth >= depth) { if (current->nodeType == PV){ - return current->score; + return {current->score, current->bestMove}; } else if (current->nodeType == AllNode && current->score <= alpha) { return alpha; } else if (current->nodeType == CutNode && current->score >= beta) { @@ -98,11 +98,12 @@ SearchResults ReadEntry(U64 &hashKey, int depth, int alpha, int beta) { return invalidEntry; } -void WriteEntry(U64 &hashKey, int depth, int score, int nodeType) { +void WriteEntry(U64 &hashKey, int depth, int score, int nodeType, Move bestMove) { TTEntry *current = &TTable[hashKey % hashSize]; current->hashKey = hashKey; current->nodeType = nodeType; current->score = score; current->depth = depth; + current->bestMove = bestMove; } diff --git a/source/tt.h b/source/tt.h index 9cb656c..1913bc9 100644 --- a/source/tt.h +++ b/source/tt.h @@ -25,9 +25,10 @@ public: int depth; int score; int nodeType; + Move bestMove; }; extern TTEntry TTable[hashSize]; SearchResults ReadEntry(U64 &hashKey, int depth, int alpha, int beta); -void WriteEntry(U64 &hashKey, int depth, int score, int nodeType); +void WriteEntry(U64 &hashKey, int depth, int score, int nodeType, Move besteMove); -- 2.47.3