aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoreug-vs <eugene@eug-vs.xyz>2023-01-27 21:24:20 +0300
committereug-vs <eugene@eug-vs.xyz>2023-01-27 21:24:20 +0300
commita85b31683d782c2cbcfc97e06f1cfb53ac9aee0a (patch)
tree65d5c65d0fe8699f5bdd148b3762ff5a1feb9593 /src
parent68536a7c80a5c8ce3af0969e7840198f85b3aa78 (diff)
downloadchessnost-a85b31683d782c2cbcfc97e06f1cfb53ac9aee0a.tar.gz
feat: improve eval_move performance
Diffstat (limited to 'src')
-rw-r--r--src/board/engine.rs21
1 files changed, 12 insertions, 9 deletions
diff --git a/src/board/engine.rs b/src/board/engine.rs
index 2ff3aed..47890ad 100644
--- a/src/board/engine.rs
+++ b/src/board/engine.rs
@@ -173,15 +173,18 @@ impl Board {
/// Evaluate move for move ordering, prioritizing efficient captures
/// where low-value pieces capture high-value pieces
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.,
- }
- });
- 2. * target_eval - source_eval
+ if m.kind == MoveKind::Capture || m.kind == MoveKind::EnPassant {
+ 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.,
+ }
+ });
+ return 2. * target_eval - source_eval
+ }
+ 0.0
}
pub fn negamax_search(&mut self, mut alpha: f32, beta: f32, depth_left: u8, deadline: Instant) -> (f32, Vec<Move>) {