aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/grossmeister/search.rs29
1 files changed, 16 insertions, 13 deletions
diff --git a/src/grossmeister/search.rs b/src/grossmeister/search.rs
index c195527..a5696d6 100644
--- a/src/grossmeister/search.rs
+++ b/src/grossmeister/search.rs
@@ -267,24 +267,27 @@ impl Grossmeister {
alpha
}
- fn reconstruct_pv(&mut self) -> Vec<Move> {
- let mut pv = Vec::new();
+ fn reconstruct_pv(&mut self, depth: u8) -> Vec<Move> {
+ let mut pv = Vec::with_capacity(depth as usize);
- if let Some(transposition) = self.transposition() {
- if let Some(mov) = transposition.mov {
- let ep_target_before = self.board.ep_target;
- let castling_rights_before = self.board.castling_rights;
- let hash_before = self.board.hash;
- let captured = self.board.make_move(mov);
+ if depth > 0 {
+ if let Some(transposition) = self.transposition() {
+ if let Some(mov) = transposition.mov {
+ let ep_target_before = self.board.ep_target;
+ let castling_rights_before = self.board.castling_rights;
+ let hash_before = self.board.hash;
+ let captured = self.board.make_move(mov);
- pv.push(mov);
- let mut subtree_pv = self.reconstruct_pv();
- pv.append(&mut subtree_pv);
+ pv.push(mov);
+ let mut subtree_pv = self.reconstruct_pv(depth - 1);
+ pv.append(&mut subtree_pv);
- self.board.unmake_move(mov, captured, ep_target_before, castling_rights_before, hash_before);
+ self.board.unmake_move(mov, captured, ep_target_before, castling_rights_before, hash_before);
+ }
}
}
+
pv
}
@@ -331,7 +334,7 @@ impl Grossmeister {
}
best_score = score;
- pv = self.reconstruct_pv();
+ pv = self.reconstruct_pv(depth);
// Print UCI info
print!("info depth {} score ", depth);