Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

⚖️ Bonus for knight attacking rooks #1192

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(65, -10)"/>
/// </summary>
public const int KnightAttacksRookBonus = -655295;

}
9 changes: 7 additions & 2 deletions src/Lynx/Model/Position.cs
Original file line number Diff line number Diff line change
Expand Up @@ -726,12 +726,17 @@ 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 rooks
var rookAttacksCount = (attacks & PieceBitBoards[(int)Piece.r - Utils.PieceOffset(pieceSide)]).CountBits();
packedBonus += KnightAttacksRookBonus * rookAttacksCount;

return packedBonus;
}

Expand Down
Loading
Loading