浏览代码

Add extra output to find out what's happening.

The make is failing with size=5, it never gets to removing
anything.  I believe it's the finalize call that needs to be
removed, or at least run much less then it currently is.
Steve Thielemann 1 周之前
父节点
当前提交
6a081b4885
共有 2 个文件被更改,包括 35 次插入10 次删除
  1. 12 2
      src/main.rs
  2. 23 8
      sudoku/src/sudoku.rs

+ 12 - 2
src/main.rs

@@ -43,10 +43,20 @@ fn main() {
         solution.make();
         solution.board.display();
         // 16x16 make_puzzle() takes too long.
+        let mut total = 0;
+
         let mut puzzle = solution.clone();
-        for _ in 0..81 {
-            puzzle.make_puzzle();
+        let mut i =  10;
+        while i > 0 {
+            println!("Take {i}:");
+            let count = puzzle.make_puzzle();
+            if count != 0 {
+                total += count;
+            } else {
+                i -= 1;
+            }
         }
+        println!("Removed {total} values from board.");
 
         if let Some(filename) = args.get_one::<PathBuf>("file") {
             let mut ksudo = Ksudoku::default();

+ 23 - 8
sudoku/src/sudoku.rs

@@ -1016,7 +1016,7 @@ impl AnySolver {
             board: initial_board.clone(),
             possible: AnyPossible::new(initial_board.size),
             group: AnyGroup::new(initial_board.size),
-            /* 
+            /*
             cell_poss: vec![
                 default_poss;
                 initial_board.width as usize * initial_board.width as usize
@@ -1114,7 +1114,9 @@ impl AnySolver {
         }
 
         if updated_here {
-            println!("find_pairs (update)");
+            if OUTPUT {
+                println!("find_pairs (update)");
+            }
         }
         updated_here = false;
 
@@ -1504,9 +1506,10 @@ impl AnySolver {
 
 
          */
-
+        /*
         println!("finalize_possible ends...");
         updated
+        */
     }
 
     // I'm saving finalize_cell, just because it's working,
@@ -1897,7 +1900,7 @@ impl AnySolver {
         let mut default_poss = Flags::new(self.board.width as usize);
         default_poss.set_range(0..self.board.width as usize);
 
-        /* 
+        /*
         for x in 0..self.board.width {
             self.cell_poss[x as usize] = default_poss.clone();
         }
@@ -1961,7 +1964,7 @@ impl AnySolver {
         let mut default_poss = Flags::new(self.board.width as usize);
         default_poss.set_range(0..self.board.width as usize);
 
-        /* 
+        /*
         for x in 0..self.board.width {
             self.cell_poss[x as usize] = default_poss.clone();
         }
@@ -2066,7 +2069,7 @@ impl AnySolver {
                     self.board.copy(&backup.board);
                     self.possible.copy(&backup.possible);
 
-                    /* 
+                    /*
                     for i in 0..backup.cell_poss.len() {
                         self.cell_poss[i] = backup.cell_poss[i].clone();
                     }
@@ -2084,14 +2087,26 @@ impl AnySolver {
 
     /// Make a puzzle by removing items
     /// - Verify it still has a single solution.
-    pub fn make_puzzle(&mut self) {
+    pub fn make_puzzle(&mut self) -> i32 {
         let mut rng = ChaCha20Rng::from_entropy();
 
+        /* 
+        // This doesn't seem like this is correct here.
+        // This fills the board in, and I'm removing parts below...
         if !self.board.complete() {
             self.fill_board(&mut rng);
         }
+        */
+
         self.reset_possible();
-        while self.remove(&mut rng) {}
+        let mut count = 0;
+        println!("Remove {count} .. begin:");
+        while self.remove(&mut rng) {
+            count += 1;
+            println!("Removed {count}");
+        }
+
+        count
     }
 
     /// Remove an item