aboutsummaryrefslogtreecommitdiff
path: root/src/board/engine.rs
diff options
context:
space:
mode:
authoreug-vs <eugene@eug-vs.xyz>2023-01-25 07:57:31 +0300
committereug-vs <eugene@eug-vs.xyz>2023-01-25 07:57:31 +0300
commite7f6024025169c6b0018132bb0b19bdfe91cb43f (patch)
tree8d70192ccf0e2f71da75ca7fac96cbc77f3027fc /src/board/engine.rs
parent80b3283f4a2a09561abae1b7b981b7a3139f00e2 (diff)
downloadchessnost-e7f6024025169c6b0018132bb0b19bdfe91cb43f.tar.gz
feat: implement move ordering
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) => {