示例#1
0
        private void checkSolutionsCountToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (S.isSolved())
            {
                return;
            }

            Sudoku.SolutionStepList L = S.ComputePossibleSteps(Sudoku.SolveMethods.All);

            S.RenderMessage(L.Count().ToString() + " possible deductions!", "Press any key to continue", false);
        }
示例#2
0
        public void GenerateGame()
        {
            if (PlaySound != null)
            {
                PlaySound(SudokuSound.Stop);
            }

            UseTemplate();

            int trials_counter = 0;

            int trials_max = 100;

            SolveMethods M = SolveMethods.All;

            // Generating a list of filled squares

            List <Point> L = new List <Point>();

            for (int i = 0; i < 9; i++)
            {
                for (int j = 0; j < 9; j++)
                {
                    if (s[j, i] > 0)
                    {
                        L.Add(new Point(i, j));
                    }
                }
            }

            int n;

            for (n = 0; n < 55;)
            {
                int index = R.Next(L.Count);

                int x = L[index].X;

                int y = L[index].Y;

                int temp = s[x, y];

                if (temp != 0)
                {
                    s[x, y] = 0;

                    Sudoku S2 = CreateCopy();

                    int solutionStepsCount = S2.ComputePossibleSteps(M).Count();

                    bool range0Ok = ((n > 35) && (solutionStepsCount > 25));

                    bool range1Ok = ((n > 15) && (solutionStepsCount > 25));

                    bool range2Ok = n < 16;

                    bool solutionStepsCountOk = range0Ok || range1Ok || range2Ok;

                    if (solutionStepsCountOk)
                    {
                        bool isSolvable = S2.SolvePuzzle(M);

                        if (isSolvable)
                        {
                            L.RemoveAt(index);

                            n++;

                            trials_counter = 0;
                        }
                        else
                        {
                            s[x, y] = temp;
                        }
                    }
                    else
                    {
                        s[x, y] = temp;
                    }
                    trials_counter++;
                }

                if (trials_counter > trials_max)
                {
                    break;
                }
            }

            ScrambleGame();

            for (int i = 0; i < 9; i++)
            {
                for (int j = 0; j < 9; j++)
                {
                    if (s[i, j] == 0)
                    {
                        f[i, j] = 0;
                    }
                    else
                    {
                        f[i, j] = 1;
                    }
                }
            }

            //  SetGameString("XX7XXX5XXXXXX4XX3XXXX832X9X8XXXXX4XXX294X586XXX6XXXXX7X5X364XXXX7XX5XXXXXX3XXX2XX");

            EnumeratePossibilities();

            starttime = DateTime.Now;

            DisplayMessage = false;

            if (PlaySound != null)
            {
                PlaySound(SudokuSound.NewPuzzle);
            }

            if (RequestRepaint != null)
            {
                RequestRepaint();
            }
        }