Exemplo n.º 1
0
        /*
         * Returns the unset variable with the fewest remaining possible values.
         */
        private static Variable GetNextVariable(SudokuGrid puzzleGrid)
        {
            Variable result = null;

            foreach (var v in puzzleGrid.GetAllUnsetVariables())
            {
                if (result == null || v.PossibleValuesCount < result.PossibleValuesCount)
                {
                    result = v;
                }
            }

            return(result);
        }
Exemplo n.º 2
0
        /*
         * Initialize the possible values for each variable using the known
         * initial values.
         */
        private static SudokuGrid InitializeVariables(Grid <int> initialValues)
        {
            var puzzleGrid = new SudokuGrid(initialValues);

            foreach (var unset in puzzleGrid.GetAllUnsetVariables())
            {
                foreach (var constraint in puzzleGrid.GetSetNeighbors(unset))
                {
                    unset.RemovePossibleValue(constraint.Value);
                }
            }

            return(puzzleGrid);
        }