|
@@ -43,6 +43,7 @@ impl error::Error for GameLoadError {}
|
|
|
/// Currently board limited to < 8x8 boards because of u8 limit. (8x8 say WAT?!)
|
|
|
/// Also limited on display (we handle 5X5 boards A-Y). Anything > 5, we would have
|
|
|
/// figure out something else for display output.
|
|
|
+/// - Should I be doing a Vec<Result<u8>> ? Some/None?
|
|
|
#[derive(Debug, Clone, Eq, PartialEq)]
|
|
|
pub struct AnyBoard {
|
|
|
/// Size of board (cell width)
|
|
@@ -54,6 +55,7 @@ pub struct AnyBoard {
|
|
|
/// Actual board data
|
|
|
/// 0 = blank (not 1!)
|
|
|
/// 1..=width+1 = values
|
|
|
+ /// Maybe Option<u8> instead and get rid of our off by one issue?
|
|
|
pub board: Vec<u8>,
|
|
|
}
|
|
|
|
|
@@ -529,6 +531,11 @@ impl AnyBoard {
|
|
|
X values don't change or move.
|
|
|
Uppercase letter gets swapped with lower case.
|
|
|
|
|
|
+ (1,0) = a
|
|
|
+ (0,1) = A
|
|
|
+ (2,1) = c
|
|
|
+ (1,2) = C
|
|
|
+
|
|
|
╔═══╦═══╦═══╗
|
|
|
║Xab║dfi║lp ║
|
|
|
║AXc║ehk║o ║
|
|
@@ -550,9 +557,16 @@ impl AnyBoard {
|
|
|
// (x1,y1) = lower case
|
|
|
// (x2,y2) = upper case
|
|
|
|
|
|
+ // The last position on the board, there's nothing for us to do.
|
|
|
+ // So we don't include it in our for loop. (self.width-1)
|
|
|
+
|
|
|
for idx in 0..self.width - 1 {
|
|
|
// println!("idx: {idx}");
|
|
|
for pass in 0..2 {
|
|
|
+ // pass 0: values that are 🡷🡵 to x1 + 1 and y2 +1.
|
|
|
+ // pass 1: values that are 🡷🡵 to the midpoint.
|
|
|
+
|
|
|
+ // Start x1,y1 and x2,y2 at same midpoint.
|
|
|
x1 = idx;
|
|
|
x2 = idx;
|
|
|
y1 = idx;
|
|
@@ -563,10 +577,13 @@ impl AnyBoard {
|
|
|
y2 += 1;
|
|
|
} else {
|
|
|
if idx == 0 {
|
|
|
+ // We'd be out of bounds (of board and of u8)
|
|
|
break;
|
|
|
}
|
|
|
+ // Move (x1,y1) 🡵
|
|
|
x1 += 1;
|
|
|
y1 -= 1;
|
|
|
+ // Move (x2,y2) 🡷
|
|
|
x2 -= 1;
|
|
|
y2 += 1;
|
|
|
}
|
|
@@ -577,10 +594,13 @@ impl AnyBoard {
|
|
|
(self[(x1, y1)], self[(x2, y2)]) = (self[(x2, y2)], self[(x1, y1)]);
|
|
|
|
|
|
if (y1 == 0) || (x2 == 0) {
|
|
|
+ // We would be moving out of bounds (of board and u8).
|
|
|
break;
|
|
|
}
|
|
|
+ // Move (x1,y1) 🡵
|
|
|
x1 += 1;
|
|
|
y1 -= 1;
|
|
|
+ // Move (x2,y2) 🡷
|
|
|
x2 -= 1;
|
|
|
y2 += 1;
|
|
|
|
|
@@ -622,7 +642,7 @@ impl AnyBoard {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /// Rotate board Clockwise
|
|
|
+ /// Rotate board Clockwise ↻
|
|
|
///
|
|
|
/// Which is same as flip + flip_x.
|
|
|
pub fn rotate_cw(&mut self) {
|
|
@@ -639,7 +659,7 @@ impl AnyBoard {
|
|
|
*/
|
|
|
}
|
|
|
|
|
|
- /// Rotate board Counter-Clockwise
|
|
|
+ /// Rotate board Counter-Clockwise ↺
|
|
|
///
|
|
|
/// Which is flip + flip_y.
|
|
|
pub fn rotate_ccw(&mut self) {
|
|
@@ -966,7 +986,7 @@ pub struct AnySolver {
|
|
|
/// Groups (Rows, Columns, Cells)
|
|
|
pub group: AnyGroup,
|
|
|
// Is this value set in the given cell?
|
|
|
- pub cell_poss: Vec<Flags>,
|
|
|
+ // pub cell_poss: Vec<Flags>,
|
|
|
}
|
|
|
|
|
|
impl AnySolver {
|
|
@@ -981,7 +1001,7 @@ impl AnySolver {
|
|
|
board: AnyBoard::new(board_size),
|
|
|
possible: AnyPossible::new(board_size),
|
|
|
group: AnyGroup::new(board_size),
|
|
|
- cell_poss: vec![default_poss; width as usize * width as usize],
|
|
|
+ // cell_poss: vec![default_poss; width as usize * width as usize],
|
|
|
};
|
|
|
s.reset_possible();
|
|
|
s
|
|
@@ -996,10 +1016,12 @@ impl AnySolver {
|
|
|
board: initial_board.clone(),
|
|
|
possible: AnyPossible::new(initial_board.size),
|
|
|
group: AnyGroup::new(initial_board.size),
|
|
|
+ /*
|
|
|
cell_poss: vec![
|
|
|
default_poss;
|
|
|
initial_board.width as usize * initial_board.width as usize
|
|
|
],
|
|
|
+ */
|
|
|
};
|
|
|
s.reset_possible();
|
|
|
s
|
|
@@ -1063,9 +1085,11 @@ impl AnySolver {
|
|
|
|
|
|
// Tests are run as debug, and this kills things...
|
|
|
// Like the invalid board in validated_board test.
|
|
|
+ /*
|
|
|
let cell_index = self.group.which_cell(x, y);
|
|
|
|
|
|
self.cell_poss[cell_index as usize].set(value as usize - 1, false);
|
|
|
+ */
|
|
|
|
|
|
if finalize {
|
|
|
self.finalize_possible();
|
|
@@ -1088,7 +1112,7 @@ impl AnySolver {
|
|
|
const OUTPUT: bool = false;
|
|
|
|
|
|
if OUTPUT {
|
|
|
- println!("finalize_possible starts");
|
|
|
+ println!("finalize_possible starts");
|
|
|
};
|
|
|
|
|
|
// I might want to save the pair information.
|
|
@@ -1366,7 +1390,7 @@ impl AnySolver {
|
|
|
}
|
|
|
|
|
|
if OUTPUT {
|
|
|
- println!("finalize_possible ends...");
|
|
|
+ println!("finalize_possible ends...");
|
|
|
}
|
|
|
return updated;
|
|
|
|
|
@@ -1803,6 +1827,7 @@ impl AnySolver {
|
|
|
// TOFIX:
|
|
|
// See: AnyPossible's find_value_pos!
|
|
|
|
|
|
+ /*
|
|
|
// Check columns - (of given cell) for logical removes (see logic_test for example)
|
|
|
for value in 0..width {
|
|
|
// Find what columns value is allowed. (in which cells).
|
|
@@ -1843,6 +1868,8 @@ impl AnySolver {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ */
|
|
|
+
|
|
|
if NOISY {
|
|
|
println!("finalize_cell ends...");
|
|
|
}
|
|
@@ -1884,9 +1911,11 @@ impl AnySolver {
|
|
|
let mut default_poss = Flags::new(self.board.width as usize);
|
|
|
default_poss.set_range(0..self.board.width as usize);
|
|
|
|
|
|
+ /*
|
|
|
for x in 0..self.board.width {
|
|
|
self.cell_poss[x as usize] = default_poss.clone();
|
|
|
}
|
|
|
+ */
|
|
|
|
|
|
for y in 0..self.board.width {
|
|
|
for x in 0..self.board.width {
|
|
@@ -1946,9 +1975,11 @@ impl AnySolver {
|
|
|
let mut default_poss = Flags::new(self.board.width as usize);
|
|
|
default_poss.set_range(0..self.board.width as usize);
|
|
|
|
|
|
+ /*
|
|
|
for x in 0..self.board.width {
|
|
|
self.cell_poss[x as usize] = default_poss.clone();
|
|
|
}
|
|
|
+ */
|
|
|
|
|
|
for y in 0..self.board.width {
|
|
|
for x in 0..self.board.width {
|
|
@@ -2050,9 +2081,11 @@ impl AnySolver {
|
|
|
self.board.copy(&backup.board);
|
|
|
self.possible.copy(&backup.possible);
|
|
|
|
|
|
+ /*
|
|
|
for i in 0..backup.cell_poss.len() {
|
|
|
self.cell_poss[i] = backup.cell_poss[i].clone();
|
|
|
}
|
|
|
+ */
|
|
|
// self.cell_poss.copy( backup.cell_poss);
|
|
|
}
|
|
|
|