Skip to content

Commit

Permalink
Add impl for KnightAttacksQueenBonus
Browse files Browse the repository at this point in the history
  • Loading branch information
eduherminio committed Nov 22, 2024
1 parent b285167 commit b921c36
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/Lynx/Attacks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,15 @@ public static class Attacks
/// [2 (B|W), 64 (Squares)]
/// </summary>
public static BitBoard[][] PawnAttacks { get; }

/// <summary>
/// [64]
/// </summary>
public static BitBoard[] KnightAttacks { get; }

/// <summary>
/// [64]
/// </summary>
public static BitBoard[] KingAttacks { get; }

static Attacks()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,9 @@ static partial class EvaluationParams
/// </summary>
public const int PieceAttackedByPawnPenalty = -2162735;

/// <summary>
/// <see cref="Utils.Pack(1, 2)"/>
/// </summary>
public const int QueenAttackedByKnightBonus = 131073;

}
11 changes: 9 additions & 2 deletions src/Lynx/Model/Position.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
3 changes: 3 additions & 0 deletions src/Lynx/TunableEvalParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down

0 comments on commit b921c36

Please sign in to comment.