Merge pull request #6 from rektdie/enpassant_fix

Enpassant fix
This commit was merged in pull request #6.
This commit is contained in:
rektdie authored and GitHub committed 2025-03-04 08:39:46 +01:00
commit 3752685273
3 files changed
+13 -6

No files matched your search

+5 -5
View File
@@ -9,7 +9,7 @@ void Board::Init() {
void Board::Reset() { void Board::Reset() {
castlingRights = 0; castlingRights = 0;
enPassantTarget = -1; enPassantTarget = noEPTarget;
halfMoves = 0; halfMoves = 0;
fullMoves = 0; fullMoves = 0;
sideToMove = White; sideToMove = White;
@@ -229,7 +229,7 @@ void Board::PrintBoard() {
} else { } else {
std::cout << "Black\n"; std::cout << "Black\n";
} }
if (enPassantTarget >= 0) { if (enPassantTarget != noEPTarget) {
std::cout << " En Passant square: " << squareCoords[enPassantTarget] << '\n'; std::cout << " En Passant square: " << squareCoords[enPassantTarget] << '\n';
} else { } else {
std::cout << " En Passant square: None" << '\n'; std::cout << " En Passant square: None" << '\n';
@@ -346,7 +346,7 @@ void Board::MakeMove(Move move) {
int targetPiece = GetPieceType(move.MoveTo()); int targetPiece = GetPieceType(move.MoveTo());
int direction = attackerColor ? south : north; int direction = attackerColor ? south : north;
int newEpTarget = -1; int newEpTarget = noEPTarget;
// Removing attacker piece from old position // Removing attacker piece from old position
RemovePiece(attackerPiece, move.MoveFrom(), attackerColor); RemovePiece(attackerPiece, move.MoveFrom(), attackerColor);
@@ -433,11 +433,11 @@ void Board::MakeMove(Move move) {
sideToMove = !attackerColor; sideToMove = !attackerColor;
hashKey ^= zSide; hashKey ^= zSide;
if (enPassantTarget != -1) { if (enPassantTarget != noEPTarget) {
hashKey ^= zEnPassant[enPassantTarget % 8]; hashKey ^= zEnPassant[enPassantTarget % 8];
} }
if (newEpTarget != -1) { if (newEpTarget != noEPTarget) {
hashKey ^= zEnPassant[newEpTarget % 8]; hashKey ^= zEnPassant[newEpTarget % 8];
} }
+2 -1
View File
@@ -5,6 +5,7 @@
#include "move.h" #include "move.h"
constexpr int nullPieceType = 100; constexpr int nullPieceType = 100;
constexpr int noEPTarget = -1;
class Board { class Board {
public: public:
@@ -26,7 +27,7 @@ public:
int fullMoves = 0; int fullMoves = 0;
uint8_t castlingRights = 0; uint8_t castlingRights = 0;
int enPassantTarget = -1; int enPassantTarget = noEPTarget;
U64 hashKey = 0ULL; U64 hashKey = 0ULL;
+6
View File
@@ -481,11 +481,13 @@ static void GenPawnMoves(Board &board, bool color) {
captures &= pinningRay; captures &= pinningRay;
// Checking for en passant // Checking for en passant
if (board.enPassantTarget != noEPTarget) {
if (captures.IsSet(board.enPassantTarget)) { if (captures.IsSet(board.enPassantTarget)) {
if (IsLegalEnPassant(board, square)) { if (IsLegalEnPassant(board, square)) {
board.AddMove(Move(square, board.enPassantTarget, epCapture)); board.AddMove(Move(square, board.enPassantTarget, epCapture));
} }
} }
}
// Removing own pieces from capture mask // Removing own pieces from capture mask
captures &= board.colors[!color]; captures &= board.colors[!color];
@@ -515,12 +517,14 @@ static void GenPawnMoves(Board &board, bool color) {
} }
// Checking for en passant // Checking for en passant
if (board.enPassantTarget != noEPTarget) {
if (captures.IsSet(board.enPassantTarget)) { if (captures.IsSet(board.enPassantTarget)) {
// Checking if the move gives discovered check to own king // Checking if the move gives discovered check to own king
if (IsLegalEnPassant(board, square)) { if (IsLegalEnPassant(board, square)) {
board.AddMove(Move(square, board.enPassantTarget, epCapture)); board.AddMove(Move(square, board.enPassantTarget, epCapture));
} }
} }
}
// Removing own pieces from capture mask // Removing own pieces from capture mask
captures &= board.colors[!color]; captures &= board.colors[!color];
@@ -868,6 +872,7 @@ static void GenCheckEvasions(Board &board, bool color) {
if (type == Pawn) { if (type == Pawn) {
pushes |= getPawnPushes(square, color, board.occupied) & pushMask; pushes |= getPawnPushes(square, color, board.occupied) & pushMask;
// Checking for en passant capture // Checking for en passant capture
if (board.enPassantTarget != noEPTarget) {
Bitboard attackedSquare = pawnAttacks[color][square] Bitboard attackedSquare = pawnAttacks[color][square]
& Bitboard::GetSquare(board.enPassantTarget); & Bitboard::GetSquare(board.enPassantTarget);
if (attackedSquare) { if (attackedSquare) {
@@ -883,6 +888,7 @@ static void GenCheckEvasions(Board &board, bool color) {
captureMask.PopBit(targetSquare); captureMask.PopBit(targetSquare);
} }
} }
}
} else { } else {
pushes |= getPieceAttacks(square, type, color, board.occupied) & pushMask; pushes |= getPieceAttacks(square, type, color, board.occupied) & pushMask;
} }