Skip to content

Commit

Permalink
⚖️ 'Bad' bishop penalty (#1022)
Browse files Browse the repository at this point in the history
`BadBishopPenalty` indexed by number of same color pawns
  • Loading branch information
eduherminio authored Sep 17, 2024
1 parent b33f5c9 commit 9aa7aa7
Show file tree
Hide file tree
Showing 3 changed files with 5,162 additions and 5,135 deletions.
20 changes: 17 additions & 3 deletions src/Lynx/Model/Position.cs
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ internal int AdditionalPieceEvaluation(int bucket, int pieceSquareIndex, int pie
{
(int)Piece.P or (int)Piece.p => PawnAdditionalEvaluation(bucket, pieceSquareIndex, pieceIndex, sameSideKingSquare, oppositeSideKingSquare),
(int)Piece.R or (int)Piece.r => RookAdditionalEvaluation(pieceSquareIndex, pieceIndex, pieceSide, enemyPawnAttacks),
(int)Piece.B or (int)Piece.b => BishopAdditionalEvaluation(pieceSquareIndex, pieceSide, enemyPawnAttacks),
(int)Piece.B or (int)Piece.b => BishopAdditionalEvaluation(pieceSquareIndex, pieceIndex, pieceSide, enemyPawnAttacks),
(int)Piece.N or (int)Piece.n => KnightAdditionalEvaluation(pieceSquareIndex, pieceSide, enemyPawnAttacks),
(int)Piece.Q or (int)Piece.q => QueenAdditionalEvaluation(pieceSquareIndex, pieceSide, enemyPawnAttacks),
_ => 0
Expand Down Expand Up @@ -714,15 +714,29 @@ private int KnightAdditionalEvaluation(int squareIndex, int pieceSide, BitBoard
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private int BishopAdditionalEvaluation(int squareIndex, int pieceSide, BitBoard enemyPawnAttacks)
private int BishopAdditionalEvaluation(int squareIndex, int pieceIndex, int pieceSide, BitBoard enemyPawnAttacks)
{
const int pawnToBishopOffset = (int)Piece.B - (int)Piece.P;

// Mobility
var attacksCount =
(Attacks.BishopAttacks(squareIndex, OccupancyBitBoards[(int)Side.Both])
& (~(OccupancyBitBoards[pieceSide] | enemyPawnAttacks)))
.CountBits();

return BishopMobilityBonus[attacksCount];
var packedBonus = BishopMobilityBonus[attacksCount];

// Bad bishop
var sameSidePawns = PieceBitBoards[pieceIndex - pawnToBishopOffset];

var sameColorPawns = sameSidePawns &
(Constants.DarkSquares[squareIndex] == 1
? Constants.DarkSquaresBitBoard
: Constants.LightSquaresBitBoard);

packedBonus += BadBishopPenalty[sameColorPawns.CountBits()];

return packedBonus;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
Expand Down
Loading

0 comments on commit 9aa7aa7

Please sign in to comment.