1
+ #include < catch2/catch_test_macros.hpp>
2
+
3
+ #include " CLI.h"
4
+ #include " TranspositionTable.h"
5
+ #include " catch2/internal/catch_windows_h_proxy.hpp"
6
+
7
+ #define MATE_SCORE 32768 // 1 << 15
8
+
9
+ auto tt = TranspositionTable();
10
+
11
+ TEST_CASE (" TT - rw" , " [TranspositionTests]" ) {
12
+ ChessBoard board;
13
+ board.setPosition (" 8/RP1qb1B1/2p2P2/6n1/P7/p3k3/Q3b1BK/6R1 w - - 0 1" );
14
+ tt.setEntry (board, Interface::CLI::parseMove (" f6e7" , board), 1 , 1 , TranspositionTable::EXACT, 1 );
15
+ auto readEntry = tt.getEntry (board.hashCode , 1 );
16
+ CHECK (readEntry.bestMove == Interface::CLI::parseMove (" f6e7" , board));
17
+ CHECK (readEntry.depth == 1 );
18
+ CHECK (readEntry.score == 1 );
19
+ CHECK (readEntry.nodeType == TranspositionTable::EXACT);
20
+ }
21
+
22
+ TEST_CASE (" TT - overwrite" , " [TranspositionTests]" ) {
23
+ ChessBoard board;
24
+ board.setPosition (" 6k1/5bPp/8/n3p1PR/7Q/4P1b1/2r3Pp/2NK4 w - - 0 1" );
25
+
26
+ tt.setEntry (board, Interface::CLI::parseMove (" h4b4" , board), 2 , 1 , TranspositionTable::LOWERBOUND, 1 );
27
+ auto readEntry = tt.getEntry (board.hashCode , 1 );
28
+ CHECK (readEntry.score == 1 );
29
+
30
+ tt.setEntry (board, Interface::CLI::parseMove (" h4b4" , board), 1 , 2 , TranspositionTable::LOWERBOUND, 1 );
31
+ readEntry = tt.getEntry (board.hashCode , 1 );
32
+ CHECK (readEntry.score == 1 );
33
+
34
+ tt.setEntry (board, Interface::CLI::parseMove (" h4b4" , board), 3 , 3 , TranspositionTable::LOWERBOUND, 1 );
35
+ readEntry = tt.getEntry (board.hashCode , 1 );
36
+ CHECK (readEntry.score == 3 );
37
+
38
+ tt.setEntry (board, Interface::CLI::parseMove (" h4b4" , board), 2 , 4 , TranspositionTable::EXACT, 1 );
39
+ readEntry = tt.getEntry (board.hashCode , 1 );
40
+ CHECK (readEntry.score == 4 );
41
+ }
42
+
43
+ TEST_CASE (" TT - mate recall" , " [TranspositionTests]" ) {
44
+ ChessBoard board;
45
+ board.setPosition (" 1b6/2N1Pnk1/pp2Pr2/8/2P5/2qp1RN1/7K/5b2 w - - 0 1" );
46
+ // mate is 8 ply from root, 3 ply from current node
47
+ tt.setEntry (board, Interface::CLI::parseMove (" g3h5" , board), 1 , MATE_SCORE - 8 , TranspositionTable::EXACT, 5 );
48
+ // current node is 2 ply from root
49
+ auto readEntry = tt.getEntry (board.hashCode , 2 );
50
+ // thus mate is 5 ply from current root
51
+ CHECK (readEntry.score == MATE_SCORE - 5 );
52
+ }
0 commit comments