Explorar el Código

fixed infinite loop bug

Nicolas Winkler hace 2 años
padre
commit
41b1c8cb6f
Se han modificado 1 ficheros con 6 adiciones y 1 borrados
  1. 6 1
      src/engine.rs

+ 6 - 1
src/engine.rs

@@ -166,9 +166,14 @@ impl Engine {
     fn reconstruct_pv(game: &Game, hash: &Cache) -> Vec<Move> {
         let mut pv: Vec<Move> = Vec::new();
         let mut g = game.clone();
-        loop {
+
+        // max 100 to avoid infinite loops
+        for _ in 0..100 {
             let mce = hash.lookup(&g);
             if let Some(ce) = mce {
+                if ce.mov == Move::Nullmove {
+                    break;
+                }
                 pv.push(ce.mov);
                 g.apply(ce.mov);
             }