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); } } } } }
protected override void OperateOn(SudokuModel model) { // We could look at all 2^N possible sets on all 3N of the model's regions, // but it is more efficient to only use the // possiblity set of each cell, and isolate that set on each intersecting region. for (var row = 0; row < model.Size; ++row) { for (var col = 0; col < model.Size; ++col) { if (!model.IsSolved(col, row)) { foreach (var region in model.GetIntersectingRegions(col, row)) { var checkedIter = GetCheckedIteration(region); if (checkedIter < model.GetLastChangedIterRegion(region.Type, region.I)) { _checkedIteration[region] = checkedIter; IsolateSet(model.GetPossibilitySetCell(col, row), region, model); } } } } } }
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; }