Skip to content

Commit 564553a

Browse files
slight randomness
1 parent fda816e commit 564553a

File tree

4 files changed

+168
-160
lines changed

4 files changed

+168
-160
lines changed

src/EvaluationValues.h

+155-156
Original file line numberDiff line numberDiff line change
@@ -4,162 +4,161 @@
44
#include <array>
55

66
namespace EvaluationValues {
7-
8-
const std::array<int, 6> mg_value = {82, 337, 365, 477, 1025, 0};
9-
const std::array<int, 6> eg_value = {94, 281, 297, 512, 936, 0};
10-
const std::array<int, 6> gamephaseInc = {0, 1, 1, 2, 4, 0};
11-
12-
constexpr std::array<int, 64> mg_pawn_table = {
13-
0, 0, 0, 0, 0, 0, 0, 0,
14-
98, 134, 61, 95, 68, 126, 34, -11,
15-
-6, 7, 26, 31, 65, 56, 25, -20,
16-
-14, 13, 6, 21, 23, 12, 17, -23,
17-
-27, -2, -5, 12, 17, 6, 10, -25,
18-
-26, -4, -4, -10, 3, 3, 33, -12,
19-
-35, -1, -20, -23, -15, 24, 38, -22,
20-
0, 0, 0, 0, 0, 0, 0, 0,
21-
};
22-
23-
constexpr std::array<int, 64> eg_pawn_table = {
24-
0, 0, 0, 0, 0, 0, 0, 0,
25-
178, 173, 158, 134, 147, 132, 165, 187,
26-
94, 100, 85, 67, 56, 53, 82, 84,
27-
32, 24, 13, 5, -2, 4, 17, 17,
28-
13, 9, -3, -7, -7, -8, 3, -1,
29-
4, 7, -6, 1, 0, -5, -1, -8,
30-
13, 8, 8, 10, 13, 0, 2, -7,
31-
0, 0, 0, 0, 0, 0, 0, 0,
32-
};
33-
34-
constexpr std::array<int, 64> mg_knight_table = {
35-
-167, -89, -34, -49, 61, -97, -15, -107,
36-
-73, -41, 72, 36, 23, 62, 7, -17,
37-
-47, 60, 37, 65, 84, 129, 73, 44,
38-
-9, 17, 19, 53, 37, 69, 18, 22,
39-
-13, 4, 16, 13, 28, 19, 21, -8,
40-
-23, -9, 12, 10, 19, 17, 25, -16,
41-
-29, -53, -12, -3, -1, 18, -14, -19,
42-
-105, -21, -58, -33, -17, -28, -19, -23,
43-
};
44-
45-
constexpr std::array<int, 64> eg_knight_table = {
46-
-58, -38, -13, -28, -31, -27, -63, -99,
47-
-25, -8, -25, -2, -9, -25, -24, -52,
48-
-24, -20, 10, 9, -1, -9, -19, -41,
49-
-17, 3, 22, 22, 22, 11, 8, -18,
50-
-18, -6, 16, 25, 16, 17, 4, -18,
51-
-23, -3, -1, 15, 10, -3, -20, -22,
52-
-42, -20, -10, -5, -2, -20, -23, -44,
53-
-29, -51, -23, -15, -22, -18, -50, -64,
54-
};
55-
56-
constexpr std::array<int, 64> mg_bishop_table = {
57-
-29, 4, -82, -37, -25, -42, 7, -8,
58-
-26, 16, -18, -13, 30, 59, 18, -47,
59-
-16, 37, 43, 40, 35, 50, 37, -2,
60-
-4, 5, 19, 50, 37, 37, 7, -2,
61-
-6, 13, 13, 26, 34, 12, 10, 4,
62-
0, 15, 15, 15, 14, 27, 18, 10,
63-
4, 15, 16, 0, 7, 21, 33, 1,
64-
-33, -3, -14, -21, -13, -12, -39, -21,
65-
};
66-
67-
constexpr std::array<int, 64> eg_bishop_table = {
68-
-14, -21, -11, -8, -7, -9, -17, -24,
69-
-8, -4, 7, -12, -3, -13, -4, -14,
70-
2, -8, 0, -1, -2, 6, 0, 4,
71-
-3, 9, 12, 9, 14, 10, 3, 2,
72-
-6, 3, 13, 19, 7, 10, -3, -9,
73-
-12, -3, 8, 10, 13, 3, -7, -15,
74-
-14, -18, -7, -1, 4, -9, -15, -27,
75-
-23, -9, -23, -5, -9, -16, -5, -17,
76-
};
77-
78-
constexpr std::array<int, 64> mg_rook_table = {
79-
32, 42, 32, 51, 63, 9, 31, 43,
80-
27, 32, 58, 62, 80, 67, 26, 44,
81-
-5, 19, 26, 36, 17, 45, 61, 16,
82-
-24, -11, 7, 26, 24, 35, -8, -20,
83-
-36, -26, -12, -1, 9, -7, 6, -23,
84-
-45, -25, -16, -17, 3, 0, -5, -33,
85-
-44, -16, -20, -9, -1, 11, -6, -71,
86-
-19, -13, 1, 17, 16, 7, -37, -26,
87-
};
88-
89-
constexpr std::array<int, 64> eg_rook_table = {
90-
13, 10, 18, 15, 12, 12, 8, 5,
91-
11, 13, 13, 11, -3, 3, 8, 3,
92-
7, 7, 7, 5, 4, -3, -5, -3,
93-
4, 3, 13, 1, 2, 1, -1, 2,
94-
3, 5, 8, 4, -5, -6, -8, -11,
95-
-4, 0, -5, -1, -7, -12, -8, -16,
96-
-6, -6, 0, 2, -9, -9, -11, -3,
97-
-9, 2, 3, -1, -5, -13, 4, -20,
98-
};
99-
100-
constexpr std::array<int, 64> mg_queen_table = {
101-
-28, 0, 29, 12, 59, 44, 43, 45,
102-
-24, -39, -5, 1, -16, 57, 28, 54,
103-
-13, -17, 7, 8, 29, 56, 47, 57,
104-
-27, -27, -16, -16, -1, 17, -2, 1,
105-
-9, -26, -9, -10, -2, -4, 3, -3,
106-
-14, 2, -11, -2, -5, 2, 14, 5,
107-
-35, -8, 11, 2, 8, 15, -3, 1,
108-
-1, -18, -9, 10, -15, -25, -31, -50,
109-
};
110-
111-
constexpr std::array<int, 64> eg_queen_table = {
112-
-9, 22, 22, 27, 27, 19, 10, 20,
113-
-17, 20, 32, 41, 58, 25, 30, 0,
114-
-20, 6, 9, 49, 47, 35, 19, 9,
115-
3, 22, 24, 45, 57, 40, 57, 36,
116-
-18, 28, 19, 47, 31, 34, 39, 23,
117-
-16, -27, 15, 6, 9, 17, 10, 5,
118-
-22, -23, -30, -16, -16, -23, -36, -32,
119-
-33, -28, -22, -43, -5, -32, -20, -41,
120-
};
121-
122-
constexpr std::array<int, 64> mg_king_table = {
123-
-65, 23, 16, -15, -56, -34, 2, 13,
124-
29, -1, -20, -7, -8, -4, -38, -29,
125-
-9, 24, 2, -16, -20, 6, 22, -22,
126-
-17, -20, -12, -27, -30, -25, -14, -36,
127-
-49, -1, -27, -39, -46, -44, -33, -51,
128-
-14, -14, -22, -46, -44, -30, -15, -27,
129-
1, 7, -8, -64, -43, -16, 9, 8,
130-
-15, 36, 12, -54, 8, -28, 24, 14,
131-
};
132-
133-
constexpr std::array<int, 64> eg_king_table = {
134-
-74, -35, -18, -18, -11, 15, 4, -17,
135-
-12, 17, 14, 17, 17, 38, 23, 11,
136-
10, 17, 23, 15, 20, 45, 44, 13,
137-
-8, 22, 24, 27, 26, 33, 26, 3,
138-
-18, -4, 21, 24, 27, 23, 9, -11,
139-
-19, -3, 11, 21, 23, 16, 7, -9,
140-
-27, -11, 4, 13, 14, 4, -5, -17,
141-
-53, -34, -21, -11, -28, -14, -24, -43
142-
};
143-
144-
const std::array<std::array<int, 64>, 6> mg_pesto_table =
145-
{
146-
mg_pawn_table,
147-
mg_knight_table,
148-
mg_bishop_table,
149-
mg_rook_table,
150-
mg_queen_table,
151-
mg_king_table
152-
};
153-
154-
const std::array<std::array<int, 64>, 6> eg_pesto_table =
155-
{
156-
eg_pawn_table,
157-
eg_knight_table,
158-
eg_bishop_table,
159-
eg_rook_table,
160-
eg_queen_table,
161-
eg_king_table
162-
};
7+
const std::array<int, 6> mg_value = {820, 3370, 3650, 4770, 10250, 0};
8+
const std::array<int, 6> eg_value = {940, 2810, 2970, 5120, 9360, 0};
9+
const std::array<int, 6> gamephaseInc = {0, 10, 10, 20, 40, 0};
10+
11+
constexpr std::array<int, 64> mg_pawn_table = {
12+
0, 0, 0, 0, 0, 0, 0, 0,
13+
980, 1340, 610, 950, 680, 1260, 340, -110,
14+
-60, 70, 260, 310, 650, 560, 250, -200,
15+
-140, 130, 60, 210, 230, 120, 170, -230,
16+
-270, -20, -50, 120, 170, 60, 100, -250,
17+
-260, -40, -40, -100, 30, 30, 330, -120,
18+
-350, -10, -200, -230, -150, 240, 380, -220,
19+
0, 0, 0, 0, 0, 0, 0, 0,
20+
};
21+
22+
constexpr std::array<int, 64> eg_pawn_table = {
23+
0, 0, 0, 0, 0, 0, 0, 0,
24+
1780, 1730, 1580, 1340, 1470, 1320, 1650, 1870,
25+
940, 1000, 850, 670, 560, 530, 820, 840,
26+
320, 240, 130, 50, -20, 40, 170, 170,
27+
130, 90, -30, -70, -70, -80, 30, -10,
28+
40, 70, -60, 10, 0, -50, -10, -80,
29+
130, 80, 80, 100, 130, 0, 20, -70,
30+
0, 0, 0, 0, 0, 0, 0, 0,
31+
};
32+
33+
constexpr std::array<int, 64> mg_knight_table = {
34+
-1670, -890, -340, -490, 610, -970, -150, -1070,
35+
-730, -410, 720, 360, 230, 620, 70, -170,
36+
-470, 600, 370, 650, 840, 1290, 730, 440,
37+
-90, 170, 190, 530, 370, 690, 180, 220,
38+
-130, 40, 160, 130, 280, 190, 210, -80,
39+
-230, -90, 120, 100, 190, 170, 250, -160,
40+
-290, -530, -120, -30, -10, 180, -140, -190,
41+
-1050, -210, -580, -330, -170, -280, -190, -230,
42+
};
43+
44+
constexpr std::array<int, 64> eg_knight_table = {
45+
-580, -380, -130, -280, -310, -270, -630, -990,
46+
-250, -80, -250, -20, -90, -250, -240, -520,
47+
-240, -200, 100, 90, -10, -90, -190, -410,
48+
-170, 30, 220, 220, 220, 110, 80, -180,
49+
-180, -60, 160, 250, 160, 170, 40, -180,
50+
-230, -30, -10, 150, 100, -30, -200, -220,
51+
-420, -200, -100, -50, -20, -200, -230, -440,
52+
-290, -510, -230, -150, -220, -180, -500, -640,
53+
};
54+
55+
constexpr std::array<int, 64> mg_bishop_table = {
56+
-290, 40, -820, -370, -250, -420, 70, -80,
57+
-260, 160, -180, -130, 300, 590, 180, -470,
58+
-160, 370, 430, 400, 350, 500, 370, -20,
59+
-40, 50, 190, 500, 370, 370, 70, -20,
60+
-60, 130, 130, 260, 340, 120, 100, 40,
61+
0, 150, 150, 150, 140, 270, 180, 100,
62+
40, 150, 160, 0, 70, 210, 330, 10,
63+
-330, -30, -140, -210, -130, -120, -390, -210,
64+
};
65+
66+
constexpr std::array<int, 64> eg_bishop_table = {
67+
-140, -210, -110, -80, -70, -90, -170, -240,
68+
-80, -40, 70, -120, -30, -130, -40, -140,
69+
20, -80, 0, -10, -20, 60, 0, 40,
70+
-30, 90, 120, 90, 140, 100, 30, 20,
71+
-60, 30, 130, 190, 70, 100, -30, -90,
72+
-120, -30, 80, 100, 130, 30, -70, -150,
73+
-140, -180, -70, -10, 40, -90, -150, -270,
74+
-230, -90, -230, -50, -90, -160, -50, -170,
75+
};
76+
77+
constexpr std::array<int, 64> mg_rook_table = {
78+
320, 420, 320, 510, 630, 90, 310, 430,
79+
270, 320, 580, 620, 800, 670, 260, 440,
80+
-50, 190, 260, 360, 170, 450, 610, 160,
81+
-240, -110, 70, 260, 240, 350, -80, -200,
82+
-360, -260, -120, -10, 90, -70, 60, -230,
83+
-450, -250, -160, -170, 30, 0, -50, -330,
84+
-440, -160, -200, -90, -10, 110, -60, -710,
85+
-190, -130, 10, 170, 160, 70, -370, -260,
86+
};
87+
88+
constexpr std::array<int, 64> eg_rook_table = {
89+
130, 100, 180, 150, 120, 120, 80, 50,
90+
110, 130, 130, 110, -30, 30, 80, 30,
91+
70, 70, 70, 50, 40, -30, -50, -30,
92+
40, 30, 130, 10, 20, 10, -10, 20,
93+
30, 50, 80, 40, -50, -60, -80, -110,
94+
-40, 0, -50, -10, -70, -120, -80, -160,
95+
-60, -60, 0, 20, -90, -90, -110, -30,
96+
-90, 20, 30, -10, -50, -130, 40, -200,
97+
};
98+
99+
constexpr std::array<int, 64> mg_queen_table = {
100+
-280, 0, 290, 120, 590, 440, 430, 450,
101+
-240, -390, -50, 10, -160, 570, 280, 540,
102+
-130, -170, 70, 80, 290, 560, 470, 570,
103+
-270, -270, -160, -160, -10, 170, -20, 10,
104+
-90, -260, -90, -100, -20, -40, 30, -30,
105+
-140, 20, -110, -20, -50, 20, 140, 50,
106+
-350, -80, 110, 20, 80, 150, -30, 10,
107+
-10, -180, -90, 100, -150, -250, -310, -500,
108+
};
109+
110+
constexpr std::array<int, 64> eg_queen_table = {
111+
-90, 220, 220, 270, 270, 190, 100, 200,
112+
-170, 200, 320, 410, 580, 250, 300, 0,
113+
-200, 60, 90, 490, 470, 350, 190, 90,
114+
30, 220, 240, 450, 570, 400, 570, 360,
115+
-180, 280, 190, 470, 310, 340, 390, 230,
116+
-160, -270, 150, 60, 90, 170, 100, 50,
117+
-220, -230, -300, -160, -160, -230, -360, -320,
118+
-330, -280, -220, -430, -50, -320, -200, -410,
119+
};
120+
121+
constexpr std::array<int, 64> mg_king_table = {
122+
-650, 230, 160, -150, -560, -340, 20, 130,
123+
290, -10, -200, -70, -80, -40, -380, -290,
124+
-90, 240, 20, -160, -200, 60, 220, -220,
125+
-170, -200, -120, -270, -300, -250, -140, -360,
126+
-490, -10, -270, -390, -460, -440, -330, -510,
127+
-140, -140, -220, -460, -440, -300, -150, -270,
128+
10, 70, -80, -640, -430, -160, 90, 80,
129+
-150, 360, 120, -540, 80, -280, 240, 140,
130+
};
131+
132+
constexpr std::array<int, 64> eg_king_table = {
133+
-740, -350, -180, -180, -110, 150, 40, -170,
134+
-120, 170, 140, 170, 170, 380, 230, 110,
135+
100, 170, 230, 150, 200, 450, 440, 130,
136+
-80, 220, 240, 270, 260, 330, 260, 30,
137+
-180, -40, 210, 240, 270, 230, 90, -110,
138+
-190, -30, 110, 210, 230, 160, 70, -90,
139+
-270, -110, 40, 130, 140, 40, -50, -170,
140+
-530, -340, -210, -110, -280, -140, -240, -430
141+
};
142+
143+
const std::array<std::array<int, 64>, 6> mg_pesto_table =
144+
{
145+
mg_pawn_table,
146+
mg_knight_table,
147+
mg_bishop_table,
148+
mg_rook_table,
149+
mg_queen_table,
150+
mg_king_table
151+
};
152+
153+
const std::array<std::array<int, 64>, 6> eg_pesto_table =
154+
{
155+
eg_pawn_table,
156+
eg_knight_table,
157+
eg_bishop_table,
158+
eg_rook_table,
159+
eg_queen_table,
160+
eg_king_table
161+
};
163162
}
164163

