From 21fae88bdbe37cdc8346188dd594f1ae8bcc3fd5 Mon Sep 17 00:00:00 2001 From: "A.M. Rowsell" Date: Fri, 29 Aug 2025 04:17:16 -0400 Subject: [PATCH] fmt: reformatted code, changed some function signatures, fairly minor --- Piece.cpp | 16 +-- inc/Board.hpp | 46 +++++---- inc/Piece.hpp | 16 +-- main.cpp | 2 + nbproject/configurations.xml | 186 +++++++++++++++++++++++++++++++++-- 5 files changed, 216 insertions(+), 50 deletions(-) diff --git a/Piece.cpp b/Piece.cpp index e0ed418..ccfd82a 100644 --- a/Piece.cpp +++ b/Piece.cpp @@ -18,11 +18,11 @@ Piece::~Piece() { // so this is just a stub that does nothing. it doesn't matter // because only the derived class versions should be called. -std::vector Piece::getLegalMoves(const Square &from, const Board &board) const { +std::vector Piece::getLegalMoves(const Square &from, Board &board) const { std::vector moveList; return moveList; } -bool King::checkForCheck() const { +bool King::checkForCheck(Board &board) const { std::vector> kingVulnerable = { {-1, 0}, // Up {-1, -1}, // up-left @@ -45,7 +45,7 @@ bool King::checkForCheck() const { return inCheck; } -std::vector King::getLegalMoves(const Square &from, const Board &board) const { +std::vector King::getLegalMoves(const Square &from, Board &board) const { std::vector moveList; std::vector> directions = { {-1, 0}, // Up @@ -156,7 +156,7 @@ std::vector King::getLegalMoves(const Square &from, const Board &board) co return moveList; } -std::vector Rook::getLegalMoves(const Square &from, const Board &board) const { +std::vector Rook::getLegalMoves(const Square &from, Board &board) const { std::vector moveList; const int directions[4][2] = { {-1, 0}, // Up @@ -186,22 +186,22 @@ std::vector Rook::getLegalMoves(const Square &from, const Board &board) co return moveList; } -std::vector Queen::getLegalMoves(const Square &from, const Board &board) const { +std::vector Queen::getLegalMoves(const Square &from, Board &board) const { std::vector moveList; return moveList; } -std::vector Knight::getLegalMoves(const Square &from, const Board &board) const { +std::vector Knight::getLegalMoves(const Square &from, Board &board) const { std::vector moveList; return moveList; } -std::vector Bishop::getLegalMoves(const Square &from, const Board &board) const { +std::vector Bishop::getLegalMoves(const Square &from, Board &board) const { std::vector moveList; return moveList; } -std::vector Pawn::getLegalMoves(const Square &from, const Board &board) const { +std::vector Pawn::getLegalMoves(const Square &from, Board &board) const { std::vector moveList; const int directions[2][4][2] = { { diff --git a/inc/Board.hpp b/inc/Board.hpp index 4076b32..599b29e 100644 --- a/inc/Board.hpp +++ b/inc/Board.hpp @@ -9,39 +9,37 @@ #ifndef BOARD_HPP #define BOARD_HPP -#include -#include #include +#include +#include +#include + #include "Piece.hpp" // why do I have to forward declare all these?! class Piece; -enum Players { - PL_WHITE, PL_BLACK -}; +enum Players { PL_WHITE, PL_BLACK }; struct Square; class Board { - private: - friend class Piece; - Players playerTurn; - public: - // this should be protected, but even when Piece is declared as a friend, - // accessing it in Piece.cpp threw an error - std::vector>> boardGrid; - Board(); - virtual ~Board(); - void setupInitialPosition(); - Piece *getPieceAt(Square square); - void movePiece(Square from, Square to); - int setupFromFEN(std::string strFEN); - bool isInBounds(Square square) const; - bool isEmpty(Square square) const; - uint64_t serialBoard = 0xFFFF00000000FFFF; // opening position - void deserializeBoard(uint64_t incomingBoard); - +private: + friend class Piece; + Players playerTurn; +public: + // this should be protected, but even when Piece is declared as a friend, + // accessing it in Piece.cpp threw an error + std::vector>> boardGrid; + Board(); + virtual ~Board(); + void setupInitialPosition(); + std::unique_ptr &getPieceAt(Square square); + void movePiece(Square from, Square to); + int setupFromFEN(std::string strFEN); + bool isInBounds(Square square) const; + bool isEmpty(Square square) const; + uint64_t serialBoard = 0xFFFF00000000FFFF; // opening position + void deserializeBoard(uint64_t incomingBoard); }; #endif // BOARD_HPP - diff --git a/inc/Piece.hpp b/inc/Piece.hpp index b2cd0cb..15132dd 100644 --- a/inc/Piece.hpp +++ b/inc/Piece.hpp @@ -68,7 +68,7 @@ class Piece { Piece(PieceColour pColour) : colour(pColour) { } virtual ~Piece(); - virtual std::vector getLegalMoves(const Square &from, const Board &board) const; + virtual std::vector getLegalMoves(const Square &from, Board &board) const; PieceColour getColour() const { return colour; @@ -101,9 +101,9 @@ class King : public Piece { pieceSymbol = 'K'; pieceType = KING; } - virtual std::vector getLegalMoves(const Square &from, const Board &board) const override; + virtual std::vector getLegalMoves(const Square &from, Board &board) const override; - bool checkForCheck() const; + bool checkForCheck(Board &board) const; bool checkForCastle(enum CastleSide side) const { if(side == KINGSIDE) @@ -130,7 +130,7 @@ class Rook : public Piece { pieceSymbol = 'R'; pieceType = ROOK; } - virtual std::vector getLegalMoves(const Square &from, const Board &board) const override; + virtual std::vector getLegalMoves(const Square &from, Board &board) const override; }; class Queen : public Piece { @@ -142,7 +142,7 @@ class Queen : public Piece { pieceSymbol = 'Q'; pieceType = QUEEN; } - virtual std::vector getLegalMoves(const Square &from, const Board &board) const override; + virtual std::vector getLegalMoves(const Square &from, Board &board) const override; }; class Knight : public Piece { @@ -154,7 +154,7 @@ class Knight : public Piece { pieceSymbol = 'N'; pieceType = KNIGHT; } - virtual std::vector getLegalMoves(const Square &from, const Board &board) const override; + virtual std::vector getLegalMoves(const Square &from, Board &board) const override; }; class Bishop : public Piece { @@ -166,7 +166,7 @@ class Bishop : public Piece { pieceSymbol = 'B'; pieceType = BISHOP; } - virtual std::vector getLegalMoves(const Square &from, const Board &board) const override; + virtual std::vector getLegalMoves(const Square &from, Board &board) const override; }; class Pawn : public Piece { @@ -178,7 +178,7 @@ class Pawn : public Piece { pieceSymbol = 'P'; pieceType = PAWN; } - virtual std::vector getLegalMoves(const Square &from, const Board &board) const override; + virtual std::vector getLegalMoves(const Square &from, Board &board) const override; }; #endif // PIECE_HPP diff --git a/main.cpp b/main.cpp index 51059d6..fa1ca31 100644 --- a/main.cpp +++ b/main.cpp @@ -179,6 +179,8 @@ extern "C" int main(void) { initInterrupts(); Board gameBoard; NeoPixel boardLights(64); + + gameBoard.setupInitialPosition(); while(1) { } } diff --git a/nbproject/configurations.xml b/nbproject/configurations.xml index 2a6fe8d..28d6976 100644 --- a/nbproject/configurations.xml +++ b/nbproject/configurations.xml @@ -54,7 +54,7 @@ PIC32MX270F256B - noID + snap XC32 4.60 2 @@ -73,7 +73,7 @@ false - true + false @@ -87,7 +87,7 @@ false false - false + true @@ -103,12 +103,12 @@ - + - + @@ -141,7 +141,7 @@ - + @@ -171,7 +171,7 @@ - + @@ -214,18 +214,18 @@ - + - + - + @@ -261,6 +261,172 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +