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

⚖️ Pawn phalanx #1009

Merged
merged 6 commits into from
Sep 15, 2024
Merged
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
33 changes: 30 additions & 3 deletions src/Lynx/Model/Position.cs
Original file line number Diff line number Diff line change
Expand Up @@ -532,8 +532,11 @@ public bool WasProduceByAValidMove()
int packedScore = 0;
int gamePhase = 0;

BitBoard whitePawnAttacks = PieceBitBoards[(int)Piece.P].ShiftUpRight() | PieceBitBoards[(int)Piece.P].ShiftUpLeft();
BitBoard blackPawnAttacks = PieceBitBoards[(int)Piece.p].ShiftDownRight() | PieceBitBoards[(int)Piece.p].ShiftDownLeft();
var whitePawns = PieceBitBoards[(int)Piece.P];
var blackPawns = PieceBitBoards[(int)Piece.p];

BitBoard whitePawnAttacks = whitePawns.ShiftUpRight() | whitePawns.ShiftUpLeft();
BitBoard blackPawnAttacks = blackPawns.ShiftDownRight() | blackPawns.ShiftDownLeft();

var whiteKing = PieceBitBoards[(int)Piece.K].GetLS1BIndex();
var blackKing = PieceBitBoards[(int)Piece.k].GetLS1BIndex();
Expand Down Expand Up @@ -590,6 +593,30 @@ public bool WasProduceByAValidMove()
packedScore -= BishopPairBonus;
}

// Pawn phalanx
var whitePawnsRight = whitePawns.ShiftRight();
var whitePhalanx = whitePawns & whitePawnsRight;
while (whitePhalanx != 0)
{
var square = whitePhalanx.GetLS1BIndex();
whitePhalanx.ResetLS1B();

var rank = Constants.Rank[square];
packedScore += PawnPhalanxBonus[rank];
}

var blackPawnsRight = blackPawns.ShiftRight();
var blackPhalanx = blackPawns & blackPawnsRight;
while (blackPhalanx != 0)
{
var square = blackPhalanx.GetLS1BIndex();
blackPhalanx.ResetLS1B();

var rank = 7 - Constants.Rank[square];
packedScore -= PawnPhalanxBonus[rank];
}


// Pieces protected by pawns bonus
packedScore += PieceProtectedByPawnBonus
* ((whitePawnAttacks & OccupancyBitBoards[(int)Side.White] /*& (~PieceBitBoards[(int)Piece.P])*/).CountBits()
Expand All @@ -613,7 +640,7 @@ public bool WasProduceByAValidMove()
gamePhase = maxPhase;
}

int totalPawnsCount = PieceBitBoards[(int)Piece.P].CountBits() + PieceBitBoards[(int)Piece.p].CountBits();
int totalPawnsCount = whitePawns.CountBits() + blackPawns.CountBits();

// Pawnless endgames with few pieces
if (gamePhase <= 3 && totalPawnsCount == 0)
Expand Down
Loading
Loading