165164
#endif //CHESSENGINE_EVALUATIONVALUES_H

src/Evaluator.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ int Evaluator::evaluate(const ChessBoard &board) {
3939
const int midGamePhase = (gamePhase > 24) ? 24 : gamePhase;
4040
const int endGamePhase = 24 - midGamePhase;
4141

42-
return (midGameScore * midGamePhase + endGameScore * endGamePhase) / 24;
42+
return ((midGameScore * midGamePhase + endGameScore * endGamePhase) / 24) + Util::randomOffset();
4343
}
4444

45-
int_fast8_t Evaluator::flipPosition(int_fast8_t pos) {
45+
int_fast8_t Evaluator::flipPosition(const int_fast8_t pos) {
4646
const int_fast8_t file = pos % 8;
4747
const int_fast8_t rank = pos / 8;
4848

src/Search.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ int Search::alphaBeta(const int depth, int alpha, int beta, const int ply) {
106106
//repetitions
107107
if (board.isDraw()) {
108108
logger.logToFile("draw, score: 0\n");
109-
return 0;
109+
return Util::randomOffset();
110110
}
111111

112112
alpha = std::max(alpha, -MATE_SCORE + ply);
@@ -190,7 +190,7 @@ int Search::quiesce(int alpha, int beta, const int ply, const int depth) {
190190
if (stop) return 0;
191191

192192
//repetitions
193-
if (board.isDraw()) return 0;
193+
if (board.isDraw()) return Util::randomOffset();
194194

195195
const int stand_pat = Evaluator::evaluate(board);
196196
if (stand_pat >= beta)

src/Util.h

+9
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include <array>
55
#include <algorithm>
6+
#include <random>
67
#include "Piece.h"
78

89
namespace Util {
@@ -88,5 +89,13 @@ namespace Util {
8889
const int_fast8_t rank = 8 - (position[1] - '0');
8990
return rank * 8 + file;
9091
}
92+
93+
inline std::random_device rd;
94+
inline std::mt19937 mt(rd());
95+
inline std::uniform_int_distribution<int> dist(-1, 1);
96+
97+
static int randomOffset() {
98+
return dist(mt);
99+
}
91100
}
92101
#endif //CHESSENGINE_UTIL_H

0 commit comments

Comments
 (0)