Nicolas Winkler 2 vuotta sitten
vanhempi
commit
71965d63b1
3 muutettua tiedostoa jossa 18 lisäystä ja 13 poistoa
  1. 1 1
      src/main.rs
  2. 6 4
      src/search.rs
  3. 11 8
      src/ttable.rs

+ 1 - 1
src/main.rs

@@ -1,4 +1,4 @@
-#![feature(pointer_is_aligned)]
+#![feature(stdsimd)]
 pub mod interface;
 pub mod bitboard;
 pub mod movegen;

+ 6 - 4
src/search.rs

@@ -236,7 +236,9 @@ pub fn negamax(game: &mut Game, sc: &mut SearchControl, hash: &mut Cache, mut al
         //println!("mov: {}", mov.to_string());
         let undo = game.apply(mov);
 
-        let val = -negamax(game, sc, hash, -decrease_mate_in(beta), -decrease_mate_in(alpha), depth - 1);
+        let val = increase_mate_in(
+            -negamax(game, sc, hash, -decrease_mate_in(beta), -decrease_mate_in(alpha), depth - 1)
+        );
         game.undo_move(undo);
 
         // return if the search has been cancelled
@@ -245,14 +247,14 @@ 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 as _, mov.to_simple(), increase_mate_in(val)));
+            hash.cache(game, CacheEntry::new_lower(depth as _, sc.halfmove_age as _, mov.to_simple(), val));
             if !mov.is_capture() {
                 sc.insert_killer(ply_depth, mov);
             }
             return val;
         }
-        if increase_mate_in(val) > alpha {
-            alpha = increase_mate_in(val);
+        if val > alpha {
+            alpha = val;
             best_move = Some(mov);
         }
     }

+ 11 - 8
src/ttable.rs

@@ -102,11 +102,11 @@ impl Cache {
         (hash % (self.table.len() as u64)) as usize
     }
 
-    pub fn lookup<'a>(&'a self, game_pos: &Game) -> Option<&'a CacheEntry> {
-        if game_pos.zobrist.is_none() {
+    pub fn lookup<'a>(&'a self, board: &Game) -> Option<&'a CacheEntry> {
+        if board.zobrist.is_none() {
             info!("invalid zobrist");
         }
-        let hash = game_pos.zobrist.as_ref().unwrap().1;
+        let hash = board.zobrist.as_ref().unwrap().1;
         let index = self.get_index(hash);
 
         let bucket = &self.table[index];
@@ -151,13 +151,16 @@ impl Cache {
         let hash = game_pos.zobrist.as_ref().unwrap().1;
         let index = self.get_index(hash);
 
-        let ptr: *const Bucket = &self.table[index];
-        if !ptr.is_aligned_to(64) {
-            println!("AAAH: {}", std::mem::size_of::<Bucket>());
-        }
-
         let bucket = &mut self.table[index];
 
+
+        for i in 0..bucket.hashes.len() {
+            if bucket.hashes[i] == hash {
+                bucket.entries[i] = ce;
+                return;
+            }
+        }
+
         for i in 0..bucket.hashes.len() {
             if Self::should_replace(bucket.hashes[i], &bucket.entries[i], hash, &ce) {
                 bucket.hashes[i] = hash;