|
@@ -265,24 +265,17 @@ impl Sudoku {
|
|
|
if self.possible[gpos as usize].is_subset(&self.possible[fpos as usize])
|
|
|
{
|
|
|
// Ok, they have the same values!
|
|
|
- println!(
|
|
|
- "Pair found! {} {}: {} {:?} and {} {:?}",
|
|
|
- gidx,
|
|
|
- fidx,
|
|
|
- gpos,
|
|
|
- xy(gpos),
|
|
|
- fpos,
|
|
|
- xy(fpos)
|
|
|
- );
|
|
|
// Ok, remove the items in the pair from the cell.
|
|
|
// Don't touch the gpos/fpos records. Keep those!
|
|
|
- let mut values: [u8; 2] = [0,0];
|
|
|
+ let mut values: [u8; 2] = [0, 0];
|
|
|
let mut vpos = 0;
|
|
|
for z in self.possible[gpos as usize].iter() {
|
|
|
values[vpos] = *z;
|
|
|
- vpos +=1;
|
|
|
+ vpos += 1;
|
|
|
}
|
|
|
|
|
|
+ let mut pair_removed = false;
|
|
|
+
|
|
|
for remove in 0..SIZE {
|
|
|
if (gidx == remove) || (fidx == remove) {
|
|
|
continue;
|
|
@@ -291,12 +284,26 @@ impl Sudoku {
|
|
|
let rpos = g.items[remove as usize];
|
|
|
if self.possible[rpos as usize].take(&values[0]).is_some() {
|
|
|
found_something = true;
|
|
|
+ pair_removed = true;
|
|
|
};
|
|
|
if self.possible[rpos as usize].take(&values[1]).is_some() {
|
|
|
found_something = true;
|
|
|
+ pair_removed = true;
|
|
|
};
|
|
|
}
|
|
|
|
|
|
+ if pair_removed {
|
|
|
+ println!(
|
|
|
+ "Pair found! {} {}: {} {:?} and {} {:?} !",
|
|
|
+ gidx,
|
|
|
+ fidx,
|
|
|
+ gpos,
|
|
|
+ xy(gpos),
|
|
|
+ fpos,
|
|
|
+ xy(fpos)
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
// Check the x's and y's to see if we can also process a row/column too.
|
|
|
if xy(gpos).0 == xy(fpos).0 {
|
|
|
// Matching X - process column
|
|
@@ -305,16 +312,22 @@ impl Sudoku {
|
|
|
vpos = 0;
|
|
|
for z in self.possible[gpos as usize].iter() {
|
|
|
values[vpos] = *z;
|
|
|
- vpos +=1;
|
|
|
+ vpos += 1;
|
|
|
}
|
|
|
for remove in 0..SIZE {
|
|
|
if (remove == xy(gpos).1) || (remove == xy(fpos).1) {
|
|
|
continue;
|
|
|
}
|
|
|
- if self.possible[pos(column, remove) as usize].take(&values[0]).is_some() {
|
|
|
+ if self.possible[pos(column, remove) as usize]
|
|
|
+ .take(&values[0])
|
|
|
+ .is_some()
|
|
|
+ {
|
|
|
found_something = true;
|
|
|
};
|
|
|
- if self.possible[pos(column, remove) as usize].take(&values[1]).is_some() {
|
|
|
+ if self.possible[pos(column, remove) as usize]
|
|
|
+ .take(&values[1])
|
|
|
+ .is_some()
|
|
|
+ {
|
|
|
found_something = true;
|
|
|
};
|
|
|
}
|
|
@@ -326,16 +339,22 @@ impl Sudoku {
|
|
|
vpos = 0;
|
|
|
for z in self.possible[gpos as usize].iter() {
|
|
|
values[vpos] = *z;
|
|
|
- vpos +=1;
|
|
|
+ vpos += 1;
|
|
|
}
|
|
|
for remove in 0..SIZE {
|
|
|
if (remove == xy(gpos).0) || (remove == xy(fpos).0) {
|
|
|
continue;
|
|
|
}
|
|
|
- if self.possible[pos(remove, row) as usize].take(&values[0]).is_some() {
|
|
|
+ if self.possible[pos(remove, row) as usize]
|
|
|
+ .take(&values[0])
|
|
|
+ .is_some()
|
|
|
+ {
|
|
|
found_something = true;
|
|
|
};
|
|
|
- if self.possible[pos(remove, row) as usize].take(&values[1]).is_some() {
|
|
|
+ if self.possible[pos(remove, row) as usize]
|
|
|
+ .take(&values[1])
|
|
|
+ .is_some()
|
|
|
+ {
|
|
|
found_something = true;
|
|
|
};
|
|
|
}
|