-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchessengine.h
117 lines (80 loc) · 3.43 KB
/
chessengine.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
#ifndef CHESSENGINE_H
#define CHESSENGINE_H
#include "includes.h"
#include "defines.h"
using namespace std;
namespace chess {
using piece_id = unsigned char;
using player = unsigned char;
template<typename key, typename value>
using umap = unordered_map<key, value>;
template<typename value>
using uset = unordered_set<value>;
inline static const unsigned char ML = 8; // "ML" stands for "MAX_LINE", it's going to be our board's size (8x8 squares)
struct coords {
char file;
int rank;
coords() : file(EMPTY), rank(EMPTY) {};
coords(char f, int r) : file(f), rank(r) {};
// coords(coords &c) : file(c.file), rank(c.rank) {};
bool operator==(const coords &c) {
return (file == c.file) && (rank == c.rank);
};
};
struct piece : public coords {
piece_id id;
piece() : id(EMPTY) {};
piece(chess::coords c, piece_id i) : coords(c), id(i) {};
// piece(piece &p) : id(p.id), coords(p.coords) {};
bool operator==(const piece &p) {
return id == p.id;
}
void move(chess::coords c) {
file = c.file;
rank = c.rank;
}
};
struct move : public piece {
coords movesTo; // coords of the square after moving the piece
move() : piece(), movesTo() {};
move(chess::piece p, coords m) : piece(p), movesTo(m) {};
// move(move &m) : piece(m.piece), movesTo(m.movesTo) {};
};
using board = struct square {
piece piece;
};
struct gameStatus {
//checkStruct check; // becomes true everytime a player is in check
player player = WHITE; // tells which player has to move. white always starts first
size_t turns = 0; // counts the turn, it's set to 0 before the game starts and increment every time white moves
vector<move> listOfMoves; // records a game moves
// uset<piece> trackPiecePositions; // TODO: keeps track of piece positions on the board
// umap<piece, vector<coords>> legalMoves; // TODO: keeps track of white legal moves // TODO: keeps track of black legal moves
board chessboard[ML][ML]; // cb = chessboard
bool hasAlreadyMoved[6] {false}; // ORDER: king e1, rook a1, rook h1, king e8, rook a8, rook h8. specific values become true after one of them moves
move lastMove;
};
// setting up
void startingPosition(gameStatus &) noexcept;
// printing
string printPieceOrEmpty(const board [ML][ML], const int, const int) noexcept ;
void printBoard(gameStatus &) noexcept;
//void printBoard();
string printPlayer(const unsigned char &) noexcept;
int ctoi(const char &) noexcept;
char itoc(const int &) noexcept;
string printPiece(piece_id) noexcept;
/* void printAllMoves(const vector<move> &);
void printPieceOrEmptysCoords(const vector<move> &);
bool updateLegalMoves();
coords movePiece(unordered_set<coords> &, move &); */
// game
void inputMove(gameStatus &) noexcept;
char gameStarts() noexcept;
// pieces logic
bool promotePawn(board [ML][ML], const unsigned char &, const move &) noexcept;
bool rookMove(gameStatus &, const move &) noexcept;
bool bishopMove(board [ML][ML], const move &) noexcept;
bool isMoveValid(gameStatus &, move) noexcept;
}
#endif // CHESSENGINE_H