|
@@ -21,13 +21,47 @@ impl fmt::Display for UnsupportedGroup {
|
|
|
|
|
|
impl error::Error for UnsupportedGroup {}
|
|
|
|
|
|
+/*
|
|
|
+What I want from load_ksudoku:
|
|
|
+
|
|
|
+ - Puzzle string
|
|
|
+ - Solution string (so I can validate it/check my code)
|
|
|
+ - specific-type & type (combined as a string is ok - I think)
|
|
|
+ - order (as a number)
|
|
|
+
|
|
|
+I get values (the puzzle), I also need solution.
|
|
|
+
|
|
|
+Having order will allow me to use AnyBoard::new(order) and load it up.
|
|
|
+
|
|
|
+Currently, it loads, and will fail if it isn't Plain, sudoku, 9.
|
|
|
+I'm not sure what future ksudoku puzzles I want to support, so I'd like to
|
|
|
+have that as flexible as possible.
|
|
|
+
|
|
|
+save_ksudoku, would need to save those fields as well...
|
|
|
+ */
|
|
|
+
|
|
|
+ pub struct Ksudoku {
|
|
|
+ pub puzzle :String,
|
|
|
+ pub solution: String,
|
|
|
+ pub specific_type: String,
|
|
|
+ pub puzzle_type: String,
|
|
|
+ pub order: u8,
|
|
|
+ }
|
|
|
+
|
|
|
pub fn load_ksudoku(filename: std::path::PathBuf) -> Result<String, Box<dyn error::Error>> {
|
|
|
let fh = File::open(filename)?;
|
|
|
let buffer = BufReader::new(fh);
|
|
|
let parser = EventReader::new(buffer);
|
|
|
+
|
|
|
+ let mut element_name: String = String::new();
|
|
|
+
|
|
|
// I'm interested in values and (maybe) solution
|
|
|
- let mut values: String = String::from("");
|
|
|
- let mut element_name: String = String::from("");
|
|
|
+ let mut values: String = String::new();
|
|
|
+ let mut _solution = String::new();
|
|
|
+ let mut _specific_type = String::new();
|
|
|
+ let mut _puzzle_type = String::new();
|
|
|
+ let mut _order = String::new();
|
|
|
+ let mut _order_value: u8 = 0;
|
|
|
|
|
|
for e in parser {
|
|
|
match e {
|
|
@@ -49,6 +83,19 @@ pub fn load_ksudoku(filename: std::path::PathBuf) -> Result<String, Box<dyn erro
|
|
|
|
|
|
let blank = String::new();
|
|
|
|
|
|
+ _specific_type = attrs.get(&"specific-type".to_string()).unwrap_or(&blank).clone();
|
|
|
+ _puzzle_type = attrs.get(&"type".to_string()).unwrap_or(&blank).clone();
|
|
|
+ _order = attrs.get(&"order".to_string()).unwrap_or(&blank).clone();
|
|
|
+
|
|
|
+ if !_order.is_empty() {
|
|
|
+ let r = _order.parse::<u8>();
|
|
|
+ if r.is_ok() {
|
|
|
+ _order_value = r.unwrap();
|
|
|
+ } else {
|
|
|
+ // Failed to convert order to u8...
|
|
|
+ return Err(Box::new(r.unwrap_err()));
|
|
|
+ }
|
|
|
+ }
|
|
|
// Format in specific order here.
|
|
|
let expected = format!(
|
|
|
"{}-{}-{}",
|
|
@@ -71,6 +118,9 @@ pub fn load_ksudoku(filename: std::path::PathBuf) -> Result<String, Box<dyn erro
|
|
|
if element_name == "values" {
|
|
|
values = text.clone();
|
|
|
}
|
|
|
+ if element_name == "solution" {
|
|
|
+ _solution = text.clone();
|
|
|
+ }
|
|
|
}
|
|
|
Err(e) => {
|
|
|
return Err(Box::new(e));
|