示例#1
0
        public Solver(PuzzleNine puzzle)
        {
            // make sure that it is creating a new object and not passing a reference
            _puzzleObject = puzzle.CopyPuzzle();
            _puzzleObject.ResetCoordinates();
            _puzzleObject.UpdateCoordinates();

            findPossibleAnswers();
            SinglePosition();
        }
示例#2
0
        public SetupPuzzle(int difficultySelection)
        {
            puzzleSolution = new PuzzleNine();

            //copy the puzzle
            setupPuzzle = puzzleSolution.CopyPuzzle();

            // take numbers out of the puzzle
            buildPuzzle(difficultySelection);

            setupPuzzle.UpdateCoordinates();
        }
示例#3
0
        public void SinglePosition()
        {
            // Goal of first solver:
            // Find where there can be only one answer, add that answer to the puzzle,
            // update the rows and columns that are affected in the canidate list

            // keep track of times that singlePosition was run

            bool flag = true;

            while (flag)
            {
                // need to not be working off coord count
                int firstCount = _blankCoordinates.Count;
                foreach (SingleCanidate canidate in _canidateList)
                {
                    // add to the puzzle where there is only one possible answer
                    int[]      xyCoords        = canidate.Coordinates;
                    List <int> possibleAnswers = canidate.PossibleAnswers;

                    if (possibleAnswers.Count == 1)
                    {
                        // get the only answer and add to the puzzle
                        _puzzleObject._puzzle[xyCoords[0], xyCoords[1]] = possibleAnswers[0];
                        //add to counter
                        _difficulty.singlePosition++;
                    }
                }

                //trash the old canidate list and start fresh
                _canidateList = new List <SingleCanidate>();

                // update canidate list
                _puzzleObject.UpdateCoordinates();
                updateAvailableCoordinates();

                if (_blankCoordinates.Count == 0)
                {
                    // the puzz is solved
                    _difficulty.isSolvedSingPos = true;
                    flag = false;
                }
                else if (firstCount == _blankCoordinates.Count)
                {
                    //compare to the count of canidate list at the begining to see if there was a change.
                    //This means that this method of solving the puzzle has reached it's limit.
                    _difficulty.isSolvedSingPos = false;
                    flag = false;
                }
                else
                {
                    //find the possible answers
                    findPossibleAnswers();
                }

                // if there are more canidates, run it again
                if (_canidateList.Count > 0)
                {
                    //_difficulty.isSolvedSingPos = false;
                    SinglePosition();
                }
            }
        }