Преглед на файлове

Use AnyBoard::load_ksudoku, it has defaults.

Steve Thielemann преди 4 месеца
родител
ревизия
9b6ca50ea8
променени са 2 файла, в които са добавени 20 реда и са изтрити 15 реда
  1. 10 10
      sudoku/src/ksudoku.rs
  2. 10 5
      sudoku/src/sudoku.rs

+ 10 - 10
sudoku/src/ksudoku.rs

@@ -203,7 +203,7 @@ mod tests {
 
         let size = (result.order as f64).sqrt() as u8;
         let mut board = AnyBoard::new(size);
-        let load = board.load_from_tld('b', '_', &result.puzzle);
+        let load = board.load_ksudoku(&result.puzzle); 
         assert!(load.is_ok());
 
         // Ok, puzzle is loaded!
@@ -234,7 +234,7 @@ mod tests {
 
         let size = (result.order as f64).sqrt() as u8;
         let mut board = AnyBoard::new(size);
-        let load = board.load_from_tld('b', '_', &result.puzzle);
+        let load = board.load_ksudoku(&result.puzzle);
         assert!(load.is_ok());
 
         // Ok, puzzle is loaded!
@@ -273,7 +273,7 @@ mod tests {
 
         let size = (result.order as f64).sqrt() as u8;
         let mut board = AnyBoard::new(size);
-        let load = board.load_from_tld('b', '_', &result.puzzle);
+        let load = board.load_ksudoku(&result.puzzle);
         assert!(load.is_ok());
 
         // Ok, puzzle is loaded!
@@ -324,9 +324,9 @@ mod tests {
 
         let size = (result.order as f64).sqrt() as u8;
         let mut board = AnyBoard::new(size);
-        let load = board.load_from_tld('b', '_', &result.puzzle);
+        let load = board.load_ksudoku(&result.puzzle);
         let mut solution = AnyBoard::new(size);
-        let solution_load = solution.load_from_tld('b', '_', &result.solution);
+        let solution_load = solution.load_ksudoku(&result.solution);
         assert!(load.is_ok());
         assert!(solution_load.is_ok());
 
@@ -379,10 +379,10 @@ mod tests {
 
         let size = (result.order as f64).sqrt() as u8;
         let mut board = AnyBoard::new(size);
-        let load = board.load_from_tld('b', '_', &result.puzzle);
+        let load = board.load_ksudoku(&result.puzzle);
         assert!(load.is_ok());
         let mut solution = AnyBoard::new(size);
-        let solution_load = solution.load_from_tld('b', '_', &result.solution);
+        let solution_load = solution.load_ksudoku(&result.solution);
         assert!(solution_load.is_ok());
 
         // Ok, puzzle is loaded!
@@ -448,10 +448,10 @@ mod tests {
 
         let size = (result.order as f64).sqrt() as u8;
         let mut board = AnyBoard::new(size);
-        let load = board.load_from_tld('b', '_', &result.puzzle);
+        let load = board.load_ksudoku(&result.puzzle);
         assert!(load.is_ok());
         let mut solution = AnyBoard::new(size);
-        let solution_load = solution.load_from_tld('b', '_', &result.solution);
+        let solution_load = solution.load_ksudoku(&result.solution);
         assert!(solution_load.is_ok());
 
         // Ok, puzzle is loaded!
@@ -524,6 +524,6 @@ mod tests {
         let mut solver = AnySolver::new_from(&board);
         assert!(solver.solve_logic());
         assert_eq!(solver.board, solution);
-        
+
     }
 }

+ 10 - 5
sudoku/src/sudoku.rs

@@ -3,13 +3,8 @@ use crate::bits::*;
 use crate::group::*;
 
 use strum::IntoEnumIterator;
-
-// use std::collections::HashSet;
 use std::string::String;
-
 extern crate rand_chacha;
-// use rand::prelude::*;
-// use rand::distributions::{Distribution, Uniform};
 use rand::seq::SliceRandom;
 use rand_chacha::rand_core::SeedableRng;
 use rand_chacha::ChaCha20Rng;
@@ -133,6 +128,16 @@ impl AnyBoard {
         self.board[index]
     }
 
+    /// Load from ksudoku file
+    /// - uses load_from_tld
+    pub fn load_ksudoku(&mut self, s: &str) -> Result<(), Box<dyn error::Error>> {
+        self.load_from_tld('b', '_', s)
+    }
+
+    pub fn save_ksudoku(&self) -> String {
+        self.save_to_tld('b', '_')
+    }
+    
     /// Load puzzle from string (top,left) going down.
     pub fn load_from_tld(
         &mut self,