diff options
Diffstat (limited to 'src/board')
-rw-r--r-- | src/board/engine.rs | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/src/board/engine.rs b/src/board/engine.rs index 05cb1e7..feb3368 100644 --- a/src/board/engine.rs +++ b/src/board/engine.rs @@ -187,11 +187,14 @@ impl Board { 0.0 } - pub fn order_moves(&self, moves: &mut Vec<Move>) { - moves.sort_unstable_by(|a, b| { - let a_eval = self.eval_move(*a); - let b_eval = self.eval_move(*b); - if a_eval == 0.0 && b_eval == 0.0 { + pub fn order_moves(&self, moves: Vec<Move>) -> Vec<Move> { + let mut moves_with_eval: Vec<(Move, f32)> = moves + .iter() + .map(|m| (*m, self.eval_move(*m))) + .collect(); + + moves_with_eval.sort_unstable_by(|(a, a_eval), (b, b_eval)| { + if *a_eval == 0.0 && *b_eval == 0.0 { // Prioritize equal captures over non-captures if a.is_tactical() && !b.is_tactical() { return Ordering::Less @@ -200,8 +203,10 @@ impl Board { return Ordering::Greater } } - a_eval.total_cmp(&b_eval).reverse() + a_eval.total_cmp(b_eval).reverse() }); + + moves_with_eval.iter_mut().map(|(m, _)| *m).collect() } pub fn negamax_search(&mut self, mut alpha: f32, beta: f32, depth_left: u8, deadline: Instant) -> (f32, Vec<Move>) { @@ -209,7 +214,7 @@ impl Board { let color = self.color(); let mut moves = self.generate_pseudolegal_moves(color); - self.order_moves(&mut moves); + moves = self.order_moves(moves); match self.transposition_table[(self.hash % TTABLE_SIZE) as usize] { Some(item) => { @@ -285,7 +290,7 @@ impl Board { pub fn quiscence(&mut self, mut alpha: f32, beta: f32) -> f32 { let color = self.color(); let mut moves = self.generate_pseudolegal_moves(color); - self.order_moves(&mut moves); + moves = self.order_moves(moves); match self.transposition_table[(self.hash % TTABLE_SIZE) as usize] { Some(item) => { |