-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests.cpp
More file actions
132 lines (106 loc) · 3.84 KB
/
Copy pathtests.cpp
File metadata and controls
132 lines (106 loc) · 3.84 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
#include "iostream"
#include "boardstate.hpp"
#include "zobrist.hpp"
#include <unordered_set>
void printBoard(const boardstate& b){
std::cout << " ";
for(int col = 0; col < 19; ++col){
std::cout << (char)('A' + col) << " ";
}
std::cout << "\n";
for(int row = 0; row < 19; ++row){
std::cout << (row + 1 < 10 ? " " : "") << row + 1 << " ";
for(int col = 0; col < 19; ++col){
if(b.black.getStone(row, col)) std::cout << "X ";
else if(b.white.getStone(row, col)) std::cout << "O ";
else std::cout << ". ";
}
std::cout << "\n";
}
std::cout << "Black captures: " << b.blackCaptures << "\n";
std::cout << "White captures: " << b.whiteCaptures << "\n";
std::cout << "Hash: " << b.zobristHash << "\n";
std::cout << "\n" << std::endl;
}
void testCapture(){
std::cout << "=== TEST: Basic capture ===\n";
// surround a white stone at (0,1) and capture it
// black plays (0,0), (0,2), (1,1) — white plays (0,1)
boardstate b{};
std::unordered_set<uint64_t> history;
b.blackMove = true;
b = b.makeMove(0 * 19 + 0); // black (0,0)
history.insert(b.zobristHash);
b = b.makeMove(0 * 19 + 1); // white (0,1) ERROR IS HERE
history.insert(b.zobristHash);
b = b.makeMove(0 * 19 + 2); // black (0,2)
history.insert(b.zobristHash);
b = b.makeMove(1 * 19 + 0); // white somewhere safe
history.insert(b.zobristHash);
b = b.makeMove(1 * 19 + 1); // black (1,1) — captures white at (0,1)
history.insert(b.zobristHash);
printBoard(b);
std::cout << "Expected: white stone at (0,1) gone, blackCaptures = 1\n\n" << std::endl;
}
void testSuicide(){
std::cout << "=== TEST: Suicide is illegal ===\n";
// black surrounds (0,0) so white can't play there
boardstate b{};
std::unordered_set<uint64_t> history;
b.blackMove = true;
b = b.makeMove(0 * 19 + 1); // black (0,1)
history.insert(b.zobristHash);
b = b.makeMove(18 * 19 + 0); // white somewhere safe
history.insert(b.zobristHash);
b = b.makeMove(1 * 19 + 0); // black (1,0)
history.insert(b.zobristHash);
// now white playing (0,0) would be suicide
bool legal = b.isLegal(0 * 19 + 0, history);
std::cout << "White playing (0,0) legal: " << (legal ? "YES (wrong!)" : "NO (correct)") << "\n\n";
}
void testKo(){
std::cout << "=== TEST: Ko ===\n";
// classic ko position
// . X O .
// X . X O
// . X O .
boardstate b{};
std::unordered_set<uint64_t> history;
b.blackMove = true;
// set up ko position manually
b.black.setStone(0, 1);
b.black.setStone(1, 0);
b.black.setStone(1, 2);
b.black.setStone(2, 1);
b.white.setStone(0, 2);
b.white.setStone(1, 3);
b.white.setStone(2, 2);
// white at (1,1) is already captured, black to retake at (1,1)
// sync empty
for(int i = 0; i < 6; ++i){
b.empty.w[i] = ~(b.black.w[i] | b.white.w[i]);
}
b.empty.w[5] &= (1ULL << 41) - 1;
printBoard(b);
// black captures at (1,1)
history.insert(b.zobristHash);
b = b.makeMove(1 * 19 + 1);
history.insert(b.zobristHash);
printBoard(b);
// white trying to retake at (1,2) — should be illegal due to ko
bool legal = b.isLegal(1 * 19 + 2, history);
std::cout << "White retaking ko legal: " << (legal ? "YES (wrong!)" : "NO (correct)") << "\n\n";
}
void testLegalMoves(){
std::cout << "=== TEST: Legal moves on empty board ===\n";
boardstate b{};
for(int i = 0; i < 6; ++i){
b.empty.w[i] = ~0ULL;
}
b.empty.w[5] &= (1ULL << 41) - 1;
b.blackMove = true;
std::unordered_set<uint64_t> history;
bitboard moves = b.legalMoves(history);
int count = moves.countStones();
std::cout << "Legal moves on empty board: " << count << " (expected 361)\n\n";
}