diff options
Diffstat (limited to 'src/board')
-rw-r--r-- | src/board/engine.rs | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/src/board/engine.rs b/src/board/engine.rs index dcb3646..d00b89b 100644 --- a/src/board/engine.rs +++ b/src/board/engine.rs @@ -99,13 +99,29 @@ impl Board { eval } + /// Evaluate a position relative to the current player + pub fn evaluate(&self, precomputed_mobility: Option<f32>) -> f32 { + let opponent_mobility = self.mobility(self.color().flip()); + let player_mobility = match precomputed_mobility { + Some(m) => m, + None => self.mobility(self.color()), + }; + let mobility_advantage = player_mobility - opponent_mobility as f32; + + let material_advantage = self.material_advantage(); + + material_advantage + 0.1 * mobility_advantage + } + pub fn negamax_search(&mut self, mut alpha: f32, beta: f32, depth_left: u8) -> (f32, Vec<Move>) { let mut principal_variation = Vec::new(); let color = self.color(); + + let moves = self.generate_pseudolegal_moves(color); + if depth_left == 0 { - return (self.material_advantage(), principal_variation); + return (self.evaluate(Some(moves.len() as f32)), principal_variation); } - let moves = self.generate_pseudolegal_moves(color); for mov in moves { let ep_target_before = self.ep_target.clone(); @@ -135,7 +151,9 @@ impl Board { pub fn quiscence(&mut self, mut alpha: f32, beta: f32) -> f32 { let color = self.color(); - let stand_pat = self.material_advantage(); + let moves = self.generate_pseudolegal_moves(color); + + let stand_pat = self.evaluate(Some(moves.len() as f32)); if stand_pat >= beta { return beta; @@ -144,7 +162,6 @@ impl Board { alpha = stand_pat; } - let moves = self.generate_pseudolegal_moves(color); let tactical_moves = moves.iter().filter(|m| m.kind == MoveKind::Capture || m.kind == MoveKind::EnPassant); for mov in tactical_moves { |