From 6155f47cadc596023d6584d35b0f9c23ef8f9dc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20C=C3=A1ceres?= Date: Tue, 31 Oct 2023 00:06:02 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=B9=20Clean=20`Position.StaticEval()`?= =?UTF-8?q?=20(#480)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Stop passing unused `movesWithoutCaptureOrPawnMove` to `Position.StaticEval()` --- src/Lynx.Dev/Program.cs | 20 ++++++++++---------- src/Lynx/LynxDriver.cs | 2 +- src/Lynx/Model/Position.cs | 2 +- src/Lynx/Search/NegaMax.cs | 8 ++++---- tests/Lynx.Test/GameTest.cs | 2 +- tests/Lynx.Test/Model/PositionTest.cs | 4 ++-- 6 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/Lynx.Dev/Program.cs b/src/Lynx.Dev/Program.cs index e63c681ab..82429c0a3 100644 --- a/src/Lynx.Dev/Program.cs +++ b/src/Lynx.Dev/Program.cs @@ -956,38 +956,38 @@ static void FileAndRankMasks() static void EnhancedPawnEvaluation() { var position = new Position("4k3/ppp5/8/8/8/P7/PP6/4K3 w - - 0 1"); - var eval = position.StaticEvaluation(default); + var eval = position.StaticEvaluation(); position.Print(); Console.WriteLine(eval); position = new Position("4k3/pp4pp/p7/8/8/P7/PPP3P1/4K3 w - - 0 1"); position.Print(); - eval = position.StaticEvaluation(default); + eval = position.StaticEvaluation(); Console.WriteLine(eval); position = new Position("4k3/pp3pp1/p7/8/8/P7/PPP4P/4K3 w - - 0 1"); position.Print(); - eval = position.StaticEvaluation(default); + eval = position.StaticEvaluation(); Console.WriteLine(eval); position = new Position("4k3/pp3pp1/p7/8/8/P7/PP3P1P/4K3 w - - 0 1"); position.Print(); - eval = position.StaticEvaluation(default); + eval = position.StaticEvaluation(); Console.WriteLine(eval); position = new Position("4k3/pp2pp2/p7/8/8/P7/PP3P1P/4K3 w - - 0 1"); position.Print(); - eval = position.StaticEvaluation(default); + eval = position.StaticEvaluation(); Console.WriteLine(eval); position = new Position("4k3/pp2pp2/p7/8/7P/P7/PP3P2/4K3 w - - 0 1"); position.Print(); - eval = position.StaticEvaluation(default); + eval = position.StaticEvaluation(); Console.WriteLine(eval); position = new Position("4k3/pp2pp1P/p7/8/8/P7/PP3P2/4K3 w - - 0 1"); position.Print(); - eval = position.StaticEvaluation(default); + eval = position.StaticEvaluation(); Console.WriteLine(eval); } @@ -995,17 +995,17 @@ static void RookEvaluation() { var position = new Position("r3k3/7p/8/8/8/8/7P/4K2R w - - 0 1"); position.Print(); - var eval = position.StaticEvaluation(default); + var eval = position.StaticEvaluation(); Console.WriteLine(eval); position = new Position("r3k3/1p6/8/8/8/8/7P/4K2R w - - 0 1"); position.Print(); - eval = position.StaticEvaluation(default); + eval = position.StaticEvaluation(); Console.WriteLine(eval); position = new Position("r3k3/1P6/8/8/8/8/7p/4K2R w - - 0 1"); position.Print(); - eval = position.StaticEvaluation(default); + eval = position.StaticEvaluation(); Console.WriteLine(eval); } diff --git a/src/Lynx/LynxDriver.cs b/src/Lynx/LynxDriver.cs index 7c3c92d64..2cec43be8 100644 --- a/src/Lynx/LynxDriver.cs +++ b/src/Lynx/LynxDriver.cs @@ -390,7 +390,7 @@ private async ValueTask HandleStaticEval(string rawCommand, CancellationToken ca _logger.Debug("Raw fen: {0}, parsed fen: {1}", fen, ourFen); } - var eval = WDL.NormalizeScore(position.StaticEvaluation(0)); + var eval = WDL.NormalizeScore(position.StaticEvaluation()); if (position.Side == Side.Black) { eval = -eval; // White perspective diff --git a/src/Lynx/Model/Position.cs b/src/Lynx/Model/Position.cs index cccf105f3..fd4a9fb21 100644 --- a/src/Lynx/Model/Position.cs +++ b/src/Lynx/Model/Position.cs @@ -591,7 +591,7 @@ public string FEN(int halfMovesWithoutCaptureOrPawnMove = 0, int fullMoveClock = /// /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public int StaticEvaluation(int movesWithoutCaptureOrPawnMove) + public int StaticEvaluation() { //var result = OnlineTablebaseProber.EvaluationSearch(this, movesWithoutCaptureOrPawnMove, cancellationToken); //Debug.Assert(result < EvaluationConstants.CheckMateBaseEvaluation, $"position {FEN()} returned tb eval out of bounds: {result}"); diff --git a/src/Lynx/Search/NegaMax.cs b/src/Lynx/Search/NegaMax.cs index d84beaf50..76ed250c8 100644 --- a/src/Lynx/Search/NegaMax.cs +++ b/src/Lynx/Search/NegaMax.cs @@ -26,7 +26,7 @@ private int NegaMax(int depth, int ply, int alpha, int beta, bool parentWasNullM if (ply >= Configuration.EngineSettings.MaxDepth) { _logger.Info("Max depth {0} reached", Configuration.EngineSettings.MaxDepth); - return position.StaticEvaluation(Game.HalfMovesWithoutCaptureOrPawnMove); + return position.StaticEvaluation(); } _maxDepthReached[ply] = ply; @@ -73,7 +73,7 @@ private int NegaMax(int depth, int ply, int alpha, int beta, bool parentWasNullM if (!pvNode && !isInCheck) { - var staticEval = position.StaticEvaluation(Game.HalfMovesWithoutCaptureOrPawnMove); + var staticEval = position.StaticEvaluation(); // 🔍 Null Move Pruning (NMP) - our position is so good that we can potentially afford giving ouropponent a double move and still remain ahead of beta if (depth >= Configuration.EngineSettings.NMP_MinDepth @@ -351,7 +351,7 @@ public int QuiescenceSearch(int ply, int alpha, int beta) if (ply >= Configuration.EngineSettings.MaxDepth) { _logger.Info("Max depth {0} reached", Configuration.EngineSettings.MaxDepth); - return position.StaticEvaluation(Game.HalfMovesWithoutCaptureOrPawnMove); + return position.StaticEvaluation(); } var pvIndex = PVTable.Indexes[ply]; @@ -369,7 +369,7 @@ public int QuiescenceSearch(int ply, int alpha, int beta) _maxDepthReached[ply] = ply; - var staticEvaluation = position.StaticEvaluation(Game.HalfMovesWithoutCaptureOrPawnMove); + var staticEvaluation = position.StaticEvaluation(); // Fail-hard beta-cutoff (updating alpha after this check) if (staticEvaluation >= beta) diff --git a/tests/Lynx.Test/GameTest.cs b/tests/Lynx.Test/GameTest.cs index e9d7135b3..72e98f573 100644 --- a/tests/Lynx.Test/GameTest.cs +++ b/tests/Lynx.Test/GameTest.cs @@ -158,7 +158,7 @@ public void IsThreefoldRepetition_CastleRightsRemoval() Assert.DoesNotThrow(() => game.MakeMove(repeatedMoves[^1])); Assert.AreEqual(repeatedMoves.Count, game.MoveHistory.Count); - var eval = winningPosition.StaticEvaluation(default); + var eval = winningPosition.StaticEvaluation(); Assert.AreNotEqual(0, eval); Assert.DoesNotThrow(() => game.MakeMove(repeatedMoves[5])); diff --git a/tests/Lynx.Test/Model/PositionTest.cs b/tests/Lynx.Test/Model/PositionTest.cs index a361283b7..26f040b33 100644 --- a/tests/Lynx.Test/Model/PositionTest.cs +++ b/tests/Lynx.Test/Model/PositionTest.cs @@ -176,7 +176,7 @@ public void StaticEvaluation_DrawDueToLackOfMaterial(string fen) { var position = new Position(fen); - Assert.AreEqual(0, position.StaticEvaluation(default)); + Assert.AreEqual(0, position.StaticEvaluation()); } [TestCase("4k3/8/8/7Q/7q/8/4K3/8 w - - 0 1", "4k3/8/8/7Q/7q/8/8/4K3 w - - 0 1", Description = "King in 7th rank with queens > King in 8th rank with queens")] @@ -184,7 +184,7 @@ public void StaticEvaluation_DrawDueToLackOfMaterial(string fen) [TestCase("4k3/7p/8/8/4K3/8/7P/8 w - - 0 1", "4k3/7p/8/q7/4K3/Q7/7P/8 w - - 0 1", Description = "King in the center without queens > King in the center with queens")] public void StaticEvaluation_KingEndgame(string fen1, string fen2) { - Assert.Greater(new Position(fen1).StaticEvaluation(default), new Position(fen2).StaticEvaluation(default)); + Assert.Greater(new Position(fen1).StaticEvaluation(), new Position(fen2).StaticEvaluation()); } ///