-
Notifications
You must be signed in to change notification settings - Fork 0
/
CBoard.h
150 lines (129 loc) · 4.19 KB
/
CBoard.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#ifndef CBOARD_H
#define CBOARD_H
#include "COLOR.h"
#include "CSlot.h"
class CGameSession;
class CPiece;
class CKing;
class CSlot;
class CMoveList;
class CMyMove;
using namespace std;
/**
* Class representing a chessboard
*/
class CBoard {
/**
* Static method rotating given move as if it was made from the other side of the board
* @param CMyMove given move to rotate
*/
static void translateMove(CMyMove & move);
public:
CBoard();
/**
* Copyconstructor
* @param oth Another board
*/
CBoard(const CBoard & oth);
/**
* Like copyconstructor but performed on existing board
* @param oth Another board
*/
void copy(const CBoard & oth);
/**
* Prints the board and its pieces in a fancy way (obviously)
*/
void printBoard() const;
/**
* (DEV FEATURE) Prints information about all slots on the board
*/
void printDebug() const;
/**
* Prints rotated board. Used for a 'rotate' command from user - see @ref COMMAND
*/
void printRotate() const;
/**
* (DEV FEATURE) Prints all possible moves that have been found for current player
* @param list List of the moves
*/
void printPossibleMoves(const CMoveList & list) const;
/**
* Fills the chessboard with pieces
* @param color of player 1 (on the bottom of the chessboard)
*/
void initBoard(COLOR player1col);
/**
* Returns a piece stored on a given slot
* @param x Row of the slot
* @param y Column of the slot
* @return pointer to the stored piece
*/
CPiece * getPiece(int x, int y) const;
/**
* Checks whether a slot is in or out of the chessboard
* @param x Row of the slot
* @param y Column of the slot
*/
bool outOfBoard(int x,int y) const;
/**
* Sets a given piece to a given slot on the chessboard
* @param row Row of the slot
* @param col Column of the slot
* @param pc Pointer to the piece to be set
*/
void setField(int row, int col, CPiece * pc);
/**
* Actually rotates the board
*/
void rotateBoard();
/**
* Performs a move given by a parameter
* @param move Move to be performed
*/
void moveFigure(const CMyMove & move);
/**
* Returns a value of a given slot on the chessboard
* @param x Row of the slot
* @param y Column of the slot
* @return Value of the slot
*/
int getSlotValue(int x,int y) const;
/**
* Creates a ficture chessboard and performs a given move on it
* @param move Move to be performed
* @param gS reference to the game instance
* @return bool Indicator if the move is valid (Not resulting with a check of the current player's king)
*/
bool tryMove(const CMyMove & move,const CGameSession & gS) const;
/**
* Finds a king specified by a its color on the chessboard
* @param col Color of the king to be found
* @return pointer to the king of the given color (the king certainly exists)
*/
CKing * findKing(COLOR col) const;
int INIT_ROW_UP; ///< The starting row of the pawns on the upper side of the board
int INIT_ROW_DOWN; ///< The starting row of the pawns on the lower side of the board
int LAST_ROW_UP; ///< The last row on the upper side of the board
int LAST_ROW_DOWN; ///< The last row on the lower side of the board
private:
/**
* Swaps figures on two slots
* @param r1 Row of the first slot
* @param c1 Column of the first slot
* @param r2 Row of the second slot
* @param c2 Column of the second slot
*/
void swapFigures(int r1,int c1, int r2,int c2);
/**
* Creates pieces. Called by CBoard::initBoard() method
* @param colorUp A color of the figures on the upper side of the board
*/
void createPieces(COLOR colorUp);
/**
* When a pawn reaches the other side of the board it gets exchanged for a queen figure
* @param move The move of a pawn to the edge of the board
*/
void promotePawn(const CMyMove & move);
CSlot slotsArr[8][8]; ///< 2D array of the slots holding the figures
};
#endif /* CBOARD_H */