style: implement clang-format styling parameters
This commit is contained in:
parent
10a4dcb60b
commit
f2ce83335c
10 changed files with 462 additions and 547 deletions
305
Board.cpp
305
Board.cpp
|
|
@ -36,8 +36,7 @@ Board::Board() {
|
|||
boardGrid[i].resize(8);
|
||||
}
|
||||
|
||||
Board::~Board() {
|
||||
}
|
||||
Board::~Board() {}
|
||||
|
||||
void Board::setupInitialPosition() {
|
||||
// set up the board grid with smart pointers
|
||||
|
|
@ -45,46 +44,46 @@ void Board::setupInitialPosition() {
|
|||
playerTurn = PL_WHITE;
|
||||
for(int i = 0; i < 8; i++) {
|
||||
switch(i) {
|
||||
case 0:
|
||||
// white back rank
|
||||
boardGrid[i][0] = std::make_unique<Rook>(PIECE_WHITE);
|
||||
boardGrid[i][1] = std::make_unique<Knight>(PIECE_WHITE);
|
||||
boardGrid[i][2] = std::make_unique<Bishop>(PIECE_WHITE);
|
||||
boardGrid[i][3] = std::make_unique<Queen>(PIECE_WHITE);
|
||||
boardGrid[i][4] = std::make_unique<King>(PIECE_WHITE);
|
||||
boardGrid[i][5] = std::make_unique<Bishop>(PIECE_WHITE);
|
||||
boardGrid[i][6] = std::make_unique<Knight>(PIECE_WHITE);
|
||||
boardGrid[i][7] = std::make_unique<Rook>(PIECE_WHITE);
|
||||
break;
|
||||
case 1:
|
||||
// white pawn rank
|
||||
for(int j = 0; j <= 8; j++)
|
||||
boardGrid[i][j] = std::make_unique<Pawn>(PIECE_WHITE);
|
||||
break;
|
||||
case 2:
|
||||
case 3:
|
||||
case 4:
|
||||
case 5:
|
||||
for(int j = 0; j <= 8; j++)
|
||||
boardGrid[i][j] = nullptr;
|
||||
break;
|
||||
case 6:
|
||||
// black pawn rank
|
||||
for(int j = 0; j <= 8; j++)
|
||||
boardGrid[i][j] = std::make_unique<Pawn>(PIECE_BLACK);
|
||||
break;
|
||||
case 7:
|
||||
// black back rank
|
||||
boardGrid[i][0] = std::make_unique<Rook>(PIECE_BLACK);
|
||||
boardGrid[i][1] = std::make_unique<Knight>(PIECE_BLACK);
|
||||
boardGrid[i][2] = std::make_unique<Bishop>(PIECE_BLACK);
|
||||
boardGrid[i][3] = std::make_unique<Queen>(PIECE_BLACK);
|
||||
boardGrid[i][4] = std::make_unique<King>(PIECE_BLACK);
|
||||
boardGrid[i][5] = std::make_unique<Bishop>(PIECE_BLACK);
|
||||
boardGrid[i][6] = std::make_unique<Knight>(PIECE_BLACK);
|
||||
boardGrid[i][7] = std::make_unique<Rook>(PIECE_BLACK);
|
||||
default:
|
||||
break;
|
||||
case 0:
|
||||
// white back rank
|
||||
boardGrid[i][0] = std::make_unique<Rook>(PIECE_WHITE);
|
||||
boardGrid[i][1] = std::make_unique<Knight>(PIECE_WHITE);
|
||||
boardGrid[i][2] = std::make_unique<Bishop>(PIECE_WHITE);
|
||||
boardGrid[i][3] = std::make_unique<Queen>(PIECE_WHITE);
|
||||
boardGrid[i][4] = std::make_unique<King>(PIECE_WHITE);
|
||||
boardGrid[i][5] = std::make_unique<Bishop>(PIECE_WHITE);
|
||||
boardGrid[i][6] = std::make_unique<Knight>(PIECE_WHITE);
|
||||
boardGrid[i][7] = std::make_unique<Rook>(PIECE_WHITE);
|
||||
break;
|
||||
case 1:
|
||||
// white pawn rank
|
||||
for(int j = 0; j <= 8; j++)
|
||||
boardGrid[i][j] = std::make_unique<Pawn>(PIECE_WHITE);
|
||||
break;
|
||||
case 2:
|
||||
case 3:
|
||||
case 4:
|
||||
case 5:
|
||||
for(int j = 0; j <= 8; j++)
|
||||
boardGrid[i][j] = nullptr;
|
||||
break;
|
||||
case 6:
|
||||
// black pawn rank
|
||||
for(int j = 0; j <= 8; j++)
|
||||
boardGrid[i][j] = std::make_unique<Pawn>(PIECE_BLACK);
|
||||
break;
|
||||
case 7:
|
||||
// black back rank
|
||||
boardGrid[i][0] = std::make_unique<Rook>(PIECE_BLACK);
|
||||
boardGrid[i][1] = std::make_unique<Knight>(PIECE_BLACK);
|
||||
boardGrid[i][2] = std::make_unique<Bishop>(PIECE_BLACK);
|
||||
boardGrid[i][3] = std::make_unique<Queen>(PIECE_BLACK);
|
||||
boardGrid[i][4] = std::make_unique<King>(PIECE_BLACK);
|
||||
boardGrid[i][5] = std::make_unique<Bishop>(PIECE_BLACK);
|
||||
boardGrid[i][6] = std::make_unique<Knight>(PIECE_BLACK);
|
||||
boardGrid[i][7] = std::make_unique<Rook>(PIECE_BLACK);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
|
@ -99,7 +98,6 @@ void Board::clearBoard() {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
int Board::setupFromFEN(std::string strFEN) {
|
||||
std::vector<std::string> splitFEN = split(strFEN, ' ');
|
||||
if(splitFEN.size() != 6) // a valid FEN *must* contain 6 fields
|
||||
|
|
@ -113,104 +111,104 @@ int Board::setupFromFEN(std::string strFEN) {
|
|||
for(auto &ranks : splitField1) {
|
||||
for(auto &sym : ranks) {
|
||||
switch(sym) {
|
||||
case 'R':
|
||||
// white rook
|
||||
boardGrid[rank][file] = std::make_unique<Rook>(PIECE_WHITE);
|
||||
file++;
|
||||
break;
|
||||
case 'r':
|
||||
// black rook
|
||||
boardGrid[rank][file] = std::make_unique<Rook>(PIECE_BLACK);
|
||||
file++;
|
||||
break;
|
||||
case 'N':
|
||||
// white knight
|
||||
boardGrid[rank][file] = std::make_unique<Knight>(PIECE_WHITE);
|
||||
file++;
|
||||
break;
|
||||
case 'n':
|
||||
// black knight
|
||||
boardGrid[rank][file] = std::make_unique<Knight>(PIECE_BLACK);
|
||||
file++;
|
||||
break;
|
||||
case 'B':
|
||||
// white bishop
|
||||
boardGrid[rank][file] = std::make_unique<Bishop>(PIECE_WHITE);
|
||||
file++;
|
||||
break;
|
||||
case 'b':
|
||||
// black bishop
|
||||
boardGrid[rank][file] = std::make_unique<Bishop>(PIECE_BLACK);
|
||||
file++;
|
||||
break;
|
||||
case 'Q':
|
||||
// white queen
|
||||
boardGrid[rank][file] = std::make_unique<Queen>(PIECE_WHITE);
|
||||
file++;
|
||||
break;
|
||||
case 'q':
|
||||
// black queen;
|
||||
boardGrid[rank][file] = std::make_unique<Queen>(PIECE_BLACK);
|
||||
file++;
|
||||
break;
|
||||
case 'K':
|
||||
// white king
|
||||
if(wKingPlaced) {
|
||||
// invalid FEN, more than 1 white king
|
||||
return -1;
|
||||
} else {
|
||||
boardGrid[rank][file] = std::make_unique<King>(PIECE_WHITE);
|
||||
wKingPlaced = true;
|
||||
// store king position for later
|
||||
whiteKing.file = static_cast<File>(file);
|
||||
whiteKing.rank = static_cast<Rank>(rank);
|
||||
file++;
|
||||
}
|
||||
break;
|
||||
case 'k':
|
||||
// black king
|
||||
if(bKingPlaced) {
|
||||
// invalid FEN, more than 1 black king
|
||||
return -1;
|
||||
} else {
|
||||
boardGrid[rank][file] = std::make_unique<King>(PIECE_BLACK);
|
||||
bKingPlaced = true;
|
||||
// store king position for later
|
||||
blackKing.file = static_cast<File>(file);
|
||||
blackKing.rank = static_cast<Rank>(rank);
|
||||
file++;
|
||||
}
|
||||
break;
|
||||
case 'P':
|
||||
// white pawn
|
||||
boardGrid[rank][file] = std::make_unique<Pawn>(PIECE_WHITE);
|
||||
file++;
|
||||
break;
|
||||
case 'p':
|
||||
// black pawn
|
||||
boardGrid[rank][file] = std::make_unique<Pawn>(PIECE_BLACK);
|
||||
file++;
|
||||
break;
|
||||
case '1':
|
||||
case '2':
|
||||
case '3':
|
||||
case '4':
|
||||
case '5':
|
||||
case '6':
|
||||
case '7':
|
||||
case '8': {
|
||||
std::string skipStr(1, sym);
|
||||
skip = atoi(skipStr.c_str());
|
||||
//skip--; // fix off by 1 error
|
||||
while(skip--) {
|
||||
boardGrid[rank][file++] = nullptr; // remove reference
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
// invalid character?
|
||||
case 'R':
|
||||
// white rook
|
||||
boardGrid[rank][file] = std::make_unique<Rook>(PIECE_WHITE);
|
||||
file++;
|
||||
break;
|
||||
case 'r':
|
||||
// black rook
|
||||
boardGrid[rank][file] = std::make_unique<Rook>(PIECE_BLACK);
|
||||
file++;
|
||||
break;
|
||||
case 'N':
|
||||
// white knight
|
||||
boardGrid[rank][file] = std::make_unique<Knight>(PIECE_WHITE);
|
||||
file++;
|
||||
break;
|
||||
case 'n':
|
||||
// black knight
|
||||
boardGrid[rank][file] = std::make_unique<Knight>(PIECE_BLACK);
|
||||
file++;
|
||||
break;
|
||||
case 'B':
|
||||
// white bishop
|
||||
boardGrid[rank][file] = std::make_unique<Bishop>(PIECE_WHITE);
|
||||
file++;
|
||||
break;
|
||||
case 'b':
|
||||
// black bishop
|
||||
boardGrid[rank][file] = std::make_unique<Bishop>(PIECE_BLACK);
|
||||
file++;
|
||||
break;
|
||||
case 'Q':
|
||||
// white queen
|
||||
boardGrid[rank][file] = std::make_unique<Queen>(PIECE_WHITE);
|
||||
file++;
|
||||
break;
|
||||
case 'q':
|
||||
// black queen;
|
||||
boardGrid[rank][file] = std::make_unique<Queen>(PIECE_BLACK);
|
||||
file++;
|
||||
break;
|
||||
case 'K':
|
||||
// white king
|
||||
if(wKingPlaced) {
|
||||
// invalid FEN, more than 1 white king
|
||||
return -1;
|
||||
break;
|
||||
} else {
|
||||
boardGrid[rank][file] = std::make_unique<King>(PIECE_WHITE);
|
||||
wKingPlaced = true;
|
||||
// store king position for later
|
||||
whiteKing.file = static_cast<File>(file);
|
||||
whiteKing.rank = static_cast<Rank>(rank);
|
||||
file++;
|
||||
}
|
||||
break;
|
||||
case 'k':
|
||||
// black king
|
||||
if(bKingPlaced) {
|
||||
// invalid FEN, more than 1 black king
|
||||
return -1;
|
||||
} else {
|
||||
boardGrid[rank][file] = std::make_unique<King>(PIECE_BLACK);
|
||||
bKingPlaced = true;
|
||||
// store king position for later
|
||||
blackKing.file = static_cast<File>(file);
|
||||
blackKing.rank = static_cast<Rank>(rank);
|
||||
file++;
|
||||
}
|
||||
break;
|
||||
case 'P':
|
||||
// white pawn
|
||||
boardGrid[rank][file] = std::make_unique<Pawn>(PIECE_WHITE);
|
||||
file++;
|
||||
break;
|
||||
case 'p':
|
||||
// black pawn
|
||||
boardGrid[rank][file] = std::make_unique<Pawn>(PIECE_BLACK);
|
||||
file++;
|
||||
break;
|
||||
case '1':
|
||||
case '2':
|
||||
case '3':
|
||||
case '4':
|
||||
case '5':
|
||||
case '6':
|
||||
case '7':
|
||||
case '8': {
|
||||
std::string skipStr(1, sym);
|
||||
skip = atoi(skipStr.c_str());
|
||||
// skip--; // fix off by 1 error
|
||||
while(skip--) {
|
||||
boardGrid[rank][file++] = nullptr; // remove reference
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
// invalid character?
|
||||
return -1;
|
||||
break;
|
||||
}
|
||||
if(file > 7) {
|
||||
file = 0;
|
||||
|
|
@ -267,17 +265,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;
|
||||
}
|
||||
|
||||
|
|
@ -289,7 +287,8 @@ void Board::nextTurn() {
|
|||
|
||||
void Board::movePiece(Square from, Square to) {
|
||||
Piece *movingPiece = getPieceAt(from);
|
||||
if(!movingPiece) return;
|
||||
if(!movingPiece)
|
||||
return;
|
||||
|
||||
Square newEnPassantTarget = {INVALID_RANK, INVALID_FILE};
|
||||
|
||||
|
|
@ -309,7 +308,7 @@ void Board::movePiece(Square from, Square to) {
|
|||
// Move the piece
|
||||
setPieceAt(to, std::move(boardGrid[from.rank][from.file]));
|
||||
clearSquare(from);
|
||||
|
||||
|
||||
enPassantTargetSquare = newEnPassantTarget;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue