Skip to content

Commit 2295fb3

Browse files
committed
0.7.4: Adjust king safety evaluation and disable LMR in the root node.
1 parent b8ff377 commit 2295fb3

File tree

4 files changed

+142
-149
lines changed

4 files changed

+142
-149
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.9)
22
project(Topple)
33

44
set(CMAKE_CXX_STANDARD 17)
5-
set(TOPPLE_VERSION 0.7.3)
5+
set(TOPPLE_VERSION 0.7.4)
66

77
# Source files for different targets
88
set(SOURCE_FILES

eval.cpp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,28 @@
1515
/// Utility tables
1616
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1717

18+
U64 BB_KING_SQUARE[64] = {};
1819
U64 BB_KING_CIRCLE[64] = {};
20+
U64 BB_PAWN_SHIELD[64] = {};
1921

2022
void evaluator_t::eval_init() {
23+
for (uint8_t sq = 0; sq < 64; sq++) {
24+
BB_KING_SQUARE[sq] = single_bit(sq) | find_moves<KING>(WHITE, sq, 0);
25+
}
26+
2127
for (uint8_t sq = 0; sq < 64; sq++) {
2228
// King circle
23-
BB_KING_CIRCLE[sq] |= find_moves<KING>(WHITE, sq, 0);
24-
BB_KING_CIRCLE[sq] |= find_moves<KNIGHT>(WHITE, sq, 0);
29+
BB_KING_CIRCLE[sq] = BB_KING_SQUARE[sq];
30+
if(rank_index(sq) == 0) BB_KING_CIRCLE[sq] |= pawns::shift<D_N>(BB_KING_SQUARE[sq]);
31+
if(rank_index(sq) == 7) BB_KING_CIRCLE[sq] |= pawns::shift<D_S>(BB_KING_SQUARE[sq]);
32+
if(file_index(sq) == 0) BB_KING_CIRCLE[sq] |= pawns::shift<D_E>(BB_KING_SQUARE[sq]);
33+
if(rank_index(sq) == 7) BB_KING_CIRCLE[sq] |= pawns::shift<D_W>(BB_KING_SQUARE[sq]);
34+
35+
if(rank_index(sq) <= 1) {
36+
BB_PAWN_SHIELD[sq] = pawns::shift<D_N>(BB_KING_SQUARE[sq]);
37+
} else if(rank_index(sq) >= 6) {
38+
BB_PAWN_SHIELD[sq] = pawns::shift<D_S>(BB_KING_SQUARE[sq]);
39+
}
2540
}
2641
}
2742

@@ -214,8 +229,8 @@ void evaluator_t::eval_movement(const board_t &board, int &mg, int &eg) {
214229
int king_pos[2] = {bit_scan(board.bb_pieces[WHITE][KING]), bit_scan(board.bb_pieces[BLACK][KING])};
215230
U64 king_circle[2] = {BB_KING_CIRCLE[king_pos[WHITE]], BB_KING_CIRCLE[king_pos[BLACK]]};
216231

217-
int pawn_shield_w = std::min(3, pop_count(king_circle[WHITE] & board.bb_pieces[WHITE][PAWN]));
218-
int pawn_shield_b = std::min(3, pop_count(king_circle[BLACK] & board.bb_pieces[BLACK][PAWN]));
232+
int pawn_shield_w = std::min(3, pop_count(BB_PAWN_SHIELD[king_pos[WHITE]] & board.bb_pieces[WHITE][PAWN]));
233+
int pawn_shield_b = std::min(3, pop_count(BB_PAWN_SHIELD[king_pos[BLACK]] & board.bb_pieces[BLACK][PAWN]));
219234

220235
U64 open_files = pawns::open_files(board.bb_pieces[WHITE][PAWN], board.bb_pieces[BLACK][PAWN]);
221236
U64 half_open_files[2] = {

eval.h

Lines changed: 119 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ enum GamePhase {
1515
MG, EG
1616
};
1717

18-
// qlc: 0.058373 lqa: 0.0649299
18+
// qlc: 0.0582706 lqa: 0.0647049
1919
struct eval_params_t {
2020
/// Material
21-
int mat_exch_knight = 27;
22-
int mat_exch_bishop = 35;
23-
int mat_exch_rook = 52;
24-
int mat_exch_queen = 146;
25-
int mat_opp_bishop[3] = {54, 64, 74}; // [PAWN ADVANTAGE]
21+
int mat_exch_knight = 26;
22+
int mat_exch_bishop = 34;
23+
int mat_exch_rook = 48;
24+
int mat_exch_queen = 156;
25+
int mat_opp_bishop[3] = {53, 63, 71}; // [PAWN ADVANTAGE]
2626

2727
/// Piece-square tables
2828

@@ -33,170 +33,170 @@ struct eval_params_t {
3333
// A1, B1, C1, D1
3434
// Horizontal, Vertical and diagonal symmetry
3535
int n_pst_mg[16] = {
36-
418, 422, 435, 435,
37-
392, 424, 431, 439,
38-
399, 397, 412, 427,
39-
277, 386, 410, 399
36+
412, 420, 431, 431,
37+
392, 423, 427, 437,
38+
397, 392, 411, 423,
39+
278, 383, 407, 400,
4040
};
4141
int q_pst_mg[16] = {
42-
1313, 1311, 1308, 1306,
43-
1331, 1329, 1325, 1316,
44-
1312, 1305, 1330, 1335,
45-
1314, 1324, 1321, 1333,
42+
1308, 1309, 1307, 1304,
43+
1328, 1328, 1325, 1314,
44+
1317, 1306, 1328, 1333,
45+
1322, 1320, 1320, 1331,
4646
};
4747
int n_pst_eg[16] = {
48-
364, 371, 373, 378,
49-
362, 370, 372, 377,
50-
352, 367, 371, 366,
51-
305, 341, 350, 366,
48+
366, 374, 377, 381,
49+
362, 370, 375, 381,
50+
353, 368, 371, 370,
51+
299, 348, 352, 368,
5252
};
5353
int q_pst_eg[16] = {
54-
1260, 1283, 1274, 1290,
55-
1220, 1253, 1267, 1269,
56-
1221, 1247, 1235, 1236,
57-
1202, 1207, 1227, 1219,
54+
1254, 1282, 1280, 1300,
55+
1216, 1249, 1267, 1270,
56+
1221, 1250, 1237, 1235,
57+
1194, 1220, 1230, 1226,
5858
};
5959

6060
// PST for pawn, rook:
6161
// A8, B8, C8, D8, A7, B7, C7, D7, etc.
6262
// Only vertical symmetry
6363
int b_pst_mg[32] = {
64-
357, 372, 378, 334,
65-
381, 397, 399, 394,
66-
419, 443, 432, 448,
67-
441, 433, 432, 430,
68-
445, 425, 431, 445,
69-
440, 453, 451, 447,
70-
445, 447, 461, 432,
71-
427, 425, 428, 428,
64+
352, 362, 364, 337,
65+
381, 392, 391, 382,
66+
417, 436, 427, 441,
67+
433, 428, 425, 425,
68+
439, 421, 430, 441,
69+
438, 449, 448, 444,
70+
443, 443, 456, 428,
71+
426, 424, 426, 427,
7272
};
7373
int r_pst_mg[32] = {
74-
584, 576, 605, 597,
75-
572, 566, 588, 616,
76-
588, 602, 595, 603,
77-
568, 578, 588, 588,
78-
563, 551, 578, 575,
79-
567, 575, 592, 579,
80-
574, 567, 576, 572,
81-
582, 588, 586, 589,
74+
594, 585, 608, 608,
75+
573, 566, 587, 615,
76+
583, 593, 592, 596,
77+
568, 579, 585, 587,
78+
563, 552, 578, 577,
79+
567, 576, 590, 578,
80+
575, 573, 577, 574,
81+
581, 586, 585, 590,
8282
};
8383
int b_pst_eg[32] = {
84-
389, 387, 384, 395,
85-
373, 378, 377, 377,
86-
369, 368, 368, 357,
87-
365, 373, 364, 374,
88-
372, 372, 378, 372,
89-
387, 384, 378, 380,
90-
372, 366, 368, 373,
91-
378, 374, 360, 368,
84+
389, 388, 384, 390,
85+
374, 379, 378, 377,
86+
369, 368, 367, 357,
87+
366, 372, 364, 376,
88+
372, 373, 377, 370,
89+
386, 385, 378, 376,
90+
372, 368, 370, 374,
91+
379, 376, 363, 370,
9292
};
9393
int r_pst_eg[32] = {
94-
679, 685, 680, 682,
95-
670, 682, 678, 663,
96-
668, 665, 672, 658,
97-
670, 670, 670, 665,
98-
675, 677, 667, 669,
99-
670, 667, 664, 666,
100-
674, 670, 674, 673,
101-
676, 673, 674, 666,
94+
681, 690, 683, 687,
95+
672, 685, 682, 666,
96+
669, 669, 675, 661,
97+
673, 671, 673, 668,
98+
678, 680, 668, 671,
99+
673, 669, 667, 668,
100+
676, 672, 677, 673,
101+
679, 678, 678, 669,
102102
};
103103
// Pawns have first and eighth rank excluded
104104
int p_pst_mg[24] = {
105-
207, 153, 159, 123,
106-
145, 157, 148, 145,
107-
122, 113, 105, 107,
108-
109, 102, 102, 116,
109-
95, 85, 99, 90,
110-
95, 98, 99, 91,
105+
207, 155, 148, 116,
106+
139, 152, 142, 137,
107+
121, 111, 102, 105,
108+
107, 102, 102, 114,
109+
95, 85, 96, 89,
110+
95, 97, 101, 88,
111111
};
112112
int p_pst_eg[24] = {
113-
181, 201, 201, 178,
114-
116, 135, 127, 106,
115-
102, 110, 111, 98,
116-
97, 101, 99, 90,
117-
95, 96, 91, 87,
118-
93, 92, 88, 80,
113+
181, 202, 203, 183,
114+
116, 131, 127, 107,
115+
102, 109, 110, 99,
116+
98, 101, 100, 90,
117+
95, 96, 92, 87,
118+
94, 92, 89, 81,
119119
};
120120

121121
// PST for king
122122
// Horizontal, Vertical and diagonal symmetry, like N and Q
123123
int k_pst_mg[16] = {
124-
-135, -99, -73, -93,
125-
-66, -56, -69, -87,
126-
30, -2, -43, -67,
127-
50, 48, 17, -21
124+
-120, -79, -57, -82,
125+
-26, -1, -24, -47,
126+
28, -11, -58, -83,
127+
53, 44, 24, -10,
128128
};
129129
int k_pst_eg[16] = {
130-
8, 25, 24, 26,
131-
5, 16, 16, 21,
132-
-20, 3, 18, 24,
133-
-50, -24, -3, 4,
130+
13, 28, 25, 26,
131+
7, 15, 16, 18,
132+
-20, 2, 15, 21,
133+
-48, -24, -2, 4,
134134
};
135135

136136
/// Pawn structure
137137

138138
// Pawn structure: doubled, isolated, backwards, chain, protected, etc.
139-
int isolated_mg[2] = {-5, -19}; // [OPEN FILE]
140-
int isolated_eg[2] = {-1, 0}; // [OPEN FILE]
141-
int backwards_mg[2] = {3, -17}; // [OPEN FILE]
142-
int backwards_eg[2] = {-6, -14}; // [OPEN FILE]
143-
int semi_backwards_mg[2] = {4, -18}; // [OPEN FILE]
144-
int semi_backwards_eg[2] = {2, 0}; // [OPEN FILE]
145-
int paired_mg[2] = {10, -1}; // [OPEN FILE]
146-
int paired_eg[2] = {2, 7}; // [OPEN FILE]
147-
int detached_mg[2] = {-3, -1}; // [OPEN FILE]
148-
int detached_eg[2] = {-8, -6}; // [OPEN FILE]
149-
int doubled_mg[2] = {-16, 5}; // [OPEN FILE]
150-
int doubled_eg[2] = {-19, -30}; // [OPEN FILE]
151-
int chain_mg[5] = {20, 13, 21, 40, 225}; // [RANK - 2]
152-
int chain_eg[5] = {14, 6, 9, 24, -22}; // [RANK - 2]
153-
int passed_mg[6] = {-30, -37, -24, 8, 10, 26}; // [RANK - 1]
154-
int passed_eg[6] = {-39, -16, 21, 60, 116, 123}; // [RANK - 1]
155-
int candidate_mg[4] = {-24, -4, 13, 63}; // [RANK - 1]
156-
int candidate_eg[4] = {-5, -1, 14, 46}; // [RANK - 1]
157-
int king_tropism_eg[2] = {0, 5}; // [OWN, OTHER]
139+
int isolated_mg[2] = {-4, -19}; // [OPEN FILE]
140+
int isolated_eg[2] = {-1, 1}; // [OPEN FILE]
141+
int backwards_mg[2] = {2, -16}; // [OPEN FILE]
142+
int backwards_eg[2] = {-6, -12}; // [OPEN FILE]
143+
int semi_backwards_mg[2] = {3, -20}; // [OPEN FILE]
144+
int semi_backwards_eg[2] = {2, 2}; // [OPEN FILE]
145+
int paired_mg[2] = {9, -2}; // [OPEN FILE]
146+
int paired_eg[2] = {3, 8}; // [OPEN FILE]
147+
int detached_mg[2] = {-4, -1}; // [OPEN FILE]
148+
int detached_eg[2] = {-7, -8}; // [OPEN FILE]
149+
int doubled_mg[2] = {-17, 4}; // [OPEN FILE]
150+
int doubled_eg[2] = {-18, -29}; // [OPEN FILE]
151+
int chain_mg[5] = {17, 11, 20, 35, 207}; // [RANK - 2]
152+
int chain_eg[5] = {14, 7, 10, 27, -13}; // [RANK - 2]
153+
int passed_mg[6] = {-24, -34, -22, 7, 11, 22}; // [RANK - 1]
154+
int passed_eg[6] = {-39, -14, 23, 60, 117, 120}; // [RANK - 1]
155+
int candidate_mg[4] = {-20, -5, 15, 61}; // [RANK - 1]
156+
int candidate_eg[4] = {-5, 0, 13, 48}; // [RANK - 1]
157+
int king_tropism_eg[2] = {-1, 5}; // [OWN, OTHER]
158158
int passer_tropism_eg[2] = {-7, 15}; // [OWN, OTHER]
159159

160160
// Evaluation of pawn structure relative to other pieces
161161
int blocked_mg[2] = {-7, -5}; // [OWN, OTHER]
162162
int blocked_eg[2] = {-4, -34}; // [OWN, OTHER]
163-
int pos_r_open_file_mg = 52;
164-
int pos_r_open_file_eg = 12;
165-
int pos_r_own_half_open_file_mg = 29; // "own" refers to side with missing pawn
163+
int pos_r_open_file_mg = 48;
164+
int pos_r_open_file_eg = 13;
165+
int pos_r_own_half_open_file_mg = 26; // "own" refers to side with missing pawn
166166
int pos_r_own_half_open_file_eg = -3;
167-
int pos_r_other_half_open_file_mg = 23;
167+
int pos_r_other_half_open_file_mg = 20;
168168
int pos_r_other_half_open_file_eg = 1;
169169

170170
// [KNIGHT, BISHOP]
171-
int outpost_mg[2] = {8, 12};
172-
int outpost_eg[2] = {12, 7};
173-
int outpost_hole_mg[2] = {41, 42};
174-
int outpost_hole_eg[2] = {12, -6};
175-
int outpost_half_mg[2] = {-2, 4};
171+
int outpost_mg[2] = {6, 9};
172+
int outpost_eg[2] = {12, 8};
173+
int outpost_hole_mg[2] = {41, 43};
174+
int outpost_hole_eg[2] = {13, -3};
175+
int outpost_half_mg[2] = {-3, 4};
176176
int outpost_half_eg[2] = {-7, 1};
177177

178178
/// King safety
179-
int ks_pawn_shield[4] = {-15, -1, 15, 26}; // 0, 1, 2, and 3 pawns close to the king
180-
181-
int kat_zero = 5;
182-
int kat_open_file = 28;
183-
int kat_own_half_open_file = 22;
184-
int kat_other_half_open_file = 10;
185-
int kat_attack_weight[5] = {3, 16, 8, 8, 12};
186-
int kat_defence_weight[5] = {13, 3, 4, 4, 1};
187-
188-
int kat_table_scale = 26;
189-
int kat_table_translate = 76;
190-
int kat_table_max = 429;
179+
int ks_pawn_shield[4] = {-20, -5, 14, 35}; // 0, 1, 2, and 3 pawns close to the king
180+
181+
int kat_zero = 6;
182+
int kat_open_file = 23;
183+
int kat_own_half_open_file = 19;
184+
int kat_other_half_open_file = 14;
185+
int kat_attack_weight[5] = {8, 15, 11, 9, 11};
186+
int kat_defence_weight[5] = {10, 3, 3, 3, 1};
187+
188+
int kat_table_scale = 23;
189+
int kat_table_translate = 77;
190+
int kat_table_max = 441;
191191
int kat_table_offset = 10;
192192

193193
/// Other positional
194-
int pos_bishop_pair_mg = 27;
195-
int pos_bishop_pair_eg = 67;
194+
int pos_bishop_pair_mg = 25;
195+
int pos_bishop_pair_eg = 69;
196196

197-
int pos_r_trapped_mg = -76;
198-
int pos_r_behind_own_passer_eg = 0;
199-
int pos_r_behind_enemy_passer_eg = 61;
197+
int pos_r_trapped_mg = -73;
198+
int pos_r_behind_own_passer_eg = -2;
199+
int pos_r_behind_enemy_passer_eg = 58;
200200
int pos_r_xray_pawn_eg = 17;
201201

202202
int pos_mob_mg[4] = {6, 7, 3, 2}; // [PIECE, ¬KING, ¬PAWN]

pvs.cpp

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -71,31 +71,9 @@ namespace pvs {
7171
bool move_is_check = board->gives_check(move);
7272
int ex = move_is_check;
7373

74-
// Singular extension
75-
if (depth >= 8 && move == tt_move
76-
&& (h_bound == tt::LOWER || h_bound == tt::EXACT)
77-
&& h.depth() >= depth - 2) {
78-
int reduced_beta = (h.value(0)) - depth;
79-
score = search_zw(reduced_beta - 1, reduced_beta, 0, depth / 2,
80-
true, move, true, aborted);
81-
if (aborted) return TIMEOUT;
82-
83-
if (score < reduced_beta) {
84-
ex = 1;
85-
}
86-
}
87-
88-
int reduction = 0;
89-
// Late move reductions
90-
if (n_legal > 1 && !move_is_check && stage == GEN_QUIETS) {
91-
if (depth >= 3) {
92-
// LMR
93-
reduction = depth / 8 + n_legal / 8 - 1;
94-
if (reduction >= 1 && board->see(reverse(move)) < 0) reduction -= 2;
95-
}
96-
}
97-
98-
move_list.emplace_back(move, n_legal, depth - reduction - 1 + ex, depth - 1 + ex);
74+
// PV extension
75+
if (n_legal == 1) ex = 1;
76+
move_list.emplace_back(move, n_legal, depth - 1 + ex, depth - 1 + ex);
9977
}
10078
}
10179
// Keep searching until we prove that all other moves are bad.

0 commit comments

Comments
 (0)