dev: Updates to Board and Piece, formatted code
This commit is contained in:
parent
8e381cf109
commit
f05dd6d90f
6 changed files with 122 additions and 121 deletions
51
Board.cpp
51
Board.cpp
|
|
@ -93,9 +93,8 @@ void Board::setupInitialPosition() {
|
|||
*/
|
||||
void Board::clearBoard() {
|
||||
for(int i = 0; i < 8; i++) {
|
||||
for(int j = 0; j < 8; j++) {
|
||||
for(int j = 0; j < 8; j++)
|
||||
boardGrid[i][j] = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -167,8 +166,8 @@ int Board::setupFromFEN(std::string strFEN) {
|
|||
boardGrid[rank][file] = std::make_unique<King>(PIECE_WHITE);
|
||||
wKingPlaced = true;
|
||||
// store king position for later
|
||||
whiteKing.file = file;
|
||||
whiteKing.rank = rank;
|
||||
whiteKing.file = static_cast<File>(file);
|
||||
whiteKing.rank = static_cast<Rank>(rank);
|
||||
file++;
|
||||
}
|
||||
break;
|
||||
|
|
@ -181,8 +180,8 @@ int Board::setupFromFEN(std::string strFEN) {
|
|||
boardGrid[rank][file] = std::make_unique<King>(PIECE_BLACK);
|
||||
bKingPlaced = true;
|
||||
// store king position for later
|
||||
blackKing.file = file;
|
||||
blackKing.rank = rank;
|
||||
blackKing.file = static_cast<File>(file);
|
||||
blackKing.rank = static_cast<Rank>(rank);
|
||||
file++;
|
||||
}
|
||||
break;
|
||||
|
|
@ -241,8 +240,11 @@ int Board::setupFromFEN(std::string strFEN) {
|
|||
// ====== END OF FIELD 2 ======
|
||||
// ====== START OF FIELD 3 ======
|
||||
std::string k = "k", K = "K", q = "q", Q = "Q";
|
||||
auto &bKing = this->getPieceAt(blackKing);
|
||||
auto &wKing = this->getPieceAt(whiteKing);
|
||||
// yeah this is hacky af but it works... blame SO
|
||||
Piece *baseBKing = getPieceAt(blackKing).get();
|
||||
Piece *baseWKing = getPieceAt(whiteKing).get();
|
||||
King *bKing = dynamic_cast<King *>(baseBKing);
|
||||
King *wKing = dynamic_cast<King *>(baseWKing);
|
||||
if(splitFEN[2] == "-") {
|
||||
// nobody can castle, either side
|
||||
bKing->setCastleKS(false);
|
||||
|
|
@ -269,19 +271,17 @@ int Board::setupFromFEN(std::string strFEN) {
|
|||
// ====== END OF FIELD 3 ======
|
||||
// ====== START OF FIELD 4 ======
|
||||
// if a pawn has just moved and can be attacked enPassant, it will be listed here
|
||||
|
||||
|
||||
#ifdef DEBUG
|
||||
for(auto &ranks : boardGrid) {
|
||||
for(auto &files : ranks) {
|
||||
if(files)
|
||||
std::cout << files->getPieceName() << " ";
|
||||
else
|
||||
std::cout << "E ";
|
||||
}
|
||||
std::cout << "\n";
|
||||
}
|
||||
#endif
|
||||
//#ifdef DEBUG
|
||||
// for(auto &ranks : boardGrid) {
|
||||
// for(auto &files : ranks) {
|
||||
// if(files)
|
||||
// std::cout << files->getPieceName() << " ";
|
||||
// else
|
||||
// std::cout << "E ";
|
||||
// }
|
||||
// std::cout << "\n";
|
||||
// }
|
||||
//#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -302,13 +302,16 @@ void Board::movePiece(Square from, Square to) {
|
|||
}
|
||||
|
||||
void Board::deserializeBoard(uint64_t incomingBoard) {
|
||||
uint8_t boardRows[8];
|
||||
union {
|
||||
uint8_t boardRows[8];
|
||||
uint64_t fullBoard;
|
||||
} serialBoard;
|
||||
for(int i = 0; i < 8; i++)
|
||||
boardRows[i] = (incomingBoard >> (8 * i)) & 0xFF;
|
||||
serialBoard.boardRows[i] = static_cast<uint8_t>((incomingBoard >> (8 * i)) & 0xFF);
|
||||
// how do we then figure out what has moved?
|
||||
return;
|
||||
}
|
||||
|
||||
std::unique_ptr<Piece> &Board::getPieceAt(Square square) {
|
||||
return boardGrid[square.rank][square.file];
|
||||
return boardGrid[static_cast<int>(square.rank)][static_cast<int>(square.file)];
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue