-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchessLogic.hpp
112 lines (91 loc) · 2.4 KB
/
chessLogic.hpp
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
#include <vector>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <assert.h>
typedef unsigned char UInt8;
enum {
BP = 'p',
BR = 'r',
BN = 'n',
BB = 'b',
BQ = 'q',
BK = 'k',
WP = 'P',
WR = 'R',
WN = 'N',
WB = 'B',
WK = 'K',
WQ = 'Q',
EMPTY = '\0'
};
#define __ EMPTY
static const UInt8 startingBoard[64] = {
BR, BN, BB, BQ, BK, BB, BN, BR,
BP, BP, BP, BP, BP, BP, BP, BP,
__, __, __, __, __, __, __, __,
__, __, __, __, __, __, __, __,
__, __, __, __, __, __, __, __,
__, __, __, __, __, __, __, __,
WP, WP, WP, WP, WP, WP, WP, WP,
WR, WN, WB, WQ, WK, WB, WN, WR
};
#undef __
const int BoxSize = 150;
const int dirLeft = -1;
const int dirRight = 1;
const int dirUp = -8;
const int dirDown = 8;
const int dirUpLeft = dirUp+dirLeft;
const int dirUpRight = dirUp+dirRight;
const int dirDownLeft = dirDown+dirLeft;
const int dirDownRight = dirDown+dirRight;
const int directions[8] = {dirLeft, dirRight, dirUp, dirDown, dirUpLeft, dirUpRight, dirDownLeft, dirDownRight};
const int actualDirections[8][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}, {-1, -1}, {1, -1}, {-1, 1}, {1, 1}};
class boardState
{
public:
UInt8 board[64];
bool isWhitesTurn;
bool whiteCanCastleQueenSide;
bool whiteCanCastleKingSide;
bool blackCanCastleQueenSide;
bool blackCanCastleKingSide;
int enPassantPos;
int halfMoves;
int fullMoves;
boardState(void);
bool isEmpty(int pos);
bool isPawn(int pos);
bool isRook(int pos);
bool isKnight(int pos);
bool isBishop(int pos);
bool isQueen(int pos);
bool isKing(int pos);
bool isBlack(int pos);
bool isWhite(int pos);
bool isAttackable(int pos);
char* convertBoardToFen(void);
};
class chessGame
{
public:
boardState currentState;
static const int maxBackup = 300;
boardState backupInfo[maxBackup];
int farthestBackup = 0;
int currentBackup = 0;
chessGame(void);
void undo();
void redo();
void backupCurrentState(void);
static void forceMove(move forcedMove, boardState* state);
static std::vector<move> generatePseudoLegalMoves(boardState* state);
static bool isInCheck(boardState* state, bool isWhite);
static std::vector<move> generateLegalMoves(boardState* state);
bool attemptMove(move attemptThisMove);
};
int nodeTree(int depth, boardState state);
int nodeTest(int depth, boardState state);
void generateDistanceToEdge(void);