瀏覽代碼

Updated, use logic then brute force.

If we're loading from a file, check to make sure the solution
there matches what we found, otherwise display it.
Bugz 3 月之前
父節點
當前提交
d08dba8490
共有 1 個文件被更改,包括 25 次插入2 次删除
  1. 25 2
      src/main.rs

+ 25 - 2
src/main.rs

@@ -71,7 +71,7 @@ fn main() {
         let result = load_ksudoku(filename.to_path_buf());
         if result.is_err() {
             println!("Failed to load file: {}", filename.display());
-            // Safe to unrap error.
+            // Safe to unwrap error.
             println!("{:?}", result.unwrap_err());
             return;
         }
@@ -104,19 +104,42 @@ fn main() {
 
         let result = solution.load_from_tld('b', '_', &puzzle.solution);
         if result.is_err() {
-            panic!("Failed loading result: {}", result.unwrap_err());
+            panic!("Failed loading solution: {}", result.unwrap_err());
         }
 
         if args.get_flag("brute") {
             let (found, solutions) = s.brute_force_solver(2);
             println!("Solutions: {}", found);
             if found != 0 {
+                solutions[0].display();
                 if solutions[0] != solution {
                     println!("The solution doesn't match the one from the file:");
                     solution.display();
                 }
             }
         } else {
+            let mut solver = AnySolver::new_from(&s);
+
+            while solver.solve_logic() {};
+
+            if solver.board.complete() {
+                println!("Solution:");
+                solver.board.display();
+            } else {
+                println!("This is as far as logic could get us:");
+                solver.board.display();
+                println!("Using brute-force.");
+                let (count, boards) = solver.board.brute_force_solver(2);
+                if count == 1 {
+                    boards[0].display();
+                    if boards[0] != solution {
+                        println!("The solution doesn't match the one from the file:");
+                        solution.display();
+                    }
+                } else {
+                    println!("Found {} solutions.", count);
+                }
+            }
             /*
             while s.solve(debug) {
                 println!("Try it again...");