-
Notifications
You must be signed in to change notification settings - Fork 1
/
Engine.h
84 lines (58 loc) · 2.42 KB
/
Engine.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
#pragma once
#include <unordered_set>
#include "Chessboard.h"
#include "Constants.h"
#define MOBILITY_SCORE 1
static const int16_t PIECE_SCORE[] =
{0, 100, 9, 5, 3, 3, 1, 0, 0, -100, -9, -5, -3, -3, -1, 0};
struct MeasuredBoard {
Chessboard board;
int16_t score; // your piece score - opponent piece score
MeasuredBoard() : board(0), score(0) {};
MeasuredBoard(const Chessboard b, const int16_t s) : board(b), score(s) {};
MeasuredBoard(const MeasuredBoard& other) {
board = other.board;
score = other.score;
}
MeasuredBoard& operator=(const MeasuredBoard other) {
board = other.board;
score = other.score;
return *this;
}
bool operator==(const MeasuredBoard other) const {
return board == other.board;
}
bool operator<(const MeasuredBoard other) const {
for (int i = BOARD_BIT_SIZE - 1; i >= 0; i--) {
if (board[i] ^ other.board[i])
return other.board[i];
}
return false;
}
};
namespace std {
template<> struct hash<MeasuredBoard> {
size_t operator()(const MeasuredBoard& b) const noexcept {
hash<Chessboard> hasher;
return hasher(b.board);
}
};
}
using namespace std;
class Engine {
public:
// Constructor
Engine();
virtual ~Engine();
Chessboard getBestMove(Chessboard board, bool color, int depth);
MeasuredBoard getInitialMeasure(Chessboard board) const; // make private later
MeasuredBoard getEngineScore(MeasuredBoard root, uint8_t depth, int16_t alpha, int16_t beta, bool player);
unordered_set<MeasuredBoard> getValidMoves(MeasuredBoard b, bool color);
unordered_set<MeasuredBoard> getMovesKnight(MeasuredBoard b, bool color, uint8_t x, uint8_t y);
unordered_set<MeasuredBoard> getMovesPawn(MeasuredBoard b, bool color, uint8_t x, uint8_t y);
unordered_set<MeasuredBoard> getMovesRook(MeasuredBoard b, bool color, uint8_t x, uint8_t y);
unordered_set<MeasuredBoard> getMovesBishop(MeasuredBoard b, bool color, uint8_t x, uint8_t y);
unordered_set<MeasuredBoard> getMovesQueen(MeasuredBoard b, bool color, uint8_t x, uint8_t y);
unordered_set<MeasuredBoard> getMovesKing(MeasuredBoard b, bool color, uint8_t x, uint8_t y);
private:
};