aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoreug-vs <eugene@eug-vs.xyz>2023-01-25 01:23:13 +0300
committereug-vs <eugene@eug-vs.xyz>2023-01-25 01:23:13 +0300
commitcb7eee871057f9afba18c505c82b44c9b02e1eec (patch)
treebe77178c172769863d78132e710fe63a3885264d /src
parentd9c41b4ef551d756ae49f1cb6e643a6f8a7bce70 (diff)
downloadchessnost-cb7eee871057f9afba18c505c82b44c9b02e1eec.tar.gz
feat: account for mobility in evaluation
Diffstat (limited to 'src')
-rw-r--r--src/board/engine.rs25
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 {