Files
cpl_cpp-project/Board.cpp

96 lines
2.0 KiB
C++

#include "Board.hpp"
#include <ostream>
#include <cassert>
#include <cmath>
#include <bitset>
#include <algorithm>
Board::Board() {
}
void Board::setPiece(const Square &square, const Piece::Optional &piece) {
auto index = square.index();
for (auto &item : mPieceBBs) {
clearIndex(item, index);
}
setIndex(mPieceBBs[piece->typeVal() + piece->colorVal()], index);
}
Piece::Optional Board::piece(const Square &square) const {
int i = 0;
BitBoard mask = indexToBitBoard(square.index());
for (const auto &kPieceBb : mPieceBBs) {
if (kPieceBb & mask) {
return Piece::fromValue(i);
}
i++;
}
return std::nullopt;
}
void Board::setTurn(PieceColor turn) {
mTurn = turn;
}
PieceColor Board::turn() const {
return mTurn;
}
void Board::setCastlingRights(CastlingRights cr) {
mCr = cr;
}
CastlingRights Board::castlingRights() const {
return mCr;
}
void Board::setEnPassantSquare(const Square::Optional &square) {
mEPS = square->index();
}
Square::Optional Board::enPassantSquare() const {
return Square::fromIndex(mEPS);
}
void Board::makeMove(const Move &move) {
(void) move;
}
void Board::pseudoLegalMoves(MoveVec &moves) const {
(void) moves;
}
void Board::pseudoLegalMovesFrom(const Square &from,
Board::MoveVec &moves) const {
(void) from;
(void) moves;
}
std::ostream &operator<<(std::ostream &os, const Board &board) {
// For debugging only, performance isn't important
for (int i = 63; i >= 0; i--) {
// Get the piece for this index. Assume it exists.
auto piece = board.piece(Square::fromIndex(i).value());
// Print piece, otherwise '.';
if (piece.has_value()) {
os << piece.value();
} else {
os << '.';
}
// If a file is done, output newline
if (i % 8 == 0) {
os << '\n';
} else {
os << ' ';
}
}
return os;
}