diff options
| author | Adam <adammegarules1@gmail.com> | 2026-07-27 10:26:54 +0200 |
|---|---|---|
| committer | Adam <adammegarules1@gmail.com> | 2026-07-27 10:26:54 +0200 |
| commit | 658a797ec8cb5b6d8607fac089e036685f2a3958 (patch) | |
| tree | 2de2efc25079b74ab4cf8cdcba9ea5c4e0469ece /src/board.cpp | |
| parent | 9b1665430fd0379db92000740c7a70045baa1746 (diff) | |
adding enpassant
Diffstat (limited to 'src/board.cpp')
| -rw-r--r-- | src/board.cpp | 39 |
1 files changed, 34 insertions, 5 deletions
diff --git a/src/board.cpp b/src/board.cpp index 877e8c7..a74c5dc 100644 --- a/src/board.cpp +++ b/src/board.cpp @@ -35,7 +35,7 @@ Piece createPiece(PieceType type, bool color, bool moved) { piece.color = color; piece.moved = moved; return piece; -}; +} void printBoard(Board *b) { std::string line = " +-----------------+\n"; std::string whiteLetters = " a b c d e f g h\n"; @@ -87,6 +87,9 @@ void printBoard(Board *b) { assert(b->castle != ""); std::println("Castling: {}", b->castle); + std::println("Can enpassant: {}", b->canEnpassant ? "Yes" : "No"); + std::println("Where enpassant: {}{}", (char)((int)b->enPassant.file + 'A'), + 8 - (int)b->enPassant.rank); } void PlayMove(Move move, Board *b) { @@ -98,8 +101,34 @@ void PlayMove(Move move, Board *b) { assert(false && "capturing friendly piece error"); } } - b->pieces[PositionToIndex(move.To)] = piece; - b->pieces[PositionToIndex(move.From)] = {false, NONE, false}; - return; -} + piece.moved = true; + if (piece.type == PAWN || piece2.type == NONE) { + b->halfMoveClock = 0; + } else { + b->halfMoveClock++; + } + if (piece.type == PAWN && b->canEnpassant && move.To == b->enPassant) { + Position capturedPawn = move.To; + capturedPawn.rank += piece.color ? 1 : -1; + b->pieces[PositionToIndex(capturedPawn)] = {false, NONE, false}; + } + + b->canEnpassant = false; + b->MoveClock++; + + if (piece.type == PAWN) { + Position to = move.To; + to.rank -= (piece.color ? -2 : 2); + if (to == move.From) { + b->canEnpassant = true; + Position target = move.From; + target.rank += piece.color ? -1 : 1; + b->enPassant = target; + }; + + b->pieces[PositionToIndex(move.To)] = piece; + b->pieces[PositionToIndex(move.From)] = {false, NONE, false}; + return; + } +}; int PositionToIndex(Position i) { return i.rank * 8 + i.file; } |
