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

⚖️ Add opponent king buckets to passed pawns bucketed arrays tuned @10k #1355

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
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
16 changes: 9 additions & 7 deletions src/Lynx/Model/Position.cs
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ public bool WasProduceByAValidMove()
bitboard.ResetLS1B();

gamePhase += GamePhaseByPiece[pieceIndex];
packedScore += AdditionalPieceEvaluation(whiteBucket, pieceSquareIndex, pieceIndex, (int)Side.White, whiteKing, blackKing, blackPawnAttacks);
packedScore += AdditionalPieceEvaluation(whiteBucket, blackBucket, pieceSquareIndex, pieceIndex, (int)Side.White, whiteKing, blackKing, blackPawnAttacks);
}
}

Expand All @@ -603,7 +603,7 @@ public bool WasProduceByAValidMove()
bitboard.ResetLS1B();

gamePhase += GamePhaseByPiece[pieceIndex];
packedScore -= AdditionalPieceEvaluation(blackBucket, pieceSquareIndex, pieceIndex, (int)Side.Black, blackKing, whiteKing, whitePawnAttacks);
packedScore -= AdditionalPieceEvaluation(blackBucket, whiteBucket, pieceSquareIndex, pieceIndex, (int)Side.Black, blackKing, whiteKing, whitePawnAttacks);
}
}
}
Expand All @@ -629,7 +629,7 @@ public bool WasProduceByAValidMove()

gamePhase += GamePhaseByPiece[pieceIndex];

packedScore += AdditionalPieceEvaluation(whiteBucket, pieceSquareIndex, pieceIndex, (int)Side.White, whiteKing, blackKing, blackPawnAttacks);
packedScore += AdditionalPieceEvaluation(whiteBucket, blackBucket, pieceSquareIndex, pieceIndex, (int)Side.White, whiteKing, blackKing, blackPawnAttacks);
}
}

Expand All @@ -652,7 +652,7 @@ public bool WasProduceByAValidMove()

gamePhase += GamePhaseByPiece[pieceIndex];

packedScore -= AdditionalPieceEvaluation(blackBucket, pieceSquareIndex, pieceIndex, (int)Side.Black, blackKing, whiteKing, whitePawnAttacks);
packedScore -= AdditionalPieceEvaluation(blackBucket, whiteBucket, pieceSquareIndex, pieceIndex, (int)Side.Black, blackKing, whiteKing, whitePawnAttacks);
}
}

Expand Down Expand Up @@ -816,11 +816,11 @@ public static int EvaluateFinalPosition(int ply, bool isInCheck)
/// Doesn't include <see cref="Piece.K"/> and <see cref="Piece.k"/> evaluation
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal int AdditionalPieceEvaluation(int bucket, int pieceSquareIndex, int pieceIndex, int pieceSide, int sameSideKingSquare, int oppositeSideKingSquare, BitBoard enemyPawnAttacks)
internal int AdditionalPieceEvaluation(int bucket, int oppositeSideBucket, int pieceSquareIndex, int pieceIndex, int pieceSide, int sameSideKingSquare, int oppositeSideKingSquare, BitBoard enemyPawnAttacks)
{
return pieceIndex switch
{
(int)Piece.P or (int)Piece.p => PawnAdditionalEvaluation(bucket, pieceSquareIndex, pieceIndex, sameSideKingSquare, oppositeSideKingSquare),
(int)Piece.P or (int)Piece.p => PawnAdditionalEvaluation(bucket, oppositeSideBucket, pieceSquareIndex, pieceIndex, sameSideKingSquare, oppositeSideKingSquare),
(int)Piece.R or (int)Piece.r => RookAdditionalEvaluation(pieceSquareIndex, pieceIndex, pieceSide, oppositeSideKingSquare, enemyPawnAttacks),
(int)Piece.B or (int)Piece.b => BishopAdditionalEvaluation(pieceSquareIndex, pieceIndex, pieceSide, oppositeSideKingSquare, enemyPawnAttacks),
(int)Piece.N or (int)Piece.n => KnightAdditionalEvaluation(pieceSquareIndex, pieceSide, oppositeSideKingSquare, enemyPawnAttacks),
Expand All @@ -830,7 +830,7 @@ internal int AdditionalPieceEvaluation(int bucket, int pieceSquareIndex, int pie
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private int PawnAdditionalEvaluation(int bucket, int squareIndex, int pieceIndex, int sameSideKingSquare, int oppositeSideKingSquare)
private int PawnAdditionalEvaluation(int bucket, int oppositeSideBucket, int squareIndex, int pieceIndex, int sameSideKingSquare, int oppositeSideKingSquare)
{
int packedBonus = 0;

Expand All @@ -857,6 +857,7 @@ private int PawnAdditionalEvaluation(int bucket, int squareIndex, int pieceIndex
if ((passedPawnsMask & OccupancyBitBoards[oppositeSide]) == 0)
{
packedBonus += PassedPawnBonusNoEnemiesAheadBonus[bucket][rank];
packedBonus += PassedPawnBonusNoEnemiesAheadEnemyBonus[oppositeSideBucket][rank];
}

// King distance to passed pawn
Expand All @@ -866,6 +867,7 @@ private int PawnAdditionalEvaluation(int bucket, int squareIndex, int pieceIndex
var enemyKingDistance = Constants.ChebyshevDistance[squareIndex][oppositeSideKingSquare];

packedBonus += PassedPawnBonus[bucket][rank]
+ PassedPawnEnemyBonus[oppositeSideBucket][rank]
+ FriendlyKingDistanceToPassedPawnBonus[friendlyKingDistance]
+ EnemyKingDistanceToPassedPawnPenalty[enemyKingDistance];
}
Expand Down
Loading
Loading