|
@@ -29,6 +29,8 @@ pub struct SearchControl<'a> {
|
|
|
|
|
|
/// depth the search was started at
|
|
/// depth the search was started at
|
|
initial_depth: i32,
|
|
initial_depth: i32,
|
|
|
|
+
|
|
|
|
+ nullmoves_enabled: bool,
|
|
}
|
|
}
|
|
|
|
|
|
pub enum SearchResult {
|
|
pub enum SearchResult {
|
|
@@ -47,7 +49,8 @@ impl<'a> SearchControl<'a> {
|
|
check,
|
|
check,
|
|
stopping: false,
|
|
stopping: false,
|
|
move_history,
|
|
move_history,
|
|
- initial_depth: depth
|
|
|
|
|
|
+ initial_depth: depth,
|
|
|
|
+ nullmoves_enabled: true
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -141,7 +144,7 @@ pub fn search(game: &mut Game, sc: &mut SearchControl, hash: &mut Cache, mut alp
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-pub fn negamax(game: &mut Game, sc: &mut SearchControl, hash: &mut Cache, mut alpha: PosValue, beta: PosValue, depth: i32) -> PosValue {
|
|
|
|
|
|
+pub fn negamax(game: &mut Game, sc: &mut SearchControl, hash: &mut Cache, mut alpha: PosValue, beta: PosValue, mut depth: i32) -> PosValue {
|
|
|
|
|
|
let cache_entry = hash.lookup(game);
|
|
let cache_entry = hash.lookup(game);
|
|
|
|
|
|
@@ -202,11 +205,16 @@ pub fn negamax(game: &mut Game, sc: &mut SearchControl, hash: &mut Cache, mut al
|
|
}
|
|
}
|
|
|
|
|
|
// Nullmove
|
|
// Nullmove
|
|
- if false && !check && depth >= 4 && game_lateness(game) < 80 {
|
|
|
|
|
|
+ if sc.nullmoves_enabled && !check && depth >= 4 && game_lateness(game) < 60 {
|
|
|
|
+
|
|
|
|
+ let reduce = if depth > 5 { if depth > 7 { 5 } else { 4 }} else { 3 };
|
|
|
|
+
|
|
let nmov = Move::Nullmove;
|
|
let nmov = Move::Nullmove;
|
|
let undo = game.apply(nmov);
|
|
let undo = game.apply(nmov);
|
|
|
|
|
|
- let val = -negamax(game, sc, hash, -beta, -alpha, depth / 2 - 1);
|
|
|
|
|
|
+ sc.nullmoves_enabled = false;
|
|
|
|
+ let val = -negamax(game, sc, hash, -beta, -alpha, depth - reduce);
|
|
|
|
+ sc.nullmoves_enabled = true;
|
|
game.undo_move(undo);
|
|
game.undo_move(undo);
|
|
|
|
|
|
if sc.stopping {
|
|
if sc.stopping {
|
|
@@ -215,7 +223,8 @@ pub fn negamax(game: &mut Game, sc: &mut SearchControl, hash: &mut Cache, mut al
|
|
|
|
|
|
if is_mate_in_p1(val).is_none() {
|
|
if is_mate_in_p1(val).is_none() {
|
|
if val >= beta {
|
|
if val >= beta {
|
|
- return beta;
|
|
|
|
|
|
+ depth -= reduce - 1;
|
|
|
|
+ //return beta;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -241,7 +250,7 @@ pub fn negamax(game: &mut Game, sc: &mut SearchControl, hash: &mut Cache, mut al
|
|
}
|
|
}
|
|
|
|
|
|
if val >= beta {
|
|
if val >= beta {
|
|
- hash.cache(game, CacheEntry::new_lower(depth as _, sc.halfmove_age, mov, val));
|
|
|
|
|
|
+ hash.cache(game, CacheEntry::new_lower(depth as _, sc.halfmove_age, mov, increase_mate_in(val)));
|
|
if !mov.is_capture() {
|
|
if !mov.is_capture() {
|
|
sc.insert_killer(ply_depth, mov);
|
|
sc.insert_killer(ply_depth, mov);
|
|
}
|
|
}
|