aboutsummaryrefslogtreecommitdiff
path: root/src/board.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/board.rs')
-rw-r--r--src/board.rs32
1 files changed, 21 insertions, 11 deletions
diff --git a/src/board.rs b/src/board.rs
index 58e4037..2cb4fcf 100644
--- a/src/board.rs
+++ b/src/board.rs
@@ -366,9 +366,9 @@ impl Board {
self.ply -= 1;
}
- fn perft(&mut self, depth: u8, print: bool) -> (u64, u64, u64) {
+ fn perft(&mut self, depth: u8, print: bool) -> (u64, u64, u64, u64) {
if depth == 0 {
- return (1, 0, 0) // This a leaf, exactly one node
+ return (1, 0, 0, 0) // This a leaf, exactly one node
}
let color = self.color_to_move();
@@ -382,15 +382,23 @@ impl Board {
let mut total = 0;
let mut tactical = 0;
let mut checks = 0;
+ let mut en_passants = 0;
for mov in moves {
let ep_target_before = self.ep_target.clone();
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;
+ match mov.kind {
+ MoveKind::Capture => {
+ tactical += 1;
+ }
+ MoveKind::EnPassant => {
+ en_passants += 1;
+ }
+ _ => {}
}
+
if self.is_king_in_check(color.flip()) {
checks += 1;
}
@@ -398,10 +406,11 @@ impl Board {
println!("{:?}", mov);
self.print();
}
- let (children_total, children_tactical, children_checks) = self.perft(depth - 1, print);
+ let (children_total, children_tactical, children_checks, children_ep) = self.perft(depth - 1, print);
total += children_total;
tactical += children_tactical;
checks += children_checks;
+ en_passants += children_ep;
}
self.unmake_move(mov, captured_piece, ep_target_before);
@@ -411,7 +420,7 @@ impl Board {
println!("Found {} nodes in this subtree (depth {})", total, depth);
}
- (total, tactical, checks)
+ (total, tactical, checks, en_passants)
}
fn is_square_attacked(&self, square: Square, attacker_color: Color) -> bool {
@@ -597,11 +606,12 @@ mod tests {
let fen = String::from(DEFAULT_FEN);
let mut board = Board::from_FEN(fen);
- 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));
+ assert_eq!(board.perft(0, false), (1, 0, 0, 0));
+ assert_eq!(board.perft(1, false), (20, 0, 0, 0));
+ assert_eq!(board.perft(2, false), (400, 0, 0, 0));
+ assert_eq!(board.perft(3, false), (8902, 34, 12, 0));
+ assert_eq!(board.perft(4, false), (197281, 1576, 469, 0));
+ // assert_eq!(board.perft(5, false), (4865609, 82719, 27351));
}
#[test]