diff options
| author | Adam <adammegarules1@gmail.com> | 2026-08-03 21:56:36 +0200 |
|---|---|---|
| committer | Adam <adammegarules1@gmail.com> | 2026-08-03 21:56:36 +0200 |
| commit | 27e879c62ecc019591201b1b1068b0c41870cfab (patch) | |
| tree | c012f4f9991af93ed6b0c1b73dabf72815696707 /src/board/board.cpp | |
| parent | 9acc4d8b4fb616e8a0b0d2fed85a752c3a86ccc6 (diff) | |
a big hell of a commit
Diffstat (limited to 'src/board/board.cpp')
| -rw-r--r-- | src/board/board.cpp | 69 |
1 files changed, 66 insertions, 3 deletions
diff --git a/src/board/board.cpp b/src/board/board.cpp index 16efbd3..28183a2 100644 --- a/src/board/board.cpp +++ b/src/board/board.cpp @@ -61,6 +61,19 @@ UndoMove MakeMove(Move move, Game *g) { undo.wasEnPassantCapture = true; undo.enPassantCapturedSquare = capturedPawn; undo.enPassantCapturedPiece = g->pieces[PositionToIndex(capturedPawn)]; + + bool captuaredColor = !piece.color; + uint64_t square = 1ULL << PositionToIndex(capturedPawn); + + g->PieceBitboards[captuaredColor][PAWN] ^= square; + + if (captuaredColor) + g->WhitePieceBitboard ^= square; + else + g->BlackPieceBitboard ^= square; + + g->PieceBitboard = g->WhitePieceBitboard | g->BlackPieceBitboard; + g->pieces[PositionToIndex(capturedPawn)] = {false, NONEPIECE}; } @@ -69,11 +82,11 @@ UndoMove MakeMove(Move move, Game *g) { // Adding enpassant if (piece.type == PAWN) { Position to = move.To; - to.rank -= static_cast<uint8_t>(piece.color ? -2 : 2); + to.rank -= static_cast<uint8_t>(piece.color ? 2 : -2); if (to == move.From) { g->canEnpassant = true; Position target = move.From; - target.rank += static_cast<uint8_t>(piece.color ? -1 : 1); + target.rank += static_cast<uint8_t>(piece.color ? 1 : -1); g->enPassant = target; }; } @@ -98,6 +111,19 @@ UndoMove MakeMove(Move move, Game *g) { Position rookTo = move.From; rookTo.file = 5; + uint64_t from = 1ULL << PositionToIndex(rookFrom); + uint64_t to = 1ULL << PositionToIndex(rookTo); + + g->PieceBitboards[piece.color][ROOK] ^= from; + g->PieceBitboards[piece.color][ROOK] ^= to; + + if (piece.color) + g->WhitePieceBitboard ^= from | to; + else + g->BlackPieceBitboard ^= from | to; + + g->PieceBitboard = g->WhitePieceBitboard | g->BlackPieceBitboard; + g->pieces[PositionToIndex(rookTo)] = g->pieces[PositionToIndex(rookFrom)]; g->pieces[PositionToIndex(rookFrom)] = {false, NONEPIECE}; } else { @@ -108,6 +134,19 @@ UndoMove MakeMove(Move move, Game *g) { Position rookTo = move.From; rookTo.file = 3; + uint64_t from = 1ULL << PositionToIndex(rookFrom); + uint64_t to = 1ULL << PositionToIndex(rookTo); + + g->PieceBitboards[piece.color][ROOK] ^= from; + g->PieceBitboards[piece.color][ROOK] ^= to; + + if (piece.color) + g->WhitePieceBitboard ^= from | to; + else + g->BlackPieceBitboard ^= from | to; + + g->PieceBitboard = g->WhitePieceBitboard | g->BlackPieceBitboard; + g->pieces[PositionToIndex(rookTo)] = g->pieces[PositionToIndex(rookFrom)]; g->pieces[PositionToIndex(rookFrom)] = {false, NONEPIECE}; } @@ -162,6 +201,31 @@ UndoMove MakeMove(Move move, Game *g) { } // playing the moves + uint64_t from = 1ULL << PositionToIndex(move.From); + uint64_t to = 1ULL << PositionToIndex(move.To); + + // remove moving piece from source + g->PieceBitboards[piece.color][undo.movedPiece.type] ^= from; + + // remove captured piece + if (piece2.type != NONEPIECE) { + g->PieceBitboards[piece2.color][piece2.type] ^= to; + + if (piece2.color) + g->WhitePieceBitboard ^= to; + else + g->BlackPieceBitboard ^= to; + } + + // add moving piece to destination + g->PieceBitboards[piece.color][piece.type] ^= to; + + if (piece.color) + g->WhitePieceBitboard ^= from | to; + else + g->BlackPieceBitboard ^= from | to; + + g->PieceBitboard = g->WhitePieceBitboard | g->BlackPieceBitboard; g->pieces[PositionToIndex(move.To)] = piece; g->pieces[PositionToIndex(move.From)] = {false, NONEPIECE}; @@ -182,7 +246,6 @@ UndoMove MakeMove(Move move, Game *g) { if (g->halfMoveClock >= 50) { g->state = DRAW; } - UpdateHelpers(g); return undo; }; void UnMakeMove(UndoMove undo, Game *g) { |
