コード例 #1
0
ファイル: Solver.cs プロジェクト: arnoutellis/sudokusolver
        /// <summary>
        /// Once possible values are determined, the SolvingAlgorithm is used to set each square
        /// and set the square value.
        /// A max of 100 attempts are made
        /// </summary>
        private void SetValues()
        {
            var sa = new SolvingAlgorithm();
            int[] solutions;
            int iterationCount = 0;

            while(iterationCount < 100 & _sudokuMap.OutstandingBoxes > 0)
            {
                foreach(Square sq in _sudokuMap.SudokuSquareMap)
                {
                    solutions = sa.SolveSquare(sq,
                                           _sudokuMap.GetCol(sq.XLoc),
                                           _sudokuMap.GetRow(sq.YLoc),
                                           _sudokuMap.GetQuadrant(sq.XLoc, sq.YLoc));

                    //The SolveSquare returns an array which contains 2 cells.
                    //The first indicates whether the square could be solved (-1 or 1)
                    //and the second indicates the value of the square if it could be solved.

                    if(solutions[0] == 1)
                        _sudokuMap.SolveSquare(sq.XLoc, sq.YLoc, solutions[1]);
                }
                iterationCount++;
            }
        }
コード例 #2
0
ファイル: Solver.cs プロジェクト: arnoutellis/sudokusolver
        private void CalculatePossibleValues()
        {
            var sa = new SolvingAlgorithm();
            foreach(var s in _sudokuMap.SudokuSquareMap)
            {

                if(!s.IsSet && !s.IsNative)
                    s.AddPossibleValue(
                        sa.ReturnPossibleValues(
                            _sudokuMap.GetCol(s.XLoc),
                            _sudokuMap.GetRow(s.YLoc),
                            _sudokuMap.GetQuadrant(s.XLoc, s.YLoc)
                        )
                    );

            }
        }