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
mod board_geometry;
mod zobrist_arrays;
mod move_stack;
mod notation;
pub use self::board_geometry::BoardGeometry;
pub use self::zobrist_arrays::ZobristArrays;
pub use self::move_stack::MoveStack;
pub use self::notation::parse_fen;
use depth::*;
use move_generator::MoveGenerator;
pub fn perft<T: MoveGenerator>(position: &mut T, depth: Depth) -> u64 {
fn pft<T: MoveGenerator>(s: &mut MoveStack, p: &mut T, d: Depth) -> u64 {
if d <= 0 {
return 1;
}
let mut nodes = 0;
s.save();
p.generate_all(s);
while let Some(m) = s.pop() {
if p.do_move(m).is_some() {
nodes += pft(s, p, d - 1);
p.undo_move(m);
}
}
s.restore();
nodes
}
let mut s = MoveStack::new();
pft(&mut s, position, depth)
}