-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboard.h
125 lines (104 loc) · 4.01 KB
/
board.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// provides board class
#ifndef BOARD_H
#define BOARD_H
#include "util.h"
#include "player.h"
#include "observer.h"
#include "pieces.h"
using namespace std;
enum class SquareColor
{
Dark,
Light
};
int getRowForOutput(int r);
// class for the game board
// ! Board now persists between games
class Board
{
vector<vector<unique_ptr<Piece>>> board; // 2D vector
vector<unique_ptr<Observer>> observers; // textDisplay & GraphicsDisplay
unique_ptr<Player> whitePlayer;
unique_ptr<Player> blackPlayer;
Player *currPlayer;
float whiteScore = 0;
float blackScore = 0;
bool text;
bool graphics;
bool useUnicode;
bool debugOutput;
bool noCheat;
// called by initBoard()
void clearBoard(); // done
public:
Board(); // done
Board(
const PlayerType whitePl,
const int whiteLevel,
const PlayerType blackPl,
const int blackLevel,
const bool graphics,
const bool text,
const bool useUnicode,
const bool debug,
const bool noCheat); // done
// Copy ctor and assignment operator
Board(const Board &other);
Board &operator=(const Board &other);
// Move ctor and assignment operator
Board(Board &&other);
Board &operator=(Board &&other);
// Dtor
~Board() = default; // done
void initBoard(); // done
// Determine GameStates
bool isPlayerInCheck(const Player *plr) const;
bool isPlayerCheckmated(const Player *plr) const;
bool isPlayerStalemated(const Player *plr) const;
// Observer Pattern methods
void notifyObservers(Position pos) const;
void notifyObservers(std::vector<Position> vec) const;
void displayObservers() const;
void refreshObservers() const;
void attach(unique_ptr<Observer> o); // done
// SetUp mode
void addPiece(const PieceType &pt, const Colour &clr, const Position &pos); // done
void delPiece(const Position &pos); // done
bool boardIsValid() const;
// getters
Player *getPlayerByColour(Colour clr) const; // done
Player *getCurrPlayer() const; // done
Piece *getPiece(const Position &pos) const; // done
Piece *getPieceByCoords(int c, int r) const; // done
Piece *getPieceByPos(const Position &pos) const;
float getScore(Colour clr);
vector<Piece *> getPlayerPieces(const Player *plr) const;
Player *getNextPlayer() const;
int getPieceTypeCount(const PieceType &pt, const Colour &col) const;
// setters
void setTurn(Colour clr); // done
void flipTurn(); // done
void incrementScore(Colour clr, float addTo); // done
// advanced moves
vector<Move> getCastlingMoves(const Player *plr) const;
bool isCaslteValid(const Piece *p, const Player* plr, bool isLeftCaslte = false) const;
// Move logic
vector<Move> getMovesToUncheck(vector<Move> &moves) const; // todo
bool putsPlayerInCheck(const Move &m, const Player *plr) const;
int putsPlayerInCheckMate(const Move &m, const Player *plr) const;
//! returns position just for the sake of error reporting
Position makeMove();
void doMove(const Move &m);
bool checkMoveEndPos(const Move &m) const; // Checks if the end location is within bounds and can be occupied
bool isLegalMove(Move m) const; // Checks if the move doesn't put the player in checkmate
vector<Move> getValidMoves(const Player *plr, bool experiment = false) const; // Gets a list of valid moves that the player can make
bool didPlayerLose(Player *plr);
};
// public fn for entire program to use
bool isKing(const Piece *p);
bool isPawn(const Piece *p);
bool isWhite(const Piece *p);
Colour getNextColour(Colour clr);
bool moveIsValid(Move &move, vector<Move> &validMoves, char mode);
bool isCastleMove(const Move &move, const Board &b);
#endif