diff options
| -rw-r--r-- | src/board.rs | 31 | 
1 files changed, 19 insertions, 12 deletions
| diff --git a/src/board.rs b/src/board.rs index d3c1666..7b17aad 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 { +    fn perft(&mut self, depth: u8, print: bool) -> (u64, u64) {          if depth == 0 { -            return 1 // This a leaf, exactly one node +            return (1, 0) // This a leaf, exactly one node          }          let color = self.color_to_move(); @@ -300,16 +300,22 @@ impl Board {          }          let mut total = 0; +        let mut tactical = 0;          for mov in moves {              let captured_piece = self.make_move(mov); -            if print { -                println!("{:?}", mov); -                self.print(); -            }              // King can not be in check after our own move              if !self.is_king_in_check(color) { -                total += self.perft(depth - 1, print); +                if print { +                    println!("{:?}", mov); +                    self.print(); +                } +                if captured_piece.is_some() { +                    tactical += 1; +                } +                let (children_total, children_tactical) = self.perft(depth - 1, print); +                total += children_total; +                tactical += children_tactical;              }              self.unmake_move(mov, captured_piece);          } @@ -318,7 +324,7 @@ impl Board {              println!("Found {} nodes in this subtree (depth {})", total, depth);          } -        total +        (total, tactical)      }      fn is_square_attacked(&self, square: Square, attacker_color: Color) -> bool { @@ -504,10 +510,11 @@ mod tests {          let fen = String::from(DEFAULT_FEN);          let mut board = Board::from_FEN(fen); -        assert_eq!(board.perft(0, false), 1); -        assert_eq!(board.perft(1, false), 20); -        assert_eq!(board.perft(2, false), 400); -        // TODO: assert_eq!(board.perft(3, false), 8902); +        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));      }      #[test] | 
