コード例 #1
0
        private static SudokuBoard Solve(SudokuBoard board, bool willGuess = true)
        {
            int solveState = 1;

            while (true)
            {
                switch (solveState)
                {
                case 0:
                    if (board.Changed == true)
                    {
                        if (board.Finished == true)
                        {
                            if (board.Guess == true)
                            {
                                if (board.SimpleTest() == false)
                                {
                                    goto case 7;
                                }
                            }
                            return(board);
                        }
                        board.Changed          = false;
                        board.ChangedExcluding = false;
                        if (solveState == 1)
                        {
                            solveState++;
                        }
                        else
                        {
                            solveState = 1;
                        }
                        break;
                    }
                    else if (solveState > 3 && board.ChangedExcluding == true)
                    {
                        if (solveState == 4)
                        {
                            board.ChangedExcluding = false;
                            solveState++;
                        }
                        else
                        {
                            solveState = 4;
                        }
                        break;
                    }
                    else
                    {
                        solveState++;
                        break;
                    }

                case 1:
                    board.SimpleHorisontalExclusion();
                    goto case 0;

                case 2:
                    board.SimpleVerticalExclusion();
                    goto case 0;

                case 3:
                    board.SimpleSquareExclusion();
                    goto case 0;

                case 4:
                    board.ChangedExcluding = false;
                    board.HorizontalExclusionOnOnlyPositionsThatFit();
                    goto case 0;

                case 5:
                    board.VerticalExclusionOnOnlyPositionsThatFit();
                    goto case 0;

                case 6:
                    board.SquareExclusionOnOnlyPositionsThatFit();
                    goto case 0;

                case 7:
                    if (willGuess)
                    {
                        board.MakeGuess();
                        goto case 0;
                    }
                    else
                    {
                        goto case 8;
                    }

                case 8:
                    return(board);
                }
            }
        }