-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFigure.h
More file actions
190 lines (162 loc) · 5.65 KB
/
Copy pathFigure.h
File metadata and controls
190 lines (162 loc) · 5.65 KB
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
#ifndef CHESS_FIGURE_H
#define CHESS_FIGURE_H
#include <vector>
#include <map>
#include <iostream>
using namespace std;
static const int None = 0;
static const int King = 1;
static const int Pawn = 2;
static const int Knight = 3;
static const int Bishop = 5;
static const int Rook = 6;
static const int Queen = 7;
static const int Black = 8;
static const int White = 16;
static const int Type_Mask = 7;
static const int Colour_Mask = White | Black;
static const int WP_Start_Row = 1; // white pawn start row
static const int BP_Start_Row = 6;
static const vector<int> Direction_Offsets = {1, 8, -1, -8, 7, 9, -7, -9};
static const vector<int> Knight_Offsets = {6, -6, 10, -10, 15, -15, 17, -17};
static const vector<int> W_Pawn_Offsets = {8, 7, 9};
static const vector<int> B_Pawn_Offsets = {-8, -9, -7};
static const map<char, int> Char_To_Number = {
{ 'p', Black | Pawn },
{ 'P', White | Pawn },
{ 'r', Black | Rook },
{ 'R', White | Rook },
{ 'n', Black | Knight },
{ 'N', White | Knight },
{ 'b', Black | Bishop },
{ 'B', White | Bishop },
{ 'q', Black | Queen },
{ 'Q', White | Queen },
{ 'k', Black | King },
{ 'K', White | King },
};
static const map<int, char> Number_To_Char = {
{ Black | Pawn, 'p'},
{ White | Pawn, 'P' },
{ Black | Rook, 'r' },
{ White | Rook, 'R' },
{ Black | Knight, 'n' },
{ White | Knight, 'N' },
{ Black | Bishop, 'b' },
{ White | Bishop, 'B' },
{ Black | Queen, 'q' },
{ White | Queen, 'Q' },
{ Black | King, 'k' },
{ White | King, 'K' },
};
static const map<int, int> Values = {
{ Pawn, 100 },
{ Knight, 320 },
{ Bishop, 350},
{ Rook, 500 },
{ Queen, 900 },
{ King, 20000 }
};
inline static int Get_Colour(int figure){
return figure & Colour_Mask;
}
inline static int Get_Type(int figure){
return figure & Type_Mask;
}
inline static bool Is_White(int figure){
return figure & White;
}
inline static bool Is_Black(int figure){
return figure & Black;
}
inline static bool Is_Colour(int figure, int colour){
return Get_Colour(figure) & colour;
}
inline static bool Is_Sliding_Piece(int figure){
return (figure & 4);
}
inline static bool Is_Same_Colour(int figure1, int figure2){
return (Get_Colour(figure1) & figure2);
}
inline static bool Is_Opponent(int figure1, int figure2){
return (figure1 | figure2) > (Black | White);
}
// Give Points to the evaluation of a Position based on where the Figures are standing on the board.
static const int Pawn_Map[] = {
0, 0, 0, 0, 0, 0, 0, 0,
50, 50, 50, 50, 50, 50, 50, 50,
10, 10, 20, 30, 30, 20, 10, 10,
5, 5, 10, 25, 25, 10, 5, 5,
0, 0, 0, 26, 25, 0, 0, 0,
5, -5,-10, 0, 0,-10, -5, 5,
5, 10, 10,-25,-25, 10, 10, 5,
0, 0, 0, 0, 0, 0, 0, 0
};
static const int Knight_Map[] = {
-50,-40,-30,-30,-30,-30,-40,-50,
-40,-20, 0, 0, 0, 0,-20,-40,
-30, 0, 10, 15, 15, 10, 0,-30,
-30, 5, 15, 20, 20, 15, 5,-30,
-30, 0, 15, 20, 20, 15, 0,-30,
-30, 5, 10, 15, 15, 10, 5,-30,
-40,-20, 0, 5, 5, 0,-20,-40,
-50,-40,-30,-30,-30,-30,-40,-50,
};
static const int Bishop_Map[] = {
-20,-10,-10,-10,-10,-10,-10,-20,
-10, 0, 0, 0, 0, 0, 0,-10,
-10, 0, 5, 10, 10, 5, 0,-10,
-10, 5, 5, 10, 10, 5, 5,-10,
-10, 0, 10, 10, 10, 10, 0,-10,
-10, 10, 10, 10, 10, 10, 10,-10,
-10, 5, 0, 0, 0, 0, 5,-10,
-20,-10,-10,-10,-10,-10,-10,-20,
};
static const int Rook_Map[] = {
0, 0, 0, 0, 0, 0, 0, 0,
5, 10, 10, 10, 10, 10, 10, 5,
-5, 0, 0, 0, 0, 0, 0, -5,
-5, 0, 0, 0, 0, 0, 0, -5,
-5, 0, 0, 0, 0, 0, 0, -5,
-5, 0, 0, 0, 0, 0, 0, -5,
-5, 0, 0, 0, 0, 0, 0, -5,
0, 0, 0, 5, 5, 0, 0, 0,
};
static const int Queen_Map[] = {
-20,-10,-10, -5, -5,-10,-10,-20,
-10, 0, 0, 0, 0, 0, 0,-10,
-10, 0, 5, 5, 5, 5, 0,-10,
-5, 0, 5, 5, 5, 5, 0, -5,
0, 0, 5, 5, 5, 5, 0, -5,
-10, 5, 5, 5, 5, 5, 0,-10,
-10, 0, 5, 0, 0, 0, 0,-10,
-20,-10,-10, -5, -5,-10,-10,-20
};
static const int King_Map[] = {
-30,-40,-40,-50,-50,-40,-40,-30,
-30,-40,-40,-50,-50,-40,-40,-30,
-30,-40,-40,-50,-50,-40,-40,-30,
-30,-40,-40,-50,-50,-40,-40,-30,
-20,-30,-30,-40,-40,-30,-30,-20,
-10,-20,-20,-20,-20,-20,-20,-10,
20, 20, 0, 0, 0, 0, 20, 20,
20, 30, 10, 0, 0, 10, 30, 20
};
inline static int Get_Figure_Value(int figure, int index){
//if (Is_White(figure)) return Values.at(Get_Type(figure));
//else return -Values.at(Get_Type(figure));
int type = Get_Type(figure);
int value;
//cout << "index: " << index;
if (Is_White(figure)) index = 63 - index;
if (type == Pawn) value = 100 + Pawn_Map[index];
else if (type == Knight) value = 320 + Knight_Map[index];
else if (type == Bishop) value = 350 + Bishop_Map[index];
else if (type == Rook) value = 500 + Rook_Map[index];
else if (type == Queen) value = 900 + Queen_Map[index];
else if (type == King) value = 20000 + King_Map[index];
//cout << " value: " << value << endl;
if (Is_White(figure)) return value;
else return -value;
}
#endif //CHESS_FIGURE_H