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.rs21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/board/engine.rs b/src/board/engine.rs
index 1516784..7f2fef3 100644
--- a/src/board/engine.rs
+++ b/src/board/engine.rs
@@ -343,6 +343,7 @@ impl Board {
let mut principal_variation = Vec::new();
let mut killer_moves = Vec::new();
let color = self.color();
+ let is_in_check = self.is_king_in_check(color);
match self.transposition() {
Some(transposition) => {
@@ -377,7 +378,7 @@ impl Board {
return (self.quiscence(alpha, beta), principal_variation);
}
- let mut should_pv_search = true;
+ let mut should_pv_search = true; // = !should_apply_LMR
let mut legal_move_found = false;
for mov in moves {
let ep_target_before = self.ep_target.clone();
@@ -392,10 +393,22 @@ impl Board {
// Assume PV-node is high in the list (if move ordering is good)
self.negamax_search(-beta, -alpha, depth_left - 1, &mut killer_moves, deadline)
} else {
+ // Apply late move reductions
+ let reduction = if
+ depth_left > 2 &&
+ !is_in_check &&
+ !mov.is_tactical()
+ {
+ 1
+ } else {
+ 0
+ };
+
// After we have PV-node (that raised alpha) all other nodes will be searched
- // with zero-window first to confirm this assumption
+ // with zero-window first to confirm this assumption.
+ // Also (optionally) apply Late Move Reductions
// TODO: changing 0.001 -> 0.0001 leads to a weird bug
- let result = self.negamax_search(-(alpha + 0.001), -alpha, depth_left - 1, &mut killer_moves, deadline);
+ let result = self.negamax_search(-(alpha + 0.001), -alpha, depth_left - 1 - reduction, &mut killer_moves, deadline);
// In case some of the other nodes raises alpha, then it's true PV node now,
// let's research with full window to find its exact value
if -result.0 > alpha {
@@ -459,7 +472,7 @@ impl Board {
}
if !legal_move_found {
- if self.is_king_in_check(color) {
+ if is_in_check {
return (-VALUE_WIN, principal_variation);
}
}