aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/board.rs30
1 files changed, 18 insertions, 12 deletions
diff --git a/src/board.rs b/src/board.rs
index 7b17aad..7295b5f 100644
--- a/src/board.rs
+++ b/src/board.rs
@@ -286,9 +286,9 @@ impl Board {
self.ply -= 1;
}
- fn perft(&mut self, depth: u8, print: bool) -> (u64, u64) {
+ fn perft(&mut self, depth: u8, print: bool) -> (u64, u64, u64) {
if depth == 0 {
- return (1, 0) // This a leaf, exactly one node
+ return (1, 0, 0) // This a leaf, exactly one node
}
let color = self.color_to_move();
@@ -301,21 +301,27 @@ impl Board {
let mut total = 0;
let mut tactical = 0;
+ let mut checks = 0;
for mov in moves {
let captured_piece = self.make_move(mov);
// King can not be in check after our own move
if !self.is_king_in_check(color) {
+ if captured_piece.is_some() {
+ tactical += 1;
+ }
+ if self.is_king_in_check(color.flip()) {
+ checks += 1;
+ }
if print {
println!("{:?}", mov);
self.print();
}
- if captured_piece.is_some() {
- tactical += 1;
- }
- let (children_total, children_tactical) = self.perft(depth - 1, print);
+ let (children_total, children_tactical, children_checks) = self.perft(depth - 1, print);
total += children_total;
tactical += children_tactical;
+ checks += children_checks;
+
}
self.unmake_move(mov, captured_piece);
}
@@ -324,7 +330,7 @@ impl Board {
println!("Found {} nodes in this subtree (depth {})", total, depth);
}
- (total, tactical)
+ (total, tactical, checks)
}
fn is_square_attacked(&self, square: Square, attacker_color: Color) -> bool {
@@ -510,11 +516,11 @@ mod tests {
let fen = String::from(DEFAULT_FEN);
let mut board = Board::from_FEN(fen);
- assert_eq!(board.perft(0, false), (1, 0));
- assert_eq!(board.perft(1, false), (20, 0));
- assert_eq!(board.perft(2, false), (400, 0));
- assert_eq!(board.perft(3, false), (8902, 34));
- // assert_eq!(board.perft(4, false), (197281, 1576));
+ assert_eq!(board.perft(0, false), (1, 0, 0));
+ assert_eq!(board.perft(1, false), (20, 0, 0));
+ assert_eq!(board.perft(2, false), (400, 0, 0));
+ assert_eq!(board.perft(3, false), (8902, 34, 12));
+ // assert_eq!(board.perft(4, false), (197281, 1576, 469));
}
#[test]