コード例 #1
0
        private static List <Sudoku> IterSolver(Sudoku curr)
        {
            if (curr.Status == SolveStatus.Solved)
            {
                return new List <Sudoku> {
                           curr
                }
            }
            ;
            var ret   = new List <Sudoku>();
            var coord = curr.NextUnsolved();

            foreach (var item in curr.GetCandidate(coord.Item1, coord.Item2))
            {
                var tmp = new Sudoku(curr);

                tmp[coord.Item1, coord.Item2] = item;
                switch (tmp.Status)
                {
                case Sudoku.SolveStatus.Solved:
                    ret.Add(tmp);
                    break;

                case Sudoku.SolveStatus.UnSolved:
                    ret.AddRange(IterSolver(tmp));
                    break;

                case Sudoku.SolveStatus.NoSolution:
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
            return(ret);
        }