-
Notifications
You must be signed in to change notification settings - Fork 0
/
Board.h
238 lines (156 loc) · 6.43 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
#pragma once
#include "SDL.h"
#include "Move.h"
#include "BoardState.h"
#include "Box.h"
#include "MoveStack.h"
#include "PieceLocations.h"
#include "KingThreatenedInfo.h"
#include <vector>
class Board
{
private:
SDL_Color boardColor1;
SDL_Color boardColor2;
BoardState* boardState;
PieceLocations whiteLocations;
PieceLocations blackLocations;
KingThreatenedInfo whiteThreatened;
KingThreatenedInfo blackThreatened;
//moving piece stuff.
bool draggingPiece;
Box draggingPieceBox;
SDL_Texture* draggingPieceTexture;
//Move stuff
std::vector<Move> pseudoLegalMoves;
std::vector<Move> legalMoves;
std::vector<Box> highlightBoxes;
Box highlightKingBox;
Box winnerKing;
Move promotionMove;
bool gameOver;
bool waitingForPromotionChoice;
char winner;
MoveStack moveStack;
public:
static int boxXWidth;
static int boxYHeight;
static int boardXBoxes;
static int boardYBoxes;
~Board();
void update();
void render(BoardState*);
void resize();
void init();
void renderBoard();
void renderDraggedPiece();
void handleMouseButtonDown(SDL_MouseButtonEvent&, BoardState*);
void attemptPickupPiece(int x, int y,BoardState*);
void attemptPlacePiece(int x, int y,BoardState*);
void stopDraggingPiece();
int getWidth();
int getHeight();
BoardState* getBoardState();
void printBoardState(BoardState*);
void renderPieces(BoardState*);
void renderPiece(Box,BoardState*);
void renderPieceTexture(SDL_Texture*, int x, int y);
SDL_Texture* getTextureAtLocation(int x, int y,BoardState*);
void loadBoardFromFen(const char* fen,BoardState*);
bool pieceIsCurrentPlayersPiece(int x, int y,BoardState*);
void switchTurns(BoardState*);
//updates the en passant squares.
void updateEnPassant(Box fromBox, Box toBox, BoardState*);
bool isEnPassant(Box fromBox, Box toBox, BoardState*);
//updates castling stuff.
void updateCastling(Box fromBox, Box toBox, BoardState*);
//calculating legal move stuff
void clearMoves();
std::vector<Move> calculatePseudoLegalMoves(BoardState*);
std::vector<Move> calculateLegalMoves(BoardState*);
void calculateRookMoves(Box,BoardState*, std::vector<Move>&);
void calculateBishopMoves(Box,BoardState*, std::vector<Move>&);
void calculateKnightMoves(Box,BoardState*, std::vector<Move>&);
void calculateKingMoves(Box,BoardState*, std::vector<Move>&);
void calculateQueenMoves(Box,BoardState*, std::vector<Move>&);
void calculatePawnUpMoves(Box,BoardState*, std::vector<Move>&);
void calculatePawnDownMoves(Box, BoardState*, std::vector<Move>&);
void calculateCastlingMoves(Box,BoardState*, std::vector<Move>&);
void calculateRookLegalMoves(Box,Box,BoardState*, std::vector<Move>&,KingThreatenedInfo);
void calculateKingLegalMoves(Box, BoardState*, std::vector<Move>&, KingThreatenedInfo);
void calculateBishopLegalMoves(Box, Box,BoardState*, std::vector<Move>&,KingThreatenedInfo);
void calculateQueenLegalMoves(Box, Box, BoardState*, std::vector<Move>&, KingThreatenedInfo);
void calculatePawnLegalMoves(Box, Box, BoardState*, std::vector<Move>&, KingThreatenedInfo);
void calculateKnightLegalMoves(Box, Box, BoardState*, std::vector<Move>&, KingThreatenedInfo);
void calculateCastlingLegalMoves(Box, BoardState*, std::vector<Move>&);
void attemptAddMove(Move move, BoardState* currentBoardState, std::vector<Move>& moves);
void addStraightUpMoves(Box, BoardState*, std::vector<Move>&);
void addStraightDownMoves(Box, BoardState*, std::vector<Move>&);
void addStraightLeftMoves(Box, BoardState*, std::vector<Move>&);
void addStraightRightMoves(Box, BoardState*, std::vector<Move>&);
void addUpRightMoves(Box, BoardState*, std::vector<Move>&);
void addDownRightMoves(Box, BoardState*, std::vector<Move>&);
void addUpLeftMoves(Box, BoardState*, std::vector<Move>&);
void addDownLeftMoves(Box, BoardState*, std::vector<Move>&);
void addStraightUpPawnMoves(Box, BoardState*, std::vector<Move>&);
void addStraightDownPawnMoves(Box, BoardState*, std::vector<Move>&);
void addDownLeftPawnMoves(Box, BoardState*, std::vector<Move>&);
void addDownRightPawnMoves(Box, BoardState*, std::vector<Move>&);
void addUpRightPawnMoves(Box, BoardState*, std::vector<Move>&);
void addUpLeftPawnMoves(Box, BoardState*, std::vector<Move>&);
bool inSameRow(Box, Box);
bool inSameCol(Box, Box);
//bottom left to top right
bool inSameDiagonal(Box, Box);
//bottom left to top right.
bool inSameReverseDiagonal(Box, Box);
void nextTurn(BoardState* boardState);
bool inLegalMoves(struct Move&);
bool inPseudoMoves(struct Move&);
void makeMove(struct Move, BoardState*);
bool canEnPassant(Box, Box, BoardState*);
void updateAllThreats(char curentTurn, BoardState* currentBoardState);
void updateMoveToThreats(Move, BoardState*);
void updateThreats(Move, BoardState*);
void updateStraightUpThreats(char currentTurn, BoardState*);
void updateStraightLeftThreats(char currentTurn,BoardState* boardState);
void updateStraightDownThreats(char currentTurn, BoardState*);
void updateStraightRightThreats(char currentTurn, BoardState* boardState);
void updateUpLeftThreats(char currentTurn, BoardState*);
void updateUpRightThreats(char currentTurn, BoardState* boardState);
void updateDownLeftThreats(char currentTurn, BoardState*);
void updateDownRightThreats(char currentTurn, BoardState* boardState);
//king threatened stuff
void initializeKingsThreatened(BoardState*);
bool kingAttacked(BoardState* currentBoardState);
bool doesBoxBlockAttack(Box, BoardState* currentBoardState);
void unMakeMove(BoardState*);
void renderAttackedSquares();
void renderBox(Box, SDL_Color);
//what moves should we highlight?
void renderHighlightMoves();
void renderPreviousMove();
void createHighlightMoves(int x, int y);
//check and checkmate stuff
bool kingInCheck(BoardState* currentBoardState);
void findKingLocation(int*, int*, BoardState*);
bool squareAttacked(Box box, BoardState* currentBoardState);
void updateHighlightKingBox();
void renderKingBox();
//game over stuff.
int isGameOver(BoardState* currentBoardState);
void reset();
int totalPossibleFutureBoardPositions(BoardState*, int depth);
void calculateBoardStates();
void renderPromotionOptions();
void togglePromotionOptions();
void tryPickingPromotionPiece(int, int, BoardState*);
void promoteQueen(BoardState*);
void promoteRook(BoardState*);
void promoteBishop(BoardState*);
void promoteKnight(BoardState*);
//random moves down here:
void makeRandomMove(BoardState*);
//piece location stuff
void initializePieceLocations(BoardState*);
};