浏览代码

Updated docs. calling make().

Choking on 25x25 boards.
Steve Thielemann 4 月之前
父节点
当前提交
1095cc63a4
共有 3 个文件被更改,包括 20 次插入18 次删除
  1. 3 1
      src/main.rs
  2. 0 3
      sudoku/src/lib.rs
  3. 17 14
      sudoku/src/sudoku.rs

+ 3 - 1
src/main.rs

@@ -38,8 +38,10 @@ fn main() {
 
     if args.get_flag("make") {
         let size: u8 = *args.get_one::<u8>("size").unwrap();
-        let mut _s = AnyBoard::new(size);
+        let mut s = AnySolver::new(size);
 
+        s.make();
+        s.board.display();
         /*
         s.make();
         let mut p = s.clone();

+ 0 - 3
sudoku/src/lib.rs

@@ -2,6 +2,3 @@ pub mod group;
 pub mod ksudoku;
 pub mod sudoku;
 pub mod bits;
-
-// use crate::group::*;
-// use crate::sudoku::*;

+ 17 - 14
sudoku/src/sudoku.rs

@@ -319,6 +319,9 @@ impl AnyBoard {
         }
     }
 
+    /// Output board as strings.
+    /// - Uses 1-9 (for 9x9), and A-? for others.
+    /// - Used by tests to confirm the board is what we think it should be.
     pub fn to_strings(&self) -> Vec<String> {
         let mut result = Vec::<String>::new();
         let alpha_display = self.width >= 10;
@@ -356,24 +359,22 @@ impl AnyBoard {
         true
     }
 
+    /// Solve by brute force
+    /// - Returns up to max # of solutions.
+    /// - Returns total solutions found, and vector of boards (up to max).
+    /// - Uses brute_force (recursive function) to solve.
     pub fn brute_force_solver(&self, max: u16) -> (u16, Vec<AnyBoard>) {
         let mut workset = self.clone();
         let mut total_solutions: u16 = 0;
         let mut solutions: Vec<AnyBoard> = Vec::new();
         let groups = AnyGroup::new(workset.size);
         solutions.reserve(max as usize);
-        workset.brute_force(&mut total_solutions, &mut solutions, &groups);
 
-        /*
-        if solutions.len() > 0 {
-            println!("*** A Solution:");
-            solutions[0].display();
-            println!("***");
-        }
-        */
+        workset.brute_force(&mut total_solutions, &mut solutions, &groups);
         (total_solutions, solutions)
     }
 
+    /// Recursive brute force solver.
     fn brute_force(
         &mut self,
         total_solutions: &mut u16,
@@ -525,12 +526,6 @@ impl AnyPossible {
         )
     }
 
-    /*
-    How can I find the max size of each display possible item?
-    I'd like to cache the info so I don't re-calc it, and I'd like a pony! :P
-
-     */
-
     /// Format all possible, finding max length.
     /// - Return vec<string> of each item formatted.
     /// - Return max length.
@@ -586,6 +581,7 @@ pub struct AnySolver {
 }
 
 impl AnySolver {
+    /// Construct new solver from given board size. (3,4,5)
     pub fn new(board_size: u8) -> Self {
         let mut s = Self {
             board: AnyBoard::new(board_size),
@@ -596,6 +592,7 @@ impl AnySolver {
         s
     }
 
+    /// Construct new solver from given board.
     pub fn new_from(initial_board: &AnyBoard) -> Self {
         let mut s = AnySolver {
             board: initial_board.clone(),
@@ -606,6 +603,8 @@ impl AnySolver {
         s
     }
 
+    /// Clear out board and possible.
+    /// - group is ok, unless they change the board size.
     pub fn clear(&mut self) {
         let board_size: u8 = self.board.size;
         self.board = AnyBoard::new(board_size);
@@ -740,12 +739,16 @@ impl AnySolver {
         }
     }
 
+    /// Make completed board.
+    /// - uses fill_board (recursive)
     pub fn make(&mut self) {
         let mut rng = ChaCha20Rng::from_entropy();
         self.reset_possible();
         self.fill_board(&mut rng);
     }
 
+    /// Recursively completely fill the board.
+    /// This takes - quite a bit of time - for a 25x25 board.
     fn fill_board(&mut self, rng: &mut ChaCha20Rng) -> bool {
         let backup = self.clone();
         let max_index = self.board.max_index;