bugfix: double pawn pushes were identified as quiet moves + fixed castling rights change on rook capturing
This commit is contained in:
1 parent
41b54eb0c3
commit
4226b21043
3 files changed
+37
-11
No files matched your search
+20
-6
@@ -291,10 +291,25 @@ void Board::RemovePiece(int piece, int square, bool color) {
|
||||
occupied.PopBit(square);
|
||||
}
|
||||
|
||||
// Updates castling rights on capturing (only if needed)
|
||||
static void UpdateCastlingRights(Board &board, int targetPiece, int targetSquare, int attackerColor) {
|
||||
if (targetPiece == Rook) {
|
||||
int queenSideRook = attackerColor ? a1 : a8;
|
||||
int kingSideRook = attackerColor ? a8 : h8;
|
||||
|
||||
if (targetSquare == queenSideRook) {
|
||||
board.castlingRights[!attackerColor * 2 + 1] = false;
|
||||
} else if (targetSquare == kingSideRook) {
|
||||
board.castlingRights[!attackerColor * 2] = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Board::Promote(int square, int pieceType, int color, bool isCapture) {
|
||||
if (isCapture) {
|
||||
int targetType = GetPieceType(square);
|
||||
RemovePiece(targetType, square, !color);
|
||||
UpdateCastlingRights(*this, targetType, square, color);
|
||||
}
|
||||
|
||||
SetPiece(pieceType, square, color);
|
||||
@@ -307,6 +322,8 @@ void Board::MakeMove(Move move) {
|
||||
int targetPiece = GetPieceType(move.MoveTo());
|
||||
int direction = attackerColor ? south : north;
|
||||
|
||||
int newEpTarget = -1;
|
||||
|
||||
// Removing attacker piece from old position
|
||||
RemovePiece(attackerPiece, move.MoveFrom(), attackerColor);
|
||||
|
||||
@@ -317,17 +334,13 @@ void Board::MakeMove(Move move) {
|
||||
break;
|
||||
case doublePawnPush:
|
||||
SetPiece(attackerPiece, move.MoveTo(), attackerColor);
|
||||
enPassantTarget = move.MoveFrom() + direction;
|
||||
newEpTarget = move.MoveFrom() + direction;
|
||||
break;
|
||||
case capture:
|
||||
RemovePiece(targetPiece, move.MoveTo(), !attackerColor);
|
||||
SetPiece(attackerPiece, move.MoveTo(), attackerColor);
|
||||
|
||||
if (targetPiece == Rook) {
|
||||
int queenSide = move.MoveTo() % 8 == 0;
|
||||
|
||||
castlingRights[!attackerColor * 2 + queenSide] = false;
|
||||
}
|
||||
UpdateCastlingRights(*this, targetPiece, move.MoveTo(), attackerColor);
|
||||
|
||||
break;
|
||||
case epCapture:
|
||||
@@ -403,6 +416,7 @@ void Board::MakeMove(Move move) {
|
||||
halfMoves++;
|
||||
if (halfMoves & 2 == 0) fullMoves++;
|
||||
sideToMove = !attackerColor;
|
||||
enPassantTarget = newEpTarget;
|
||||
|
||||
GenAttackMaps(*this);
|
||||
}
|
||||
+2
-2
@@ -9,8 +9,8 @@ int main() {
|
||||
initSliderAttacks();
|
||||
|
||||
Board board;
|
||||
board.SetByFen("rnbq1k1r/pp1Pbppp/2p5/8/2B5/8/PPP1NnPP/RNBQK2R w KQ - 1 8");
|
||||
Perft(board, 3);
|
||||
//board.SetByFen("rnbq1k1r/pp1Pbppp/2p5/8/2B5/8/PPP1NnPP/RNBQK2R w KQ - 1 8");
|
||||
Perft(board, 5);
|
||||
|
||||
return 0;
|
||||
}
|
||||
+15
-3
@@ -498,7 +498,11 @@ static void GenPawnMoves(Board &board, bool color) {
|
||||
while (pushes.GetBoard()) {
|
||||
int pushSquare = pushes.getLS1BIndex();
|
||||
|
||||
board.AddMove(Move(square, pushSquare, quiet));
|
||||
if (abs(square - pushSquare) == 16) {
|
||||
board.AddMove(Move(square, pushSquare, doublePawnPush));
|
||||
} else {
|
||||
board.AddMove(Move(square, pushSquare, quiet));
|
||||
}
|
||||
|
||||
pushes.PopBit(pushSquare);
|
||||
}
|
||||
@@ -538,7 +542,11 @@ static void GenPawnMoves(Board &board, bool color) {
|
||||
board.AddMove(Move(square, pushSquare, rookPromotion));
|
||||
board.AddMove(Move(square, pushSquare, queenPromotion));
|
||||
} else {
|
||||
board.AddMove(Move(square, pushSquare, quiet));
|
||||
if (abs(square - pushSquare) == 16) {
|
||||
board.AddMove(Move(square, pushSquare, doublePawnPush));
|
||||
} else {
|
||||
board.AddMove(Move(square, pushSquare, quiet));
|
||||
}
|
||||
}
|
||||
|
||||
pushes.PopBit(pushSquare);
|
||||
@@ -884,7 +892,11 @@ static void GenCheckEvasions(Board &board, bool color) {
|
||||
while (pushes.GetBoard()) {
|
||||
int pushSquare = pushes.getLS1BIndex();
|
||||
|
||||
board.AddMove(Move(square, pushSquare, quiet));
|
||||
if (type == Pawn && abs(square - pushSquare) == 16) {
|
||||
board.AddMove(Move(square, pushSquare, doublePawnPush));
|
||||
} else {
|
||||
board.AddMove(Move(square, pushSquare, quiet));
|
||||
}
|
||||
|
||||
pushes.PopBit(pushSquare);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user