Пример #1
0
 public static void EliminateDuplicates(SudokuModel model, int col, int row)
 {
     if (model.IsSolved(col, row)) {
         var value = model.GetValue(col, row);
         foreach (var region in model.GetIntersectingRegions(col, row)) {
             foreach (var other in model.GetCells(region.Type, region.I)) {
                 if (other.Column != col || other.Row != row) {
                     model.Eliminate(other.Column, other.Row, value);
                 }
             }
         }
     }
 }
Пример #2
0
 bool OperateOn(int col, int row, SudokuModel model)
 {
     if (!model.IsSolved(col, row)) {
         // obviously can't eliminate anything in a solved cell.
         // try each int i that is a possibility for the cell, and see if an error results
         foreach (var i in model.GetPossibilitySetCell(col, row).HighBitPositions()) {
             var clone = new SudokuModel(model);
             clone.SetValue(col, row, i);
             _elimStrategy.Run(clone);
             if (clone.IsConsistent()) {
                 continue;
             }
             // If so, we can eliminate that from the original model.
             model.Eliminate(col, row, i);
             return true;
             // return immediately after eliminating something, since
             // this is a slow algorithm, and we want our faster
             // algorithms to see if they make some more eliminations first.
         }
     }
     return false;
 }