Function shakmaty::perft[][src]

pub fn perft<P: Position + Clone>(pos: &P, depth: u8) -> u64

Counts legal move paths of a given length.

Paths with mate or stalemate are not counted unless it occurs in the final position. Computing perft numbers is useful for comparing, testing and debugging move generation correctness and performance.

The method used here is simply recursively enumerating the entire tree of legal moves. While this is fine for testing there is much faster specialized software.

Warning: Computing perft numbers can take a long time, even at moderate depths.

Examples

use shakmaty::Chess;
use shakmaty::perft;

let pos = Chess::default();
assert_eq!(perft(&pos, 1), 20);
assert_eq!(perft(&pos, 2), 400);
assert_eq!(perft(&pos, 3), 8902);