Skip to content

Commit

Permalink
Save always static eval (no final position eval) + re-use TT static e…
Browse files Browse the repository at this point in the history
…val in QSearch
  • Loading branch information
eduherminio committed Jan 2, 2025
1 parent d4eadb8 commit 2a72cd6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
6 changes: 4 additions & 2 deletions src/Lynx/Model/TranspositionTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ public void PrefetchTTEntry(Position position)
// We want to translate the checkmate position relative to the saved node to our root position from which we're searching
// If the recorded score is a checkmate in 3 and we are at depth 5, we want to read checkmate in 8
var recalculatedScore = RecalculateMateScores(entry.Score, ply);
var recalculatedStaticEval = RecalculateMateScores(entry.StaticEval, ply);

return (recalculatedScore, entry.Move, entry.Type, entry.StaticEval, entry.Depth);
return (recalculatedScore, entry.Move, entry.Type, recalculatedStaticEval, entry.Depth);
}

/// <summary>
Expand Down Expand Up @@ -105,8 +106,9 @@ public void RecordHash(Position position, int staticEval, int depth, int ply, in
// We want to store the distance to the checkmate position relative to the current node, independently from the root
// If the evaluated score is a checkmate in 8 and we're at depth 5, we want to store checkmate value in 3
var recalculatedScore = RecalculateMateScores(score, -ply);
var recalculatedStaticEval = RecalculateMateScores(staticEval, -ply);

entry.Update(position.UniqueIdentifier, recalculatedScore, staticEval, depth, nodeType, move);
entry.Update(position.UniqueIdentifier, recalculatedScore, recalculatedStaticEval, depth, nodeType, move);
}

/// <summary>
Expand Down
7 changes: 2 additions & 5 deletions src/Lynx/Search/NegaMax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ void RevertMove()
Debug.Assert(bestMove is null);

var finalEval = Position.EvaluateFinalPosition(ply, isInCheck);
_tt.RecordHash(position, finalEval, depth, ply, finalEval, NodeType.Exact);
_tt.RecordHash(position, staticEval, depth, ply, finalEval, NodeType.Exact);

return finalEval;
}
Expand Down Expand Up @@ -556,13 +556,10 @@ public int QuiescenceSearch(int ply, int alpha, int beta, CancellationToken canc

_maxDepthReached[ply] = ply;

/*
var staticEval = ttHit
? ttProbeResult.StaticEval
: position.StaticEvaluation(Game.HalfMovesWithoutCaptureOrPawnMove).Score;
*/

var staticEval = position.StaticEvaluation(Game.HalfMovesWithoutCaptureOrPawnMove).Score;
Debug.Assert(staticEval != EvaluationConstants.NoHashEntry, "Assertion failed", "All TT entries should have a static eval");

Game.UpdateStaticEvalInStack(ply, staticEval);
Expand Down Expand Up @@ -677,7 +674,7 @@ public int QuiescenceSearch(int ply, int alpha, int beta, CancellationToken canc
Debug.Assert(bestMove is null);

var finalEval = Position.EvaluateFinalPosition(ply, position.IsInCheck());
_tt.RecordHash(position, finalEval, 0, ply, finalEval, NodeType.Exact);
_tt.RecordHash(position, staticEval, 0, ply, finalEval, NodeType.Exact);

return finalEval;
}
Expand Down

0 comments on commit 2a72cd6

Please sign in to comment.