From f015e56471d7cea15de6b0e0c940bf8c631e7cfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20C=C3=A1ceres?= Date: Thu, 16 May 2024 00:08:06 +0200 Subject: [PATCH 1/4] Remove pawn additional evaluation --- src/Lynx.Cli/appsettings.json | 84 +++++++++++++++++------------------ src/Lynx/Configuration.cs | 22 ++++----- src/Lynx/Model/Position.cs | 58 ++++++++++++------------ 3 files changed, 82 insertions(+), 82 deletions(-) diff --git a/src/Lynx.Cli/appsettings.json b/src/Lynx.Cli/appsettings.json index 43045a9e7..5a6f9f9b8 100644 --- a/src/Lynx.Cli/appsettings.json +++ b/src/Lynx.Cli/appsettings.json @@ -58,14 +58,14 @@ "FP_Margin": 250, // Evaluation - "DoubledPawnPenalty": { - "MG": -6, - "EG": -12 - }, - "IsolatedPawnPenalty": { - "MG": -17, - "EG": -13 - }, + //"DoubledPawnPenalty": { + // "MG": -6, + // "EG": -12 + //}, + //"IsolatedPawnPenalty": { + // "MG": -17, + // "EG": -13 + //}, "OpenFileRookBonus": { "MG": 47, "EG": 10 @@ -102,40 +102,40 @@ "MG": 31, "EG": 80 }, - "PassedPawnBonus": { - "Rank0": { - "MG": 0, - "EG": 0 - }, - "Rank1": { - "MG": -2, - "EG": 7 - }, - "Rank2": { - "MG": -15, - "EG": 13 - }, - "Rank3": { - "MG": -14, - "EG": 41 - }, - "Rank4": { - "MG": 20, - "EG": 74 - }, - "Rank5": { - "MG": 60, - "EG": 150 - }, - "Rank6": { - "MG": 98, - "EG": 217 - }, - "Rank7": { - "MG": 0, - "EG": 0 - } - } + //"PassedPawnBonus": { + // "Rank0": { + // "MG": 0, + // "EG": 0 + // }, + // "Rank1": { + // "MG": -2, + // "EG": 7 + // }, + // "Rank2": { + // "MG": -15, + // "EG": 13 + // }, + // "Rank3": { + // "MG": -14, + // "EG": 41 + // }, + // "Rank4": { + // "MG": 20, + // "EG": 74 + // }, + // "Rank5": { + // "MG": 60, + // "EG": 150 + // }, + // "Rank6": { + // "MG": 98, + // "EG": 217 + // }, + // "Rank7": { + // "MG": 0, + // "EG": 0 + // } + //} // End of evaluation }, diff --git a/src/Lynx/Configuration.cs b/src/Lynx/Configuration.cs index 0364442f7..b8c9d08d7 100644 --- a/src/Lynx/Configuration.cs +++ b/src/Lynx/Configuration.cs @@ -203,9 +203,9 @@ public sealed class EngineSettings #region Evaluation - public TaperedEvaluationTerm DoubledPawnPenalty { get; set; } = new(-6, -12); + //public TaperedEvaluationTerm DoubledPawnPenalty { get; set; } = new(-6, -12); - public TaperedEvaluationTerm IsolatedPawnPenalty { get; set; } = new(-17, -13); + //public TaperedEvaluationTerm IsolatedPawnPenalty { get; set; } = new(-17, -13); public TaperedEvaluationTerm OpenFileRookBonus { get; set; } = new(47, 10); @@ -225,15 +225,15 @@ public sealed class EngineSettings public TaperedEvaluationTerm BishopPairBonus { get; set; } = new(31, 80); - public TaperedEvaluationTermByRank PassedPawnBonus { get; set; } = new( - new(0, 0), - new(-2, 7), - new(-15, 13), - new(-14, 41), - new(20, 74), - new(60, 150), - new(98, 217), - new(0, 0)); + //public TaperedEvaluationTermByRank PassedPawnBonus { get; set; } = new( + // new(0, 0), + // new(-2, 7), + // new(-15, 13), + // new(-14, 41), + // new(20, 74), + // new(60, 150), + // new(98, 217), + // new(0, 0)); #endregion } diff --git a/src/Lynx/Model/Position.cs b/src/Lynx/Model/Position.cs index a4cd0a9cd..288dbb215 100644 --- a/src/Lynx/Model/Position.cs +++ b/src/Lynx/Model/Position.cs @@ -848,7 +848,7 @@ internal int AdditionalPieceEvaluation(int pieceSquareIndex, int pieceIndex) { return pieceIndex switch { - (int)Piece.P or (int)Piece.p => PawnAdditionalEvaluation(pieceSquareIndex, pieceIndex), + //(int)Piece.P or (int)Piece.p => PawnAdditionalEvaluation(pieceSquareIndex, pieceIndex), (int)Piece.R or (int)Piece.r => RookAdditionalEvaluation(pieceSquareIndex, pieceIndex), (int)Piece.B or (int)Piece.b => BishopAdditionalEvaluation(pieceSquareIndex, pieceIndex), (int)Piece.Q or (int)Piece.q => QueenAdditionalEvaluation(pieceSquareIndex), @@ -862,34 +862,34 @@ internal int AdditionalPieceEvaluation(int pieceSquareIndex, int pieceIndex) /// /// /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] - private int PawnAdditionalEvaluation(int squareIndex, int pieceIndex) - { - int packedBonus = 0; - - var doublePawnsCount = (PieceBitBoards[pieceIndex] & Masks.FileMasks[squareIndex]).CountBits(); - if (doublePawnsCount > 1) - { - packedBonus += doublePawnsCount * Configuration.EngineSettings.DoubledPawnPenalty.PackedEvaluation; - } - - if ((PieceBitBoards[pieceIndex] & Masks.IsolatedPawnMasks[squareIndex]) == default) // isIsolatedPawn - { - packedBonus += Configuration.EngineSettings.IsolatedPawnPenalty.PackedEvaluation; - } - - if ((PieceBitBoards[(int)Piece.p - pieceIndex] & Masks.PassedPawns[pieceIndex][squareIndex]) == default) // isPassedPawn - { - var rank = Constants.Rank[squareIndex]; - if (pieceIndex == (int)Piece.p) - { - rank = 7 - rank; - } - packedBonus += Configuration.EngineSettings.PassedPawnBonus[rank].PackedEvaluation; - } - - return packedBonus; - } + //[MethodImpl(MethodImplOptions.AggressiveInlining)] + //private int PawnAdditionalEvaluation(int squareIndex, int pieceIndex) + //{ + // int packedBonus = 0; + + // var doublePawnsCount = (PieceBitBoards[pieceIndex] & Masks.FileMasks[squareIndex]).CountBits(); + // if (doublePawnsCount > 1) + // { + // packedBonus += doublePawnsCount * Configuration.EngineSettings.DoubledPawnPenalty.PackedEvaluation; + // } + + // if ((PieceBitBoards[pieceIndex] & Masks.IsolatedPawnMasks[squareIndex]) == default) // isIsolatedPawn + // { + // packedBonus += Configuration.EngineSettings.IsolatedPawnPenalty.PackedEvaluation; + // } + + // if ((PieceBitBoards[(int)Piece.p - pieceIndex] & Masks.PassedPawns[pieceIndex][squareIndex]) == default) // isPassedPawn + // { + // var rank = Constants.Rank[squareIndex]; + // if (pieceIndex == (int)Piece.p) + // { + // rank = 7 - rank; + // } + // packedBonus += Configuration.EngineSettings.PassedPawnBonus[rank].PackedEvaluation; + // } + + // return packedBonus; + //} /// /// Open and semiopen file bonus From 7f76db8c0aa893152c704ba79aa816327c7763e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20C=C3=A1ceres?= Date: Thu, 16 May 2024 01:10:41 +0200 Subject: [PATCH 2/4] Remove double pawns --- src/Lynx.Cli/appsettings.json | 76 +++++++++++++++++------------------ src/Lynx/Configuration.cs | 20 ++++----- src/Lynx/Model/Position.cs | 62 ++++++++++++++-------------- 3 files changed, 79 insertions(+), 79 deletions(-) diff --git a/src/Lynx.Cli/appsettings.json b/src/Lynx.Cli/appsettings.json index 5a6f9f9b8..3914a319a 100644 --- a/src/Lynx.Cli/appsettings.json +++ b/src/Lynx.Cli/appsettings.json @@ -62,10 +62,10 @@ // "MG": -6, // "EG": -12 //}, - //"IsolatedPawnPenalty": { - // "MG": -17, - // "EG": -13 - //}, + "IsolatedPawnPenalty": { + "MG": -17, + "EG": -13 + }, "OpenFileRookBonus": { "MG": 47, "EG": 10 @@ -102,40 +102,40 @@ "MG": 31, "EG": 80 }, - //"PassedPawnBonus": { - // "Rank0": { - // "MG": 0, - // "EG": 0 - // }, - // "Rank1": { - // "MG": -2, - // "EG": 7 - // }, - // "Rank2": { - // "MG": -15, - // "EG": 13 - // }, - // "Rank3": { - // "MG": -14, - // "EG": 41 - // }, - // "Rank4": { - // "MG": 20, - // "EG": 74 - // }, - // "Rank5": { - // "MG": 60, - // "EG": 150 - // }, - // "Rank6": { - // "MG": 98, - // "EG": 217 - // }, - // "Rank7": { - // "MG": 0, - // "EG": 0 - // } - //} + "PassedPawnBonus": { + "Rank0": { + "MG": 0, + "EG": 0 + }, + "Rank1": { + "MG": -2, + "EG": 7 + }, + "Rank2": { + "MG": -15, + "EG": 13 + }, + "Rank3": { + "MG": -14, + "EG": 41 + }, + "Rank4": { + "MG": 20, + "EG": 74 + }, + "Rank5": { + "MG": 60, + "EG": 150 + }, + "Rank6": { + "MG": 98, + "EG": 217 + }, + "Rank7": { + "MG": 0, + "EG": 0 + } + } // End of evaluation }, diff --git a/src/Lynx/Configuration.cs b/src/Lynx/Configuration.cs index b8c9d08d7..ad6ed7bd7 100644 --- a/src/Lynx/Configuration.cs +++ b/src/Lynx/Configuration.cs @@ -205,7 +205,7 @@ public sealed class EngineSettings //public TaperedEvaluationTerm DoubledPawnPenalty { get; set; } = new(-6, -12); - //public TaperedEvaluationTerm IsolatedPawnPenalty { get; set; } = new(-17, -13); + public TaperedEvaluationTerm IsolatedPawnPenalty { get; set; } = new(-17, -13); public TaperedEvaluationTerm OpenFileRookBonus { get; set; } = new(47, 10); @@ -225,15 +225,15 @@ public sealed class EngineSettings public TaperedEvaluationTerm BishopPairBonus { get; set; } = new(31, 80); - //public TaperedEvaluationTermByRank PassedPawnBonus { get; set; } = new( - // new(0, 0), - // new(-2, 7), - // new(-15, 13), - // new(-14, 41), - // new(20, 74), - // new(60, 150), - // new(98, 217), - // new(0, 0)); + public TaperedEvaluationTermByRank PassedPawnBonus { get; set; } = new( + new(0, 0), + new(-2, 7), + new(-15, 13), + new(-14, 41), + new(20, 74), + new(60, 150), + new(98, 217), + new(0, 0)); #endregion } diff --git a/src/Lynx/Model/Position.cs b/src/Lynx/Model/Position.cs index 288dbb215..d5a1087b1 100644 --- a/src/Lynx/Model/Position.cs +++ b/src/Lynx/Model/Position.cs @@ -848,7 +848,7 @@ internal int AdditionalPieceEvaluation(int pieceSquareIndex, int pieceIndex) { return pieceIndex switch { - //(int)Piece.P or (int)Piece.p => PawnAdditionalEvaluation(pieceSquareIndex, pieceIndex), + (int)Piece.P or (int)Piece.p => PawnAdditionalEvaluation(pieceSquareIndex, pieceIndex), (int)Piece.R or (int)Piece.r => RookAdditionalEvaluation(pieceSquareIndex, pieceIndex), (int)Piece.B or (int)Piece.b => BishopAdditionalEvaluation(pieceSquareIndex, pieceIndex), (int)Piece.Q or (int)Piece.q => QueenAdditionalEvaluation(pieceSquareIndex), @@ -859,37 +859,37 @@ internal int AdditionalPieceEvaluation(int pieceSquareIndex, int pieceIndex) /// /// Doubled pawns penalty, isolated pawns penalty, passed pawns bonus /// - /// - /// + /// + /// < param name="pieceIndex"> /// - //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //private int PawnAdditionalEvaluation(int squareIndex, int pieceIndex) - //{ - // int packedBonus = 0; - - // var doublePawnsCount = (PieceBitBoards[pieceIndex] & Masks.FileMasks[squareIndex]).CountBits(); - // if (doublePawnsCount > 1) - // { - // packedBonus += doublePawnsCount * Configuration.EngineSettings.DoubledPawnPenalty.PackedEvaluation; - // } - - // if ((PieceBitBoards[pieceIndex] & Masks.IsolatedPawnMasks[squareIndex]) == default) // isIsolatedPawn - // { - // packedBonus += Configuration.EngineSettings.IsolatedPawnPenalty.PackedEvaluation; - // } - - // if ((PieceBitBoards[(int)Piece.p - pieceIndex] & Masks.PassedPawns[pieceIndex][squareIndex]) == default) // isPassedPawn - // { - // var rank = Constants.Rank[squareIndex]; - // if (pieceIndex == (int)Piece.p) - // { - // rank = 7 - rank; - // } - // packedBonus += Configuration.EngineSettings.PassedPawnBonus[rank].PackedEvaluation; - // } - - // return packedBonus; - //} + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private int PawnAdditionalEvaluation(int squareIndex, int pieceIndex) + { + int packedBonus = 0; + + //var doublePawnsCount = (PieceBitBoards[pieceIndex] & Masks.FileMasks[squareIndex]).CountBits(); + //if (doublePawnsCount > 1) + //{ + // packedBonus += doublePawnsCount * Configuration.EngineSettings.DoubledPawnPenalty.PackedEvaluation; + //} + + if ((PieceBitBoards[pieceIndex] & Masks.IsolatedPawnMasks[squareIndex]) == default) // isIsolatedPawn + { + packedBonus += Configuration.EngineSettings.IsolatedPawnPenalty.PackedEvaluation; + } + + if ((PieceBitBoards[(int)Piece.p - pieceIndex] & Masks.PassedPawns[pieceIndex][squareIndex]) == default) // isPassedPawn + { + var rank = Constants.Rank[squareIndex]; + if (pieceIndex == (int)Piece.p) + { + rank = 7 - rank; + } + packedBonus += Configuration.EngineSettings.PassedPawnBonus[rank].PackedEvaluation; + } + + return packedBonus; + } /// /// Open and semiopen file bonus From de329a089f3667c9e27665dcb82fb0fd14d92405 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20C=C3=A1ceres?= Date: Thu, 16 May 2024 03:05:20 +0200 Subject: [PATCH 3/4] Add tuned values --- src/Lynx.Cli/appsettings.json | 56 +++++----- src/Lynx/EvaluationConstants.cs | 192 ++++++++++++++++---------------- 2 files changed, 122 insertions(+), 126 deletions(-) diff --git a/src/Lynx.Cli/appsettings.json b/src/Lynx.Cli/appsettings.json index 3914a319a..4f4eb22fb 100644 --- a/src/Lynx.Cli/appsettings.json +++ b/src/Lynx.Cli/appsettings.json @@ -58,21 +58,17 @@ "FP_Margin": 250, // Evaluation - //"DoubledPawnPenalty": { - // "MG": -6, - // "EG": -12 - //}, "IsolatedPawnPenalty": { - "MG": -17, - "EG": -13 + "MG": -21, + "EG": -17 }, "OpenFileRookBonus": { - "MG": 47, - "EG": 10 + "MG": 46, + "EG": 9 }, "SemiOpenFileRookBonus": { - "MG": 18, - "EG": 17 + "MG": 15, + "EG": 15 }, "BishopMobilityBonus": { "MG": 10, @@ -84,22 +80,22 @@ }, "QueenMobilityBonus": { "MG": 4, - "EG": 7 + "EG": 8 }, "SemiOpenFileKingPenalty": { - "MG": -36, - "EG": 24 + "MG": -41, + "EG": 21 }, "OpenFileKingPenalty": { - "MG": -105, - "EG": 8 + "MG": -110, + "EG": 10 }, "KingShieldBonus": { - "MG": 16, - "EG": -6 + "MG": 17, + "EG": -5 }, "BishopPairBonus": { - "MG": 31, + "MG": 33, "EG": 80 }, "PassedPawnBonus": { @@ -108,28 +104,28 @@ "EG": 0 }, "Rank1": { - "MG": -2, - "EG": 7 + "MG": 4, + "EG": 12 }, "Rank2": { - "MG": -15, - "EG": 13 + "MG": -11, + "EG": 19 }, "Rank3": { - "MG": -14, - "EG": 41 + "MG": -11, + "EG": 47 }, "Rank4": { - "MG": 20, - "EG": 74 + "MG": 21, + "EG": 80 }, "Rank5": { - "MG": 60, - "EG": 150 + "MG": 62, + "EG": 158 }, "Rank6": { - "MG": 98, - "EG": 217 + "MG": 104, + "EG": 243 }, "Rank7": { "MG": 0, diff --git a/src/Lynx/EvaluationConstants.cs b/src/Lynx/EvaluationConstants.cs index 14ac2ea3f..4c48622c5 100644 --- a/src/Lynx/EvaluationConstants.cs +++ b/src/Lynx/EvaluationConstants.cs @@ -26,158 +26,158 @@ public static class EvaluationConstants internal static readonly short[] MiddleGamePieceValues = [ - +105, +392, +363, +488, +1116, 0, - -105, -392, -363, -488, -1116, 0 + +105, +399, +365, +493, +1129, 0, + -105, -399, -365, -493, -1129, 0 ]; internal static readonly short[] EndGamePieceValues = [ - +135, +443, +399, +774, +1424, 0, - -135, -443, -399, -774, -1424, 0 + +128, +440, +392, +769, +1408, 0, + -128, -440, -392, -769, -1408, 0 ]; internal static readonly short[] MiddleGamePawnTable = [ 0, 0, 0, 0, 0, 0, 0, 0, - -26, -22, -15, -10, -2, 29, 31, -15, - -26, -24, -6, 9, 18, 28, 26, 7, - -25, -15, 3, 17, 25, 31, 4, -5, - -25, -11, 1, 19, 27, 28, 3, -6, - -24, -17, -4, 3, 14, 25, 19, 1, - -26, -20, -19, -14, -5, 23, 21, -22, + -26, -25, -16, -9, -3, 29, 29, -11, + -27, -27, -7, 10, 17, 26, 23, 11, + -25, -17, 1, 18, 26, 29, 1, -1, + -25, -13, 0, 20, 27, 27, 1, -2, + -23, -21, -5, 3, 13, 23, 16, 5, + -26, -23, -20, -13, -6, 23, 19, -19, 0, 0, 0, 0, 0, 0, 0, 0, ]; internal static readonly short[] EndGamePawnTable = [ 0, 0, 0, 0, 0, 0, 0, 0, - 11, 11, 6, -12, 6, 2, -5, -10, - 9, 10, 0, -13, -7, -6, -5, -11, - 24, 17, -1, -20, -16, -12, 6, -2, - 22, 17, -2, -16, -14, -9, 4, -4, - 10, 8, -3, -11, -3, -4, -4, -11, - 13, 11, 9, -12, 15, 5, -2, -6, + 15, 10, 5, -12, 7, 1, -7, -7, + 13, 9, -1, -12, -6, -7, -7, -8, + 27, 17, 0, -19, -15, -13, 4, 0, + 25, 16, -1, -15, -14, -10, 2, -2, + 14, 7, -3, -10, -3, -5, -6, -8, + 17, 11, 9, -11, 16, 4, -4, -4, 0, 0, 0, 0, 0, 0, 0, 0, ]; internal static readonly short[] MiddleGameKnightTable = [ - -145, -22, -50, -31, -12, -20, -10, -98, - -45, -28, -3, 16, 17, 24, -14, -17, - -28, 2, 20, 57, 60, 40, 34, -4, - -10, 25, 44, 59, 59, 59, 45, 18, - -7, 25, 46, 47, 57, 58, 45, 17, - -26, 4, 20, 49, 58, 34, 28, -5, - -46, -19, 0, 15, 17, 19, -13, -18, - -163, -25, -48, -20, -9, -11, -18, -88, + -147, -24, -51, -30, -14, -21, -11, -98, + -45, -28, -5, 15, 16, 25, -12, -17, + -29, 0, 18, 56, 60, 39, 33, -4, + -11, 25, 42, 59, 58, 58, 44, 17, + -8, 23, 44, 46, 56, 56, 44, 16, + -27, 2, 18, 48, 57, 32, 26, -5, + -46, -18, 0, 14, 15, 19, -12, -18, + -164, -26, -50, -20, -9, -11, -19, -88, ]; internal static readonly short[] EndGameKnightTable = [ - -67, -59, -12, -11, -10, -27, -53, -87, - -18, 1, 13, 8, 8, 5, -10, -20, - -14, 15, 35, 35, 32, 17, 9, -14, - 7, 19, 47, 48, 52, 46, 24, -7, - 4, 24, 46, 51, 52, 42, 28, 0, - -16, 18, 26, 40, 32, 18, 5, -10, - -25, 4, 5, 11, 4, 0, -11, -24, - -71, -57, -7, -14, -11, -26, -50, -85, + -62, -59, -12, -12, -10, -27, -53, -82, + -17, 0, 13, 8, 8, 5, -13, -22, + -13, 14, 35, 34, 32, 16, 8, -13, + 5, 18, 47, 48, 52, 46, 23, -5, + 4, 23, 45, 51, 52, 41, 27, -1, + -15, 17, 26, 39, 31, 18, 6, -9, + -25, 2, 5, 11, 4, 0, -12, -26, + -66, -58, -8, -16, -12, -26, -51, -82, ]; internal static readonly short[] MiddleGameBishopTable = [ - -18, 14, -3, -15, -12, -16, -22, 0, - 7, 2, 7, -18, 2, -1, 27, -12, - -6, 5, -4, 3, -8, 13, 4, 27, - -8, -6, -5, 23, 20, -17, 2, -2, - -15, -1, -13, 18, 6, -13, -6, 5, - 5, 5, 7, -4, 6, 6, 7, 22, - 9, 13, 11, -6, -3, 3, 19, -3, - 7, 18, 11, -30, -14, -21, 1, -15, + -17, 15, -2, -14, -10, -16, -21, 1, + 6, 2, 7, -17, 2, 3, 28, -7, + -6, 5, -4, 2, -8, 14, 5, 28, + -6, -6, -6, 24, 20, -17, 2, -1, + -13, -1, -13, 20, 6, -14, -6, 5, + 5, 5, 7, -5, 6, 8, 7, 24, + 9, 13, 11, -5, -2, 5, 20, -1, + 8, 20, 12, -29, -11, -20, 2, -14, ]; internal static readonly short[] EndGameBishopTable = [ - -11, 13, -14, 3, -2, 4, -2, -27, - -3, -7, -3, 4, 2, -9, -3, -15, - 12, 13, 7, 2, 11, 3, 6, 9, - 12, 7, 6, -3, -6, 6, 5, 6, - 8, 10, 6, 0, -8, 6, 7, 7, - 10, 4, 0, 0, 5, -1, 4, 6, - -13, -10, -14, 2, 1, -3, -3, -10, - -7, -14, -9, 7, 7, 6, -4, -13, + -8, 15, -12, 4, -1, 6, -1, -25, + 0, -7, -3, 5, 2, -10, -3, -15, + 14, 13, 6, 1, 10, 3, 6, 9, + 13, 7, 6, -4, -7, 6, 5, 8, + 8, 10, 5, -1, -10, 6, 7, 10, + 10, 3, -1, -1, 5, -2, 3, 7, + -10, -8, -14, 3, 1, -3, -2, -7, + -6, -13, -8, 8, 7, 7, -3, -11, ]; internal static readonly short[] MiddleGameRookTable = [ - -4, -10, -4, 2, 14, 4, 7, -2, - -26, -17, -13, -12, 0, 3, 17, -3, - -29, -20, -22, -12, 3, 10, 50, 27, - -24, -21, -17, -8, -4, 9, 38, 19, - -18, -15, -13, -5, -6, 8, 29, 14, - -22, -16, -18, -4, 2, 19, 48, 27, - -24, -26, -9, -6, 2, 2, 23, 2, - -2, -4, 0, 12, 22, 8, 15, 9, + -5, -10, -5, 2, 14, 3, 6, -4, + -26, -17, -13, -11, 1, 5, 19, -2, + -28, -19, -23, -12, 5, 11, 50, 30, + -25, -20, -18, -6, -4, 10, 38, 21, + -18, -16, -12, -4, -6, 8, 29, 14, + -22, -15, -19, -4, 2, 19, 48, 27, + -24, -26, -10, -6, 3, 3, 26, 3, + -4, -4, -1, 11, 21, 7, 14, 7, ]; internal static readonly short[] EndGameRookTable = [ - 4, 2, 6, -3, -11, 3, 0, -4, - 16, 19, 18, 8, -1, -2, -4, 3, - 14, 11, 12, 5, -7, -9, -20, -16, - 15, 11, 13, 6, 0, -1, -13, -13, - 15, 11, 13, 4, 1, -6, -10, -9, - 13, 14, 5, -3, -10, -13, -20, -11, - 19, 22, 14, 4, -4, -2, -4, 2, - 0, -3, 1, -9, -18, -5, -8, -12, + 5, 3, 7, -1, -10, 5, 1, -3, + 16, 19, 18, 8, -2, -2, -3, 1, + 12, 10, 11, 5, -8, -10, -21, -18, + 14, 10, 12, 4, 0, -1, -14, -13, + 14, 10, 12, 3, 1, -6, -12, -10, + 13, 12, 4, -3, -10, -14, -20, -12, + 19, 21, 14, 4, -4, -3, -6, 2, + 0, -2, 3, -8, -17, -3, -7, -11, ]; internal static readonly short[] MiddleGameQueenTable = [ - -12, -10, -5, 9, 3, -30, 9, 2, - -2, -10, 7, -3, 2, 6, 22, 49, - -9, -6, -9, -10, -12, 7, 34, 55, - -12, -19, -18, -9, -9, -5, 11, 24, - -12, -16, -19, -18, -8, -5, 9, 22, - -6, -4, -15, -12, -5, 4, 20, 37, - -16, -20, 3, 10, 7, 3, 6, 36, - -10, -10, 4, 11, 6, -36, -13, 25, + -11, -9, -5, 10, 4, -30, 8, -5, + -2, -11, 8, -1, 4, 7, 24, 62, + -7, -6, -9, -10, -12, 7, 33, 58, + -13, -19, -19, -10, -11, -4, 11, 24, + -11, -16, -20, -20, -11, -5, 9, 22, + -8, -3, -14, -11, -5, 4, 20, 38, + -15, -21, 4, 11, 9, 5, 8, 46, + -9, -9, 7, 12, 8, -35, -14, 25, ]; internal static readonly short[] EndGameQueenTable = [ - -24, -20, -11, -11, -16, -10, -34, 9, - -16, -9, -25, 0, -2, -16, -45, -7, - -15, -4, 6, 2, 23, 20, -8, 4, - -9, 9, 9, 14, 27, 38, 44, 31, - -2, 5, 16, 25, 22, 34, 25, 40, - -15, -11, 14, 12, 14, 20, 19, 15, - -10, -3, -21, -18, -12, -11, -31, 3, - -15, -16, -17, -6, -9, 16, 14, -3, + -24, -22, -11, -11, -16, -6, -33, 14, + -15, -10, -28, -2, -3, -15, -41, -7, + -17, -6, 5, 0, 22, 21, -1, 3, + -10, 7, 7, 12, 27, 37, 44, 36, + -4, 3, 15, 24, 24, 33, 28, 44, + -11, -14, 11, 6, 13, 20, 20, 20, + -10, -2, -22, -20, -15, -15, -26, 4, + -15, -16, -20, -5, -11, 16, 14, 0, ]; internal static readonly short[] MiddleGameKingTable = [ - 25, 50, 26, -74, 9, -61, 39, 48, - -11, -16, -34, -72, -84, -58, -10, 19, - -82, -67, -105, -107, -116, -124, -83, -96, - -105, -95, -115, -150, -145, -138, -137, -162, - -71, -69, -103, -130, -146, -123, -141, -158, - -79, -43, -96, -104, -93, -104, -75, -87, - 72, -9, -37, -63, -68, -47, 4, 26, - 38, 75, 38, -59, 20, -51, 52, 62, + 27, 51, 26, -74, 9, -61, 38, 48, + -6, -16, -32, -72, -85, -59, -11, 18, + -74, -63, -104, -106, -115, -128, -85, -93, + -95, -91, -110, -144, -142, -137, -133, -168, + -70, -65, -99, -122, -139, -122, -139, -158, + -79, -35, -91, -101, -92, -104, -75, -87, + 76, -8, -35, -63, -67, -46, 4, 27, + 41, 77, 39, -56, 21, -50, 52, 64, ]; internal static readonly short[] EndGameKingTable = [ - -72, -46, -20, 5, -33, -2, -38, -89, - -13, 18, 27, 39, 46, 33, 13, -23, - 10, 42, 59, 68, 72, 64, 44, 22, - 15, 53, 75, 90, 88, 80, 68, 39, - 5, 45, 72, 86, 91, 78, 70, 39, - 11, 39, 57, 68, 66, 59, 43, 17, - -38, 13, 28, 37, 39, 29, 8, -26, - -82, -56, -26, -2, -29, -6, -42, -94, + -70, -45, -19, 7, -31, -2, -36, -88, + -15, 18, 27, 39, 46, 34, 13, -22, + 8, 40, 58, 68, 71, 64, 43, 21, + 11, 51, 73, 87, 86, 79, 65, 39, + 3, 42, 71, 83, 89, 77, 69, 38, + 10, 35, 56, 67, 65, 58, 41, 18, + -38, 13, 28, 37, 40, 29, 8, -25, + -82, -57, -26, -1, -27, -5, -41, -95, ]; #pragma warning restore IDE0055 From dfecfc1ed0f27be4d97e34e45dc8e71e75bfd67c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20C=C3=A1ceres?= Date: Thu, 16 May 2024 12:02:56 +0200 Subject: [PATCH 4/4] Cleanup --- src/Lynx/Configuration.cs | 30 +++++------ src/Lynx/Model/Position.cs | 6 --- tests/Lynx.Test/Model/PositionTest.cs | 78 +++++++++++++-------------- 3 files changed, 53 insertions(+), 61 deletions(-) diff --git a/src/Lynx/Configuration.cs b/src/Lynx/Configuration.cs index ad6ed7bd7..87156d6e9 100644 --- a/src/Lynx/Configuration.cs +++ b/src/Lynx/Configuration.cs @@ -203,36 +203,34 @@ public sealed class EngineSettings #region Evaluation - //public TaperedEvaluationTerm DoubledPawnPenalty { get; set; } = new(-6, -12); + public TaperedEvaluationTerm IsolatedPawnPenalty { get; set; } = new(-21, -17); - public TaperedEvaluationTerm IsolatedPawnPenalty { get; set; } = new(-17, -13); + public TaperedEvaluationTerm OpenFileRookBonus { get; set; } = new(46, 9); - public TaperedEvaluationTerm OpenFileRookBonus { get; set; } = new(47, 10); - - public TaperedEvaluationTerm SemiOpenFileRookBonus { get; set; } = new(18, 17); + public TaperedEvaluationTerm SemiOpenFileRookBonus { get; set; } = new(15, 15); public TaperedEvaluationTerm BishopMobilityBonus { get; set; } = new(10, 9); public TaperedEvaluationTerm RookMobilityBonus { get; set; } = new(5, 5); - public TaperedEvaluationTerm QueenMobilityBonus { get; set; } = new(4, 7); + public TaperedEvaluationTerm QueenMobilityBonus { get; set; } = new(4, 8); - public TaperedEvaluationTerm SemiOpenFileKingPenalty { get; set; } = new(-36, 24); + public TaperedEvaluationTerm SemiOpenFileKingPenalty { get; set; } = new(-41, 21); - public TaperedEvaluationTerm OpenFileKingPenalty { get; set; } = new(-105, 8); + public TaperedEvaluationTerm OpenFileKingPenalty { get; set; } = new(-110, 10); - public TaperedEvaluationTerm KingShieldBonus { get; set; } = new(16, -6); + public TaperedEvaluationTerm KingShieldBonus { get; set; } = new(17, -5); - public TaperedEvaluationTerm BishopPairBonus { get; set; } = new(31, 80); + public TaperedEvaluationTerm BishopPairBonus { get; set; } = new(33, 80); public TaperedEvaluationTermByRank PassedPawnBonus { get; set; } = new( new(0, 0), - new(-2, 7), - new(-15, 13), - new(-14, 41), - new(20, 74), - new(60, 150), - new(98, 217), + new(4, 12), + new(-11, 19), + new(-11, 47), + new(21, 80), + new(62, 158), + new(104, 243), new(0, 0)); #endregion diff --git a/src/Lynx/Model/Position.cs b/src/Lynx/Model/Position.cs index d5a1087b1..bf94e26a1 100644 --- a/src/Lynx/Model/Position.cs +++ b/src/Lynx/Model/Position.cs @@ -867,12 +867,6 @@ private int PawnAdditionalEvaluation(int squareIndex, int pieceIndex) { int packedBonus = 0; - //var doublePawnsCount = (PieceBitBoards[pieceIndex] & Masks.FileMasks[squareIndex]).CountBits(); - //if (doublePawnsCount > 1) - //{ - // packedBonus += doublePawnsCount * Configuration.EngineSettings.DoubledPawnPenalty.PackedEvaluation; - //} - if ((PieceBitBoards[pieceIndex] & Masks.IsolatedPawnMasks[squareIndex]) == default) // isIsolatedPawn { packedBonus += Configuration.EngineSettings.IsolatedPawnPenalty.PackedEvaluation; diff --git a/tests/Lynx.Test/Model/PositionTest.cs b/tests/Lynx.Test/Model/PositionTest.cs index e142fccb3..ce751284f 100644 --- a/tests/Lynx.Test/Model/PositionTest.cs +++ b/tests/Lynx.Test/Model/PositionTest.cs @@ -230,25 +230,25 @@ public void StaticEvaluation_IsolatedPawnPenalty(string fen) /// a b c d e f g h /// /// - [TestCase("4k3/ppp5/8/8/8/P7/PP6/4K3 w - - 0 1")] - /// - /// Previous one mirrored - /// - /// - [TestCase("3k4/6pp/7p/8/8/8/5PPP/3K4 b - - 0 1")] - public void StaticEvaluation_DoublePawnPenalty(string fen) - { - Position position = new Position(fen); - int evaluation = AdditionalPieceEvaluation(position, Piece.P) - - AdditionalPieceEvaluation(position, Piece.p); - - if (position.Side == Side.Black) - { - evaluation = -evaluation; - } - - Assert.AreEqual(4 * Configuration.EngineSettings.DoubledPawnPenalty.MG, evaluation); - } + //[TestCase("4k3/ppp5/8/8/8/P7/PP6/4K3 w - - 0 1")] + ///// + ///// Previous one mirrored + ///// + ///// + //[TestCase("3k4/6pp/7p/8/8/8/5PPP/3K4 b - - 0 1")] + //public void StaticEvaluation_DoublePawnPenalty(string fen) + //{ + // Position position = new Position(fen); + // int evaluation = AdditionalPieceEvaluation(position, Piece.P) + // - AdditionalPieceEvaluation(position, Piece.p); + + // if (position.Side == Side.Black) + // { + // evaluation = -evaluation; + // } + + // Assert.AreEqual(4 * Configuration.EngineSettings.DoubledPawnPenalty.MG, evaluation); + //} /// /// Illegal position, but avoids any positional bonuses @@ -263,25 +263,25 @@ public void StaticEvaluation_DoublePawnPenalty(string fen) /// a b c d e f g h /// /// - [TestCase("7k/ppp2ppp/8/8/8/P7/PP4PP/P6K w - - 0 1")] - /// - /// Previous one mirrored - /// - /// - [TestCase("k6p/pp4pp/7p/8/8/8/PPP2PPP/K7 b - - 0 1")] - public void StaticEvaluation_TriplePawnPenalty(string fen) - { - Position position = new Position(fen); - int evaluation = AdditionalPieceEvaluation(position, Piece.P) - - AdditionalPieceEvaluation(position, Piece.p); - - if (position.Side == Side.Black) - { - evaluation = -evaluation; - } - - Assert.AreEqual(9 * Configuration.EngineSettings.DoubledPawnPenalty.MG, evaluation); - } + //[TestCase("7k/ppp2ppp/8/8/8/P7/PP4PP/P6K w - - 0 1")] + ///// + ///// Previous one mirrored + ///// + ///// + //[TestCase("k6p/pp4pp/7p/8/8/8/PPP2PPP/K7 b - - 0 1")] + //public void StaticEvaluation_TriplePawnPenalty(string fen) + //{ + // Position position = new Position(fen); + // int evaluation = AdditionalPieceEvaluation(position, Piece.P) + // - AdditionalPieceEvaluation(position, Piece.p); + + // if (position.Side == Side.Black) + // { + // evaluation = -evaluation; + // } + + // Assert.AreEqual(9 * Configuration.EngineSettings.DoubledPawnPenalty.MG, evaluation); + //} /// /// 8 . . . . . . k . @@ -422,7 +422,7 @@ public void StaticEvaluation_PassedPawnBonus(string fen, BoardSquare square) } Assert.AreEqual( - (-4 * Configuration.EngineSettings.DoubledPawnPenalty.MG) + //(-4 * Configuration.EngineSettings.DoubledPawnPenalty.MG) + Configuration.EngineSettings.IsolatedPawnPenalty.MG + Configuration.EngineSettings.PassedPawnBonus[rank].MG,