Exemplo n.º 1
0
 //copy constructor
 public PossibilitySet(PossibilitySet toCopy)
 {
     foreach (HashSet <int> set in toCopy)
     {
         Add(new HashSet <int>(set));
     }
 }
Exemplo n.º 2
0
            //Make this instance a deep copy of toCopy
            private void copy(gridSquare toCopy)
            {
                this.x = toCopy.x;
                this.y = toCopy.y;

                this.knownValue = toCopy.knownValue;
                for (int i = 1; i <= 9; ++i)
                {
                    this.possibilities[i] = toCopy.possibilities[i];
                }
                this.possList = new List <int>(toCopy.possList);

                this.solveType = toCopy.solveType;
                this.setList   = new PossibilitySet(toCopy.setList);
            }
Exemplo n.º 3
0
            //initialize/return to freshly constructed state
            public void setToInitialState()
            {
                knownValue = 0;

                for (int i = 1; i <= 9; ++i)
                {
                    possibilities[i] = true;
                }
                possList = new List <int> {
                    1, 2, 3, 4, 5, 6, 7, 8, 9
                };

                setList = new PossibilitySet(new HashSet <int>(possList), maxSetLength);

                solveType = SudokuGrid.SolveType.Unsolved;
            }
Exemplo n.º 4
0
        //scan for and use aligned matched sets to eliminate other possibilities
        private bool matchedSetEliminationScan()
        {
            bool madeChanges = false;

            //scan for sets in box, in col, in row

            //check by each section type
            foreach (iterateBy iterType in Enum.GetValues(typeof(iterateBy)))
            {
                //for each section:
                for (int s = 0; s < 9; s++)
                {
                    if (unsolvedValues[(int)iterType, s].Count == 0)
                    {
                        continue;                         //section already completely solved
                    }
                    PossibilitySet sectionPossibilities = new PossibilitySet(unsolvedValues[(int)iterType, s], 8);
                    foreach (HashSet <int> set in sectionPossibilities)
                    {
                        HashSet <int> matchIndices = new HashSet <int>();
                        //for each element in section
                        for (int e = 0; e < 9; e++)
                        {
                            bool match = true;
                            for (int i = 1; i <= 9; i++)
                            {
                                if (!set.Contains(i) && iterCoords(iterType, s, e).isPossible(i))
                                {
                                    match = false;
                                    break;
                                }
                            }
                            if (match)
                            {
                                matchIndices.Add(e);
                            }
                        }
                        if (matchIndices.Count == set.Count)
                        {
                            bool tempMadeChanges = false;
                            //values in set can ONLY be in squares that contain only values in set
                            //so eliminate set values all other places in section
                            for (int eE = 0; eE < 9; eE++)
                            {
                                if (matchIndices.Contains(eE))
                                {
                                    continue;
                                }

                                foreach (int i in set)
                                {
                                    tempMadeChanges |= iterCoords(iterType, s, eE).eliminate(i);
                                }
                            }
                            if (tempMadeChanges)
                            {
                                madeChanges = true;
                            }
                        }
                    }
                }
            }
            return(madeChanges);
        }