organize: moved include files to inc/

This commit is contained in:
A.M. Rowsell 2025-08-28 10:45:41 -04:00
commit 22fe7bdf0b
Signed by untrusted user who does not match committer: amr
GPG key ID: E0879EDBDB0CA7B1
7 changed files with 7 additions and 7 deletions

47
inc/Board.hpp Normal file
View file

@ -0,0 +1,47 @@
// © 2025 A.M. Rowsell <amr@frzn.dev>
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
// This Source Code Form is "Incompatible With Secondary Licenses", as
// defined by the Mozilla Public License, v. 2.0.
#ifndef BOARD_HPP
#define BOARD_HPP
#include <vector>
#include <memory>
#include <cstdint>
#include "Piece.hpp"
// why do I have to forward declare all these?!
class Piece;
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<std::vector<std::unique_ptr<Piece>>> 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);
};
#endif // BOARD_HPP

30
inc/NeoPixel.hpp Normal file
View file

@ -0,0 +1,30 @@
// © 2025 A.M. Rowsell <amr@frzn.dev>
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
// This Source Code Form is "Incompatible With Secondary Licenses", as
// defined by the Mozilla Public License, v. 2.0.
#ifndef NEOPIXEL_HPP
#define NEOPIXEL_HPP
#include <cstdint>
#include <xc.h>
class NeoPixel {
public:
NeoPixel(uint8_t stringLength) : length(stringLength) {
gpioPin = LATBbits.LATB9;
};
uint8_t setNeoPixel(uint8_t index, uint8_t red, uint8_t green, uint8_t blue);
void allPixelsOff(void);
private:
uint8_t sendPixelData(uint8_t count, uint8_t *data);
uint8_t PixelArray[64][3] = {{0}};
uint8_t length;
volatile uint32_t gpioPin;
};
#endif // NEOPIXEL_HPP

184
inc/Piece.hpp Normal file
View file

@ -0,0 +1,184 @@
// © 2025 A.M. Rowsell <amr@frzn.dev>
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
// This Source Code Form is "Incompatible With Secondary Licenses", as
// defined by the Mozilla Public License, v. 2.0.
#ifndef PIECE_HPP
#define PIECE_HPP
#pragma once
#include <cstdint>
#include <algorithm>
#include <utility>
#include <string>
#include <memory>
#include <vector>
#include "Board.hpp"
class Board;
enum PieceType {
PAWN, BISHOP, KNIGHT, ROOK, QUEEN, KING, EMPTY
};
enum PieceColour {
PIECE_WHITE, PIECE_BLACK, PIECE_EMPTY
};
enum Rank {
R1 = 0, R2 = 1, R3 = 2, R4 = 3, R5 = 4, R6 = 5, R7 = 6, R8 = 7, INVALID_RANK = 255
};
enum File {
A = 0, B = 1, C = 2, D = 3, E = 4, F = 5, G = 6, H = 7, INVALID_FILE = 255
};
enum CastleSide {
KINGSIDE = 1, QUEENSIDE = 2
};
struct Square {
Rank rank;
File file;
bool isValid() const {
return rank >= 0 && rank < 8 && file >= 0 && file < 8;
}
};
struct Move {
Square from;
Square to;
};
class Piece {
private:
friend class Board;
protected:
PieceColour colour;
PieceType pieceType;
std::string pieceName;
char pieceSymbol;
bool hasMoved = false;
public:
Piece(PieceColour pColour) : colour(pColour) {
}
virtual ~Piece();
virtual std::vector<Move> getLegalMoves(const Square &from, const Board &board) const;
PieceColour getColour() const {
return colour;
}
std::string getPieceName() const {
return pieceName;
}
char getPieceSymbol() const {
return pieceSymbol;
}
PieceType getPieceType() const {
return pieceType;
}
bool checkIfMoved() const {
return hasMoved;
}
};
class King : public Piece {
private:
friend class Board;
public:
King(PieceColour colour) : Piece(colour) {
pieceName = "King";
pieceSymbol = 'K';
pieceType = KING;
}
virtual std::vector<Move> getLegalMoves(const Square &from, const Board &board) const override;
bool checkForCheck() const;
bool checkForCastle(enum CastleSide side) const {
if(side == KINGSIDE)
return canCastleKS;
else if(side == QUEENSIDE)
return canCastleQS;
else
return false;
}
protected:
bool canCastleQS = true;
bool canCastleKS = true;
bool inCheck = false;
};
class Rook : public Piece {
friend class Board;
public:
Rook(PieceColour colour) : Piece(colour) {
pieceName = "Rook";
pieceSymbol = 'R';
pieceType = ROOK;
}
virtual std::vector<Move> getLegalMoves(const Square &from, const Board &board) const override;
};
class Queen : public Piece {
friend class Board;
public:
Queen(PieceColour colour) : Piece(colour) {
pieceName = "Queen";
pieceSymbol = 'Q';
pieceType = QUEEN;
}
virtual std::vector<Move> getLegalMoves(const Square &from, const Board &board) const override;
};
class Knight : public Piece {
friend class Board;
public:
Knight(PieceColour colour) : Piece(colour) {
pieceName = "Knight";
pieceSymbol = 'N';
pieceType = KNIGHT;
}
virtual std::vector<Move> getLegalMoves(const Square &from, const Board &board) const override;
};
class Bishop : public Piece {
friend class Board;
public:
Bishop(PieceColour colour) : Piece(colour) {
pieceName = "Bishop";
pieceSymbol = 'B';
pieceType = BISHOP;
}
virtual std::vector<Move> getLegalMoves(const Square &from, const Board &board) const override;
};
class Pawn : public Piece {
friend class Board;
public:
Pawn(PieceColour colour) : Piece(colour) {
pieceName = "Pawn";
pieceSymbol = 'P';
pieceType = PAWN;
}
virtual std::vector<Move> getLegalMoves(const Square &from, const Board &board) const override;
};
#endif // PIECE_HPP