|
@@ -77,7 +77,7 @@ impl Sudoku {
|
|
|
|
|
|
for ch in s.chars() {
|
|
|
if ch != blank {
|
|
|
- self.set(x,y, (ch as u8-start_ch as u8) +1);
|
|
|
+ self.set(x, y, (ch as u8 - start_ch as u8) + 1);
|
|
|
}
|
|
|
y += 1;
|
|
|
if y >= WIDTH {
|
|
@@ -95,21 +95,21 @@ impl Sudoku {
|
|
|
|
|
|
for ch in s.chars() {
|
|
|
if ch != blank {
|
|
|
- self.set(xy(i).0, xy(i).1, (ch as u8-start_ch as u8) +1);
|
|
|
+ self.set(xy(i).0, xy(i).1, (ch as u8 - start_ch as u8) + 1);
|
|
|
}
|
|
|
i += 1;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- pub fn save_to_tld(&self, mut start_ch:char, blank: char) -> String {
|
|
|
+ pub fn save_to_tld(&self, mut start_ch: char, blank: char) -> String {
|
|
|
let mut result = String::new();
|
|
|
result.reserve(MAX_SIZE as usize);
|
|
|
- start_ch = (start_ch as u8 -1) as char;
|
|
|
- let mut x:u8 = 0;
|
|
|
- let mut y:u8 = 0;
|
|
|
+ start_ch = (start_ch as u8 - 1) as char;
|
|
|
+ let mut x: u8 = 0;
|
|
|
+ let mut y: u8 = 0;
|
|
|
|
|
|
for i in 0..MAX_SIZE {
|
|
|
- if self.board[pos(x,y) as usize] == 0 {
|
|
|
+ if self.board[pos(x, y) as usize] == 0 {
|
|
|
result.push(blank);
|
|
|
} else {
|
|
|
result.push((start_ch as u8 + self.board[i as usize]) as char);
|
|
@@ -117,16 +117,16 @@ impl Sudoku {
|
|
|
y += 1;
|
|
|
if y >= WIDTH {
|
|
|
y = 0;
|
|
|
- x +=1;
|
|
|
+ x += 1;
|
|
|
}
|
|
|
}
|
|
|
result
|
|
|
}
|
|
|
|
|
|
- pub fn save_to_tlr(&self, mut start_ch:char, blank: char) -> String {
|
|
|
+ pub fn save_to_tlr(&self, mut start_ch: char, blank: char) -> String {
|
|
|
let mut result = String::new();
|
|
|
result.reserve(MAX_SIZE as usize);
|
|
|
- start_ch = (start_ch as u8 -1) as char;
|
|
|
+ start_ch = (start_ch as u8 - 1) as char;
|
|
|
for i in 0..MAX_SIZE {
|
|
|
if self.board[i as usize] == 0 {
|
|
|
result.push(blank);
|
|
@@ -139,19 +139,19 @@ impl Sudoku {
|
|
|
pub fn set(&mut self, x: u8, y: u8, value: u8) {
|
|
|
self.board[pos(x, y) as usize] = value;
|
|
|
// Ok, update the possible
|
|
|
- let mut g = for_row(y);
|
|
|
+ let mut g = for_row(y);
|
|
|
// g.for_row(x, y);
|
|
|
for g in g.items {
|
|
|
// remove value from these sets.
|
|
|
self.possible[g as usize].take(&value);
|
|
|
}
|
|
|
- g = for_column(x);
|
|
|
+ g = for_column(x);
|
|
|
// g.for_column(x, y);
|
|
|
for g in g.items {
|
|
|
// remove value from these sets.
|
|
|
self.possible[g as usize].take(&value);
|
|
|
}
|
|
|
- g = for_cell(which_cell(x,y));
|
|
|
+ g = for_cell(which_cell(x, y));
|
|
|
// g.for_block(x, y);
|
|
|
for g in g.items {
|
|
|
// remove value from these sets.
|
|
@@ -169,13 +169,13 @@ impl Sudoku {
|
|
|
// remove value from these sets.
|
|
|
self.possible[g as usize].take(&value);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
g.for_column(x, y);
|
|
|
for g in g.items {
|
|
|
// remove value from these sets.
|
|
|
self.possible[g as usize].take(&value);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
g.for_block(x, y);
|
|
|
for g in g.items {
|
|
|
// remove value from these sets.
|
|
@@ -184,7 +184,6 @@ impl Sudoku {
|
|
|
self.possible[pos(x, y) as usize].clear();
|
|
|
}
|
|
|
|
|
|
-
|
|
|
pub fn display(&self) {
|
|
|
println!("╔═══╦═══╦═══╗");
|
|
|
for y in 0..WIDTH {
|