aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--benches/search.rs2
-rw-r--r--src/grossmeister/search.rs32
2 files changed, 17 insertions, 17 deletions
diff --git a/benches/search.rs b/benches/search.rs
index 89c59d5..926f5c3 100644
--- a/benches/search.rs
+++ b/benches/search.rs
@@ -7,7 +7,7 @@ fn main() {
let mut gm = Grossmeister::new(board);
let start = Instant::now();
- let (score, pv) = gm.iterative_deepening(8);
+ let (score, pv) = gm.iterative_deepening(8).unwrap();
println!("Finished in {:?}: score={:?} {:?}", start.elapsed(), score, pv);
gm.board.print();
diff --git a/src/grossmeister/search.rs b/src/grossmeister/search.rs
index cad2b99..d3dc0b4 100644
--- a/src/grossmeister/search.rs
+++ b/src/grossmeister/search.rs
@@ -233,7 +233,7 @@ impl Grossmeister {
alpha
}
- pub fn iterative_deepening(&mut self, max_depth: u8) -> (f32, Vec<Move>) {
+ pub fn iterative_deepening(&mut self, max_depth: u8) -> Option<(f32, Vec<Move>)> {
let mut result = None;
let mut depth = 1;
let mut alpha = -INFINITY;
@@ -310,17 +310,17 @@ impl Grossmeister {
println!("info hashfull {}", 1000 * self.transposition_table.iter().filter(|item| item.is_some()).count() / self.transposition_table.len());
- match result {
- Some(r) => {
+ if let Some(r) = result.clone() {
+ if !r.1.is_empty() {
print!("bestmove {}", r.1[0]);
- if r.1.len() > 1 {
- print!(" ponder {}", r.1[1])
- }
- println!();
- r
}
- None => panic!("No move found by search")
+ if r.1.len() > 1 {
+ print!(" ponder {}", r.1[1])
+ }
+ println!();
}
+
+ result
}
pub fn perft(&mut self, depth: u8, print: bool) -> PerftResult {
@@ -436,7 +436,7 @@ mod tests {
let fen = String::from("2kr1b1r/pp1npppp/2p1bn2/7q/5B2/2NB1Q1P/PPP1N1P1/2KR3R w - - 0 1");
let board = Board::from_FEN(fen);
let mut gm = Grossmeister::new(board);
- let (score, pv) = gm.iterative_deepening(8);
+ let (score, pv) = gm.iterative_deepening(8).unwrap();
assert_eq!(score, SCORE_MATE - 3.0);
assert_eq!(pv, vec![
@@ -452,7 +452,7 @@ mod tests {
let board = Board::from_FEN(fen);
let mut gm = Grossmeister::new(board);
- let (_, pv) = gm.iterative_deepening(6);
+ let (_, pv) = gm.iterative_deepening(6).unwrap();
assert_eq!(
pv[0],
Move { source: Square::F5, target: Square::H4, kind: MoveKind::Quiet },
@@ -466,7 +466,7 @@ mod tests {
let board = Board::from_FEN(fen);
let mut gm = Grossmeister::new(board);
- let (_, pv) = gm.iterative_deepening(5);
+ let (_, pv) = gm.iterative_deepening(5).unwrap();
assert_eq!(
pv[0],
Move { source: Square::C2, target: Square::C3, kind: MoveKind::Quiet },
@@ -481,7 +481,7 @@ mod tests {
let mut gm = Grossmeister::new(board);
gm.debug = true;
- let (score, pv) = gm.iterative_deepening(5);
+ let (score, pv) = gm.iterative_deepening(5).unwrap();
dbg!(score, pv);
assert_eq!(SCORE_MATE - score, 3.0); // Mate in 3 plies
}
@@ -493,7 +493,7 @@ mod tests {
let mut gm = Grossmeister::new(board);
gm.debug = true;
- let (score, pv) = gm.iterative_deepening(5);
+ let (score, pv) = gm.iterative_deepening(5).unwrap();
dbg!(score, pv);
assert_eq!(score + SCORE_MATE, 4.0); // Mate in 4 plies
}
@@ -505,7 +505,7 @@ mod tests {
let mut gm = Grossmeister::new(board);
gm.debug = true;
- let (score, pv) = gm.iterative_deepening(5);
+ let (score, pv) = gm.iterative_deepening(5).unwrap();
dbg!(score, pv);
assert_eq!(SCORE_MATE - score, 3.0); // Mate in 3 plies
}
@@ -517,7 +517,7 @@ mod tests {
let mut gm = Grossmeister::new(board);
gm.debug = true;
- let (score, pv) = gm.iterative_deepening(5);
+ let (score, pv) = gm.iterative_deepening(5).unwrap();
dbg!(score, pv);
assert!(score <= 0.0);
}