Explorar el Código

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 hace 4 meses
padre
commit
d08dba8490
Se han modificado 1 ficheros con 25 adiciones y 2 borrados
  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...");