diff --git a/src/Lynx/Attacks.cs b/src/Lynx/Attacks.cs index 6c32607eb..9804c47de 100644 --- a/src/Lynx/Attacks.cs +++ b/src/Lynx/Attacks.cs @@ -30,7 +30,15 @@ public static class Attacks /// [2 (B|W), 64 (Squares)] /// public static BitBoard[][] PawnAttacks { get; } + + /// + /// [64] + /// public static BitBoard[] KnightAttacks { get; } + + /// + /// [64] + /// public static BitBoard[] KingAttacks { get; } static Attacks() diff --git a/src/Lynx/Generated/Lynx.Generator/Lynx.Generator.GeneratedPackGenerator/EvaluationParams.g.cs b/src/Lynx/Generated/Lynx.Generator/Lynx.Generator.GeneratedPackGenerator/EvaluationParams.g.cs index d7a53a61b..7f3b9660e 100644 --- a/src/Lynx/Generated/Lynx.Generator/Lynx.Generator.GeneratedPackGenerator/EvaluationParams.g.cs +++ b/src/Lynx/Generated/Lynx.Generator/Lynx.Generator.GeneratedPackGenerator/EvaluationParams.g.cs @@ -47,4 +47,9 @@ static partial class EvaluationParams /// public const int PieceAttackedByPawnPenalty = -2162735; + /// + /// + /// + public const int QueenAttackedByKnightBonus = 131073; + } diff --git a/src/Lynx/Model/Position.cs b/src/Lynx/Model/Position.cs index e52e50f55..77a9006f2 100644 --- a/src/Lynx/Model/Position.cs +++ b/src/Lynx/Model/Position.cs @@ -726,12 +726,19 @@ private int KnightAdditionalEvaluation(int squareIndex, int pieceSide, int oppos var packedBonus = KnightMobilityBonus[attacksCount]; + var knightAttacks = Attacks.KnightAttacks; + // Checks - var enemyKingCheckThreats = Attacks.KnightAttacks[oppositeSideKingSquare]; + var enemyKingCheckThreats = knightAttacks[oppositeSideKingSquare]; var checks = (attacks & enemyKingCheckThreats).CountBits(); - packedBonus += CheckBonus[(int)Piece.N] * checks; + // Attacks to enemy queens + if ((attacks & PieceBitBoards[(int)Piece.q - Utils.PieceOffset(pieceSide)]) != 0) + { + packedBonus += KnightAttacksQueenBonus; + } + return packedBonus; } diff --git a/src/Lynx/TunableEvalParameters.cs b/src/Lynx/TunableEvalParameters.cs index 917dfa039..e76fb59b7 100644 --- a/src/Lynx/TunableEvalParameters.cs +++ b/src/Lynx/TunableEvalParameters.cs @@ -6043,6 +6043,9 @@ public static partial class EvaluationParams [GeneratedPack(-47, -33)] private static readonly int _PieceAttackedByPawnPenalty; + [GeneratedPack(1, 2)] + private static readonly int _KnightAttacksQueenBonus; + #pragma warning restore IDE0051, IDE0052, CS0169 // Remove unread private members public static readonly TaperedEvaluationTermByRank PawnPhalanxBonus =