internal Region(Puzzle puzzle, SudokuRegion region, int index) { switch (region) { case SudokuRegion.Block: Points = new SPoint[9]; int ix = (index % 3) * 3, iy = (index / 3) * 3; int c = 0; for (int x = ix; x < ix + 3; x++) { for (int y = iy; y < iy + 3; y++) { Points[c++] = new SPoint(x, y); } } break; case SudokuRegion.Row: Points = new SPoint[9]; for (int i = 0; i < 9; i++) { Points[i] = new SPoint(i, index); } break; case SudokuRegion.Column: Points = new SPoint[9]; for (int i = 0; i < 9; i++) { Points[i] = new SPoint(index, i); } break; } Cells = Points.Select(p => puzzle[p]).ToArray(); }
public int EliminateEveryCandidateInRegion(SudokuRegion Region) { int eliminatedTotal = 0; int eliminatedRound = 0; do { eliminatedRound = EliminateCandidatesInRegion(Region); eliminatedTotal += eliminatedRound; }while (eliminatedRound != 0); return(eliminatedTotal); }
public int EliminateCandidatesInRegion(SudokuRegion Region) { int eliminatedTotal = 0; int eliminatedRound = 0; ScopeRegionDelegate ScopeFunction = GetScopeDelegate(Region); int counter = 1; do { List<SudokuCell> scope = ScopeFunction(counter); eliminatedRound = EliminateCandidatesInScope(scope); eliminatedTotal += eliminatedRound; } while (counter++ <= StaticSudoku.Dimension); return eliminatedTotal; }
public int EliminateCandidatesInRegion(SudokuRegion Region) { int eliminatedTotal = 0; int eliminatedRound = 0; ScopeRegionDelegate ScopeFunction = GetScopeDelegate(Region); int counter = 1; do { List <SudokuCell> scope = ScopeFunction(counter); eliminatedRound = EliminateCandidatesInScope(scope); eliminatedTotal += eliminatedRound; }while (counter++ <= StaticSudoku.Dimension); return(eliminatedTotal); }
private ScopeRegionDelegate GetScopeDelegate(SudokuRegion Region) { if (Region == SudokuRegion.Column) { return((ScopeRegionDelegate)_sudokuGrid.GetColumnScope); } else if (Region == SudokuRegion.Row) { return((ScopeRegionDelegate)_sudokuGrid.GetRowScope); } else if (Region == SudokuRegion.Block) { return((ScopeRegionDelegate)_sudokuGrid.GetBlockScope); } else { throw new ArgumentException("The SudokuRegion supplied is not supported."); } }
int FoundNakedMatchingCandidates(List <SudokuCell> matchingGroup, SudokuRegion region, int regionIndex) { List <int> groupValues = matchingGroup[0].Candidates.ToList(); DebugWrite("Found: Naked Matching Candidates! GroupSize=\"{0}\", Region=\"{1} {2}\", Candidates=\"{3}\".", matchingGroup.Count, Enum.GetName(typeof(SudokuRegion), region), regionIndex, StaticSudoku.ArrayToString(groupValues, ",")); SudokuCell cell = matchingGroup[0]; foreach (SudokuCell seen in matchingGroup) { visitedGroups.Add(seen.GridPosition.ToString(), seen.FormatCandidatesString_Compact()); } int totalEliminated = 0; if (InSameRow(matchingGroup)) { List <SudokuCell> rowScope = _sudokuGrid.GetRowScope(cell.Row).Except(matchingGroup).ToList(); totalEliminated += RemoveCandidatesValues(groupValues, rowScope); } else if (InSameColumn(matchingGroup)) { List <SudokuCell> columnScope = _sudokuGrid.GetColumnScope(cell.Column).Except(matchingGroup).ToList(); totalEliminated += RemoveCandidatesValues(groupValues, columnScope); } if (InSameBlock(matchingGroup)) { List <SudokuCell> blockScope = _sudokuGrid.GetBlockScope(cell.Block).Except(matchingGroup).ToList(); totalEliminated += RemoveCandidatesValues(groupValues, blockScope); } return(totalEliminated); }
/// <summary>Initializes all column regions.</summary> protected void InitializeColumnRegions(int size2) { for (var column = 0; column < size2; column++) { var region = new SudokuRegion(SudokuRegionType.Column); Regions.Add(region); for (var height = 0; height < size2; height++) { region.Add(Grid[height, column]); } } }
/// <summary>Initializes all sub square regions.</summary> protected void InitializeSubSquareRegions(int size) { for (var xSub = 0; xSub < size; xSub++) { for (var ySub = 0; ySub < size; ySub++) { var region = new SudokuRegion(SudokuRegionType.SubSquare); Regions.Add(region); for (var x = 0; x < size; x++) { for (var y = 0; y < size; y++) { region.Add(Grid[xSub * size + x, ySub * size + y]); } } } } }
/// <summary>Initializes all row regions.</summary> protected void InitializeRowRegions(int size2) { for (int row = 0; row < size2; row++) { var region = new SudokuRegion(SudokuRegionType.Row); Regions.Add(region); for (int width = 0; width < size2; width++) { region.Add(Grid[row, width]); } } }
private ScopeRegionDelegate GetScopeDelegate(SudokuRegion Region) { if (Region == SudokuRegion.Column) return (ScopeRegionDelegate)_sudokuGrid.GetColumnScope; else if (Region == SudokuRegion.Row) return (ScopeRegionDelegate)_sudokuGrid.GetRowScope; else if (Region == SudokuRegion.Block) return (ScopeRegionDelegate)_sudokuGrid.GetBlockScope; else throw new ArgumentException("The SudokuRegion supplied is not supported."); }
public List<SudokuCell> GetRegionScope(SudokuRegion Region, int Index) { return GetScopeDelegate(Region).Invoke(Index); }
public int EliminateEveryCandidateInRegion(SudokuRegion Region) { int eliminatedTotal = 0; int eliminatedRound = 0; do { eliminatedRound = EliminateCandidatesInRegion(Region); eliminatedTotal += eliminatedRound; } while (eliminatedRound != 0); return eliminatedTotal; }
int FoundNakedMatchingCandidates(List<SudokuCell> matchingGroup, SudokuRegion region, int regionIndex) { List<int> groupValues = matchingGroup[0].Candidates.ToList(); DebugWrite("Found: Naked Matching Candidates! GroupSize=\"{0}\", Region=\"{1} {2}\", Candidates=\"{3}\".", matchingGroup.Count, Enum.GetName(typeof(SudokuRegion),region), regionIndex, StaticSudoku.ArrayToString(groupValues,",")); SudokuCell cell = matchingGroup[0]; foreach(SudokuCell seen in matchingGroup) { visitedGroups.Add(seen.GridPosition.ToString(),seen.FormatCandidatesString_Compact()); } int totalEliminated = 0; if(InSameRow(matchingGroup)) { List<SudokuCell> rowScope = _sudokuGrid.GetRowScope(cell.Row).Except(matchingGroup).ToList(); totalEliminated += RemoveCandidatesValues(groupValues, rowScope); } else if(InSameColumn(matchingGroup)) { List<SudokuCell> columnScope = _sudokuGrid.GetColumnScope(cell.Column).Except(matchingGroup).ToList(); totalEliminated += RemoveCandidatesValues(groupValues, columnScope); } if(InSameBlock(matchingGroup)) { List<SudokuCell> blockScope = _sudokuGrid.GetBlockScope(cell.Block).Except(matchingGroup).ToList(); totalEliminated += RemoveCandidatesValues(groupValues, blockScope); } return totalEliminated; }
public List <SudokuCell> GetRegionScope(SudokuRegion Region, int Index) { return(GetScopeDelegate(Region).Invoke(Index)); }