浏览代码

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;
+                                        };
+                                    }
                                 }
                             }
                         }