-
Notifications
You must be signed in to change notification settings - Fork 0
/
score.rs
69 lines (61 loc) · 4.84 KB
/
score.rs
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
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use gobit::{Color, Goban, score::Score};
const XIA_CHENKUN_TAN_XIAO: [(char, (u8, u8)); 246] = [
('B', (16, 3)), ('W', (3, 15)), ('B', (3, 2)), ('W', (16, 15)), ('B', (2, 16)), ('W', (2, 15)), ('B', (3, 16)),
('W', (4, 15)), ('B', (5, 17)), ('W', (2, 4)), ('B', (14, 16)), ('W', (14, 2)), ('B', (15, 14)), ('W', (15, 4)),
('B', (16, 4)), ('W', (16, 14)), ('B', (15, 13)), ('W', (15, 5)), ('B', (17, 6)), ('W', (16, 13)), ('B', (15, 12)),
('W', (16, 12)), ('B', (4, 3)), ('W', (3, 8)), ('B', (6, 16)), ('W', (3, 11)), ('B', (11, 2)), ('W', (7, 2)),
('B', (3, 7)), ('W', (4, 4)), ('B', (5, 4)), ('W', (4, 5)), ('B', (6, 3)), ('W', (4, 7)), ('B', (2, 3)),
('W', (1, 3)), ('B', (1, 2)), ('W', (9, 2)), ('B', (11, 4)), ('W', (5, 2)), ('B', (5, 3)), ('W', (4, 1)),
('B', (1, 4)), ('W', (1, 5)), ('B', (0, 3)), ('W', (16, 1)), ('B', (17, 1)), ('W', (15, 11)), ('B', (2, 7)),
('W', (4, 9)), ('B', (4, 6)), ('W', (5, 6)), ('B', (3, 6)), ('W', (2, 8)), ('B', (1, 8)), ('W', (1, 9)),
('B', (1, 7)), ('W', (5, 7)), ('B', (0, 9)), ('W', (1, 10)), ('B', (8, 3)), ('W', (8, 2)), ('B', (5, 5)),
('W', (16, 2)), ('B', (15, 3)), ('W', (17, 2)), ('B', (14, 3)), ('W', (13, 2)), ('B', (11, 15)), ('W', (12, 4)),
('B', (16, 9)), ('W', (12, 5)), ('B', (11, 5)), ('W', (11, 6)), ('B', (9, 5)), ('W', (16, 7)), ('B', (17, 7)),
('W', (9, 6)), ('B', (14, 9)), ('W', (7, 14)), ('B', (16, 17)), ('W', (14, 11)), ('B', (17, 10)), ('W', (16, 16)),
('B', (15, 17)), ('W', (13, 13)), ('B', (12, 6)), ('W', (11, 7)), ('B', (8, 6)), ('W', (13, 6)), ('B', (12, 7)),
('W', (12, 8)), ('B', (10, 6)), ('W', (13, 7)), ('B', (9, 7)), ('W', (16, 5)), ('B', (17, 5)), ('W', (17, 3)),
('B', (17, 4)), ('W', (13, 15)), ('B', (14, 15)), ('W', (14, 14)), ('B', (12, 14)), ('W', (13, 14)),
('B', (12, 16)), ('W', (17, 11)), ('B', (16, 10)), ('W', (15, 15)), ('B', (1, 15)), ('W', (1, 14)), ('B', (1, 16)),
('W', (9, 15)), ('B', (6, 14)), ('W', (10, 16)), ('B', (11, 16)), ('W', (6, 13)), ('B', (7, 15)), ('W', (8, 14)),
('B', (5, 14)), ('W', (17, 17)), ('B', (17, 18)), ('W', (18, 17)), ('B', (10, 17)), ('W', (9, 17)), ('B', (10, 18)),
('W', (5, 13)), ('B', (11, 1)), ('W', (9, 1)), ('B', (3, 1)), ('W', (11, 3)), ('B', (10, 3)), ('W', (12, 3)),
('B', (10, 2)), ('W', (6, 2)), ('B', (4, 0)), ('W', (5, 0)), ('B', (3, 0)), ('W', (7, 0)), ('B', (4, 14)),
('W', (2, 13)), ('B', (9, 13)), ('W', (7, 12)), ('B', (0, 10)), ('W', (10, 13)), ('B', (1, 11)), ('W', (2, 11)),
('B', (1, 12)), ('W', (2, 12)), ('B', (7, 9)), ('W', (10, 14)), ('B', (12, 13)), ('W', (8, 10)), ('B', (11, 12)),
('W', (10, 12)), ('B', (8, 17)), ('W', (9, 18)), ('B', (11, 17)), ('W', (7, 10)), ('B', (6, 9)), ('W', (16, 8)),
('B', (17, 8)), ('W', (7, 7)), ('B', (8, 8)), ('W', (6, 10)), ('B', (0, 8)), ('W', (11, 11)), ('B', (9, 9)),
('W', (2, 5)), ('B', (0, 6)), ('W', (10, 8)), ('B', (9, 8)), ('W', (9, 3)), ('B', (9, 4)), ('W', (10, 4)),
('B', (10, 5)), ('W', (8, 16)), ('B', (7, 17)), ('W', (7, 3)), ('B', (6, 6)), ('W', (4, 16)), ('B', (4, 17)),
('W', (5, 9)), ('B', (4, 2)), ('W', (5, 1)), ('B', (6, 7)), ('W', (7, 6)), ('B', (6, 5)), ('W', (7, 5)),
('B', (7, 4)), ('W', (8, 4)), ('B', (8, 5)), ('W', (6, 4)), ('B', (15, 2)), ('W', (15, 1)), ('B', (7, 4)),
('W', (5, 15)), ('B', (6, 15)), ('W', (6, 4)), ('B', (13, 1)), ('W', (14, 1)), ('B', (7, 4)), ('W', (7, 8)),
('B', (6, 8)), ('W', (6, 4)), ('B', (12, 2)), ('W', (7, 4)), ('B', (13, 0)), ('W', (12, 12)), ('B', (13, 3)),
('W', (18, 1)), ('B', (13, 16)), ('W', (11, 13)), ('B', (10, 10)), ('W', (9, 10)), ('B', (10, 9)), ('W', (14, 8)),
('B', (14, 10)), ('W', (13, 11)), ('B', (14, 5)), ('W', (14, 6)), ('B', (13, 5)), ('W', (18, 10)), ('B', (18, 9)),
('W', (18, 11)), ('B', (12, 6)), ('W', (12, 7)), ('B', (12, 9)), ('W', (11, 9)), ('B', (11, 10)), ('W', (13, 9)),
('B', (12, 10)), ('W', (13, 10)), ('B', (18, 4)), ('W', (10, 11)), ('B', (11, 8)), ('W', (10, 7)), ('B', (14, 0)),
('W', (18, 3)), ('B', (8, 18)), ('W', (9, 16)), ('B', (15, 16)), ('W', (16, 11)), ('B', (15, 9)), ('W', (10, 0)),
('B', (11, 0)), ('W', (4, 13))
];
fn score(moves: &[(char, (u8, u8))]) -> Color {
let mut goban = Goban::new(19, 19);
for (color, (x, y)) in moves {
let at = (*x, *y).into();
let color = match color {
'B' => Color::Black,
'W' => Color::White,
_ => unreachable!(),
};
debug_assert!(goban.is_legal(at, color));
goban.play(at, color);
}
let winner = Score::new(&goban, Color::Black, 7.5).winner();
assert_eq!(winner, Color::White);
winner
}
fn criterion_benchmark(c: &mut Criterion) {
c.bench_function("xia_chenkun_tan_xiao", |b| b.iter(|| score(black_box(&XIA_CHENKUN_TAN_XIAO))));
}
criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);