Skip to content

Commit 9305591

Browse files
committed
Run all tricky perft tests, separate impossible checker perft
1 parent e22c7c1 commit 9305591

File tree

3 files changed

+88
-74
lines changed

3 files changed

+88
-74
lines changed

test/perft_test.dart

Lines changed: 61 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,67 @@ import 'perft_parser.dart';
66
const nodeLimit = 10000000;
77

88
void main() async {
9+
group('Standard chess', () {
10+
test('initial position', () {
11+
const pos = Chess.initial;
12+
expect(perft(pos, 0), 1);
13+
expect(perft(pos, 1), 20);
14+
expect(perft(pos, 2), 400);
15+
expect(perft(pos, 3), 8902);
16+
expect(perft(pos, 4), 197281);
17+
});
18+
19+
group('tricky', () {
20+
final tests = Parser()
21+
.parse(File('test/resources/tricky.perft').readAsStringSync());
22+
for (final perftTest in tests) {
23+
for (final testCase in perftTest.cases
24+
.takeWhile((testCase) => testCase.nodes < nodeLimit)) {
25+
test('${perftTest.id} ${perftTest.fen} ${testCase.depth}', () {
26+
final position = Chess.fromSetup(Setup.parseFen(perftTest.fen));
27+
expect(perft(position, testCase.depth), testCase.nodes,
28+
reason:
29+
'id: ${perftTest.id}\nfen: ${perftTest.fen} \ndepth: ${testCase.depth} \nnodes: ${testCase.nodes}');
30+
});
31+
}
32+
}
33+
});
34+
35+
group('impossible checker', () {
36+
final tests = Parser().parse(
37+
File('test/resources/impossible-checker.perft').readAsStringSync());
38+
for (final perftTest in tests) {
39+
for (final testCase in perftTest.cases
40+
.takeWhile((testCase) => testCase.nodes < nodeLimit)) {
41+
test('${perftTest.id} ${perftTest.fen} ${testCase.depth}', () {
42+
final position = Chess.fromSetup(Setup.parseFen(perftTest.fen),
43+
ignoreImpossibleCheck: true);
44+
expect(perft(position, testCase.depth), testCase.nodes,
45+
reason:
46+
'id: ${perftTest.id}\nfen: ${perftTest.fen} \ndepth: ${testCase.depth} \nnodes: ${testCase.nodes}');
47+
});
48+
}
49+
}
50+
});
51+
52+
group('random', () {
53+
final tests = Parser()
54+
.parse(File('test/resources/random.perft').readAsStringSync());
55+
// only test 10 position in random. Test file has around 6000 positions
56+
for (final perftTest in tests.take(50)) {
57+
final position = Chess.fromSetup(Setup.parseFen(perftTest.fen));
58+
for (final testCase in perftTest.cases
59+
.takeWhile((testCase) => testCase.nodes < nodeLimit)) {
60+
test('${perftTest.id} ${perftTest.fen} ${testCase.depth}', () {
61+
expect(perft(position, testCase.depth), testCase.nodes,
62+
reason:
63+
'id: ${perftTest.id}\nfen: ${perftTest.fen} \ndepth: ${testCase.depth} \nnodes: ${testCase.nodes}');
64+
});
65+
}
66+
}
67+
});
68+
});
69+
970
group('Three Check', () {
1071
final tests =
1172
Parser().parse(File('test/resources/3check.perft').readAsStringSync());
@@ -103,52 +164,6 @@ void main() async {
103164
}
104165
});
105166

106-
// group('Chess Tricky', () {
107-
// final tests =
108-
// Parser().parse(File('test/resources/tricky.perft').readAsStringSync());
109-
// for (final perftTest in tests) {
110-
// for (final testCase in perftTest.cases
111-
// .takeWhile((testCase) => testCase.nodes < nodeLimit)) {
112-
// test('${perftTest.id} ${perftTest.fen} ${testCase.depth}', () {
113-
// final position = Chess.fromSetup(Setup.parseFen(perftTest.fen),
114-
// ignoreImpossibleCheck:
115-
// true); // true: otherwise there is an Impossible Check Error
116-
// expect(perft(position, testCase.depth), testCase.nodes,
117-
// reason:
118-
// 'id: ${perftTest.id}\nfen: ${perftTest.fen} \ndepth: ${testCase.depth} \nnodes: ${testCase.nodes}');
119-
// });
120-
// }
121-
// }
122-
// });
123-
124-
group('Random', () {
125-
final tests =
126-
Parser().parse(File('test/resources/random.perft').readAsStringSync());
127-
// only test 10 position in random. Test file has around 6000 positions
128-
for (final perftTest in tests.take(50)) {
129-
final position = Chess.fromSetup(Setup.parseFen(perftTest.fen));
130-
for (final testCase in perftTest.cases
131-
.takeWhile((testCase) => testCase.nodes < nodeLimit)) {
132-
test('${perftTest.id} ${perftTest.fen} ${testCase.depth}', () {
133-
expect(perft(position, testCase.depth), testCase.nodes,
134-
reason:
135-
'id: ${perftTest.id}\nfen: ${perftTest.fen} \ndepth: ${testCase.depth} \nnodes: ${testCase.nodes}');
136-
});
137-
}
138-
}
139-
});
140-
141-
group('Standard', () {
142-
test('initial position', () {
143-
const pos = Chess.initial;
144-
expect(perft(pos, 0), 1);
145-
expect(perft(pos, 1), 20);
146-
expect(perft(pos, 2), 400);
147-
expect(perft(pos, 3), 8902);
148-
expect(perft(pos, 4), 197281);
149-
});
150-
});
151-
152167
group('Chess 960', () {
153168
final tests = Parser()
154169
.parse(File('test/resources/chess960.perft').readAsStringSync());
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#
2+
# Impossible checker alignment.
3+
#
4+
5+
id align-diag-1
6+
epd 3R4/8/q4k2/2B5/1NK5/3b4/8/8 w - -
7+
perft 1 4
8+
perft 2 125
9+
perft 3 2854
10+
11+
id align-diag-2
12+
epd 2Nq4/2K5/1b6/8/7R/3k4/7P/8 w - -
13+
perft 1 3
14+
perft 2 81
15+
perft 3 1217
16+
17+
id align-horizontal
18+
epd 5R2/2P5/8/4k3/8/3rK2r/8/8 w - -
19+
perft 1 2
20+
perft 2 56
21+
perft 3 1030
22+
23+
# id align-ep
24+
# epd 8/8/8/1k6/3Pp3/8/8/4KQ2 b - d3
25+
# perft 1 6
26+
# perft 2 121
27+
# perft 3 711

test/resources/tricky.perft

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -112,31 +112,3 @@ epd 4rrk1/pbbp2p1/1ppnp3/3n1pqp/3N1PQP/1PPNP3/PBBP2P1/4RRK1 w Ff -
112112
perft 1 42
113113
perft 2 1743
114114
perft 3 71908
115-
116-
#
117-
# Impossible checker alignment.
118-
#
119-
120-
id align-diag-1
121-
epd 3R4/8/q4k2/2B5/1NK5/3b4/8/8 w - -
122-
perft 1 4
123-
perft 2 125
124-
perft 3 2854
125-
126-
id align-diag-2
127-
epd 2Nq4/2K5/1b6/8/7R/3k4/7P/8 w - -
128-
perft 1 3
129-
perft 2 81
130-
perft 3 1217
131-
132-
id align-horizontal
133-
epd 5R2/2P5/8/4k3/8/3rK2r/8/8 w - -
134-
perft 1 2
135-
perft 2 56
136-
perft 3 1030
137-
138-
id align-ep
139-
epd 8/8/8/1k6/3Pp3/8/8/4KQ2 b - d3
140-
perft 1 6
141-
perft 2 121
142-
perft 3 711

0 commit comments

Comments
 (0)