Compare commits
2 Commits
c52f57293e
...
16c7fe2a34
Author | SHA1 | Date | |
---|---|---|---|
16c7fe2a34 | |||
4671fec523 |
33
Board.cpp
33
Board.cpp
@@ -5,6 +5,7 @@
|
||||
#include <cmath>
|
||||
#include <bitset>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
|
||||
Board::Board() {
|
||||
}
|
||||
@@ -108,13 +109,25 @@ void Board::makeMove(const Move &move) {
|
||||
}
|
||||
}
|
||||
|
||||
// en passant
|
||||
handleEnPassant(move, movedPiece);
|
||||
|
||||
handlePawnDoubleAdvance(move, toBB, movedPiece);
|
||||
|
||||
|
||||
// change turn
|
||||
mTurn = !mTurn;
|
||||
}
|
||||
void Board::handleEnPassant(const Move &move, const Piece &movedPiece) {
|
||||
if (movedPiece.type() == PieceType::Pawn && mEPS.has_value() && move.from().file() != move.to().file()) {
|
||||
auto epBB = indexToBitBoard(Square::fromCoordinates(move.to().file(), move.from().rank())->index());
|
||||
auto capturedPiece = Piece(!mTurn, PieceType::Pawn);
|
||||
|
||||
mPieceBBs[toIndex(capturedPiece.color())] ^= epBB;
|
||||
mPieceBBs[toIndex(capturedPiece.type())] ^= epBB;
|
||||
mOccupiedBB ^= epBB;
|
||||
}
|
||||
}
|
||||
|
||||
void Board::handlePawnDoubleAdvance(const Move &move, BitBoard bb, const Piece &movedPiece) {
|
||||
if (movedPiece.type() == PieceType::Pawn) {
|
||||
auto fromR = move.from().rank();
|
||||
@@ -185,6 +198,24 @@ bool Board::isMoveCastling(const BitBoard &from, const BitBoard &to, const Piece
|
||||
|
||||
return (from & indexToBitBoard(E8));
|
||||
}
|
||||
void Board::printBitBoard(const Board::BitBoard &bb) {
|
||||
// For debugging only, performance isn't important
|
||||
for (int i = 7; i >= 0; i--) {
|
||||
int rank = i * 8;
|
||||
for (int j = 0; j < 8; j++) {
|
||||
// Get the piece for this index. Assume it exists.
|
||||
// Print piece, otherwise '.';
|
||||
if (bb & (1ULL << (rank + j))) {
|
||||
std::cout << 1;
|
||||
} else {
|
||||
std::cout << '.';
|
||||
}
|
||||
|
||||
std::cout << ' ';
|
||||
}
|
||||
std::cout << '\n';
|
||||
}
|
||||
}
|
||||
|
||||
std::ostream &operator<<(std::ostream &os, const Board &board) {
|
||||
// For debugging only, performance isn't important
|
||||
|
@@ -127,7 +127,9 @@ private:
|
||||
return __builtin_ctzll(b);
|
||||
}
|
||||
|
||||
static void printBitBoard(const BitBoard &bb);
|
||||
void handlePawnDoubleAdvance(const Move &move, BitBoard bb, const Piece &movedPiece);
|
||||
void handleEnPassant(const Move &move, const Piece &movedPiece);
|
||||
};
|
||||
|
||||
std::ostream &operator<<(std::ostream &os, const Board &board);
|
||||
|
Reference in New Issue
Block a user