aboutsummaryrefslogtreecommitdiff
path: root/src/board/engine.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/board/engine.rs')
-rw-r--r--src/board/engine.rs20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/board/engine.rs b/src/board/engine.rs
index 4fe8652..75a505e 100644
--- a/src/board/engine.rs
+++ b/src/board/engine.rs
@@ -1,3 +1,4 @@
+use std::cmp::Ordering;
use crate::{bitboard::pop_count, board::*};
use super::ttable::{NodeType, TranspositionTableItem};
@@ -107,6 +108,19 @@ impl Board {
material_advantage + 0.1 * mobility_advantage
}
+ /// Evaluate move for move ordering, prioritizing efficient captures
+ fn eval_move(&self, m: Move) -> f32 {
+ let [source_eval, target_eval] = [m.source, m.target]
+ .map(|sq| self.piece_by_square(sq))
+ .map(|p| {
+ match p {
+ Some(p) => p.static_eval(),
+ None => 0.,
+ }
+ });
+ source_eval - target_eval
+ }
+
pub fn negamax_search(&mut self, mut alpha: f32, beta: f32, depth_left: u8) -> (f32, Vec<Move>) {
let transposition = self.transposition_table[(self.hash % TTABLE_SIZE) as usize];
@@ -115,6 +129,12 @@ impl Board {
let mut moves = self.generate_pseudolegal_moves(color);
+ moves.sort_unstable_by(|a, b| {
+ let a_eval = self.eval_move(*a);
+ let b_eval = self.eval_move(*b);
+ a_eval.total_cmp(&b_eval)
+ });
+
if transposition.is_some() {
match transposition {
Some(item) => {