Переглянути джерело

adding null move reduction

Nicolas Winkler 2 роки тому
батько
коміт
262413bd33
2 змінених файлів з 27 додано та 6 видалено
  1. 12 0
      Cargo.toml
  2. 15 6
      src/search.rs

+ 12 - 0
Cargo.toml

@@ -12,7 +12,19 @@ rand = "*"
 [build-dependencies]
 rand = "*"
 
+[build]
+rustflags = ["-C","target-cpu=native"]
+
 [profile.release]
 opt-level = 3
 lto = true
+strip = "debuginfo"
+
+# Optimize the build script;
+# As we generate magic tables in it, it needs to be optimized
+[profile.dev.build-override]
+opt-level = 3
+[profile.release.build-override]
+opt-level = 3
+
 

+ 15 - 6
src/search.rs

@@ -29,6 +29,8 @@ pub struct SearchControl<'a> {
 
     /// depth the search was started at
     initial_depth: i32,
+
+    nullmoves_enabled: bool,
 }
 
 pub enum SearchResult {
@@ -47,7 +49,8 @@ impl<'a> SearchControl<'a> {
             check,
             stopping: false,
             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);
 
@@ -202,11 +205,16 @@ pub fn negamax(game: &mut Game, sc: &mut SearchControl, hash: &mut Cache, mut al
     }
 
     // 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 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);
 
         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 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 {
-            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() {
                 sc.insert_killer(ply_depth, mov);
             }