Переглянути джерело

Process pairs on row/column (if possible).

Steve Thielemann 10 місяців тому
батько
коміт
e44123af10
1 змінених файлів з 50 додано та 2 видалено
  1. 50 2
      src/main.rs

+ 50 - 2
src/main.rs

@@ -289,8 +289,56 @@ impl Sudoku {
                                     }
                                     // Ok, these aren't the ones to save, so:
                                     let rpos = g.items[remove as usize];
-                                    self.possible[rpos as usize].take(&values[0]);
-                                    self.possible[rpos as usize].take(&values[1]);
+                                    if self.possible[rpos as usize].take(&values[0]).is_some() {
+                                        found_something = true;
+                                    };
+                                    if self.possible[rpos as usize].take(&values[1]).is_some() {
+                                        found_something = true;
+                                    };
+                                }
+
+                                // 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
+                                    let column = xy(gpos).0;
+
+                                    vpos = 0;
+                                    for z in self.possible[gpos as usize].iter() {
+                                        values[vpos] = *z;
+                                        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() {
+                                            found_something = true;
+                                        };
+                                        if self.possible[pos(column, remove) as usize].take(&values[1]).is_some() {
+                                            found_something = true;
+                                        };
+                                    }
+                                }
+                                if xy(gpos).1 == xy(fpos).1 {
+                                    // Matching Y - process row
+                                    let row = xy(gpos).1;
+
+                                    vpos = 0;
+                                    for z in self.possible[gpos as usize].iter() {
+                                        values[vpos] = *z;
+                                        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() {
+                                            found_something = true;
+                                        };
+                                        if self.possible[pos(remove, row) as usize].take(&values[1]).is_some() {
+                                            found_something = true;
+                                        };
+                                    }
                                 }
                             }
                         }