Skip to content

Commit 38ec0b3

Browse files
committed
Optimised square mirroring and reverted move ordering behaviour
1 parent 5b8f713 commit 38ec0b3

File tree

4 files changed

+17
-18
lines changed

4 files changed

+17
-18
lines changed

board.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ void board_t::mirror() {
562562
// Mirror en-passant
563563
if (record.back().ep_square != 0) {
564564
record.back().hash ^= zobrist::ep[record.back().ep_square];
565-
record.back().ep_square = MIRROR_TABLE[record.back().ep_square];
565+
record.back().ep_square = rel_sq(BLACK, record.back().ep_square);
566566
record.back().hash ^= zobrist::ep[record.back().ep_square];
567567
}
568568

@@ -585,7 +585,7 @@ void board_t::mirror() {
585585
if(old_data[sq].occupied()) switch_piece<true>(old_data[sq].team(), old_data[sq].piece(), sq);
586586
}
587587
for (uint8_t sq = 0; sq < 64; sq++) {
588-
if(old_data[sq].occupied()) switch_piece<true>(Team(!old_data[sq].team()), old_data[sq].piece(), MIRROR_TABLE[sq]);
588+
if(old_data[sq].occupied()) switch_piece<true>(Team(!old_data[sq].team()), old_data[sq].piece(), rel_sq(BLACK, sq));
589589
}
590590
}
591591

eval.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ processed_params_t::processed_params_t(const eval_params_t &params)
8181
// Mirror PST for black
8282
for (int piece = 0; piece < 6; piece++) {
8383
for (int square = 0; square < 64; square++) {
84-
pst[BLACK][piece][MIRROR_TABLE[square]] = pst[WHITE][piece][square];
84+
pst[BLACK][piece][rel_sq(BLACK, square)] = pst[WHITE][piece][square];
8585
}
8686
}
8787

movesort.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,18 @@ movesort_t::movesort_t(GenMode mode, const heuristic_set_t &heuristics, const b
1010
killer_1 = heur.killers.primary(ply);
1111
killer_2 = heur.killers.secondary(ply);
1212
killer_3 = ply > 2 ? heur.killers.primary(ply - 2) : EMPTY_MOVE;
13+
14+
if(killer_1 == hash_move) {
15+
killer_1 = EMPTY_MOVE;
16+
}
17+
18+
if(killer_2 == killer_1 || killer_2 == hash_move) {
19+
killer_2 = EMPTY_MOVE;
20+
}
21+
22+
if(killer_3 == killer_2 || killer_3 == killer_1 || killer_3 == hash_move) {
23+
killer_3 = EMPTY_MOVE;
24+
}
1325
}
1426

1527
// Pray that the compiler optimises tail recursion here - this is a very hot method
@@ -61,9 +73,7 @@ move_t movesort_t::next(GenStage &stage, int &score, bool skip_quiets) {
6173

6274
// Score quiets
6375
for (int i = 0; i < main_buf_size; i++) {
64-
if (main_buf[i] == hash_move) {
65-
main_scores[i] = -1000000000;
66-
} else if (main_buf[i] == killer_1) {
76+
if (main_buf[i] == killer_1) {
6777
main_scores[i] = 1000000003;
6878
} else if (main_buf[i] == killer_2) {
6979
main_scores[i] = 1000000002;

types.h

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,6 @@ enum Square {
6363
A8, B8, C8, D8, E8, F8, G8, H8,
6464
};
6565

66-
constexpr uint8_t MIRROR_TABLE[64] = {
67-
56, 57, 58, 59, 60, 61, 62, 63,
68-
48, 49, 50, 51, 52, 53, 54, 55,
69-
40, 41, 42, 43, 44, 45, 46, 47,
70-
32, 33, 34, 35, 36, 37, 38, 39,
71-
24, 25, 26, 27, 28, 29, 30, 31,
72-
16, 17, 18, 19, 20, 21, 22, 23,
73-
8, 9, 10, 11, 12, 13, 14, 15,
74-
0, 1, 2, 3, 4, 5, 6, 7
75-
};
76-
7766
enum Direction {
7867
D_SW = -9, D_S = -8, D_SE = -7, D_W = -1, D_X = 0, D_E = 1, D_NW = 7, D_N = 8, D_NE = 9
7968
};
@@ -83,7 +72,7 @@ constexpr Direction rel_offset(Team side, Direction dir) {
8372
}
8473

8574
constexpr uint8_t rel_sq(Team side, uint8_t square) {
86-
return side ? MIRROR_TABLE[square] : square;
75+
return side ? square ^ 56 : square;
8776
}
8877

8978
constexpr uint8_t rel_rank(Team side, uint8_t rank) {

0 commit comments

Comments
 (0)