Skip to content

Commit

Permalink
⚖️ Passed pawns: bonus for not enemy pieces ahead (#1008)
Browse files Browse the repository at this point in the history
Replace miscalculated penalty for blocked passers with a bonus for unblocked passers, defining unblocked as no enemy pieces in the passed pawn mask of the square where the pawn is.
  • Loading branch information
eduherminio authored Sep 15, 2024
1 parent 3b2b48f commit 4928f93
Show file tree
Hide file tree
Showing 3 changed files with 5,351 additions and 5,341 deletions.
11 changes: 5 additions & 6 deletions src/Lynx/Model/Position.cs
Original file line number Diff line number Diff line change
Expand Up @@ -753,21 +753,20 @@ private int PawnAdditionalEvaluation(int bucket, int squareIndex, int pieceIndex
packedBonus += IsolatedPawnPenalty;
}

if ((PieceBitBoards[(int)Piece.p - pieceIndex] & Masks.PassedPawns[pieceIndex][squareIndex]) == default) // isPassedPawn
ulong passedPawnsMask = Masks.PassedPawns[pieceIndex][squareIndex];
if ((PieceBitBoards[(int)Piece.p - pieceIndex] & passedPawnsMask) == default) // isPassedPawn
{
var rank = Constants.Rank[squareIndex];
var blockingSquare = squareIndex + 8;
var oppositeSide = (int)Side.Black;
if (pieceIndex == (int)Piece.p)
{
rank = 7 - rank;
blockingSquare -= 16;
oppositeSide = (int)Side.White;
}
}

if (OccupancyBitBoards[oppositeSide].GetBit(blockingSquare))
if ((passedPawnsMask & OccupancyBitBoards[oppositeSide]) == 0)
{
packedBonus += PassedPawnBlockedPenalty[bucket][rank];
packedBonus += PassedPawnBonusNoEnemiesAheadBonus[bucket][rank];
}

var friendlyKingDistance = Constants.ChebyshevDistance[squareIndex][sameSideKingSquare];
Expand Down
Loading

0 comments on commit 4928f93

Please sign in to comment.