Ejemplo n.º 1
0
        // Generate
        private void btnGenerate_Click(object sender, System.EventArgs e)
        {
            Sudoku s = new Sudoku();

            byte[,] d = GetData();
            s.Data    = d;

            Cursor oldCursor = Cursor.Current;

            Cursor.Current = Cursors.WaitCursor;
            tbHistory.AppendText("-------------------------------\r\n");
            var result = s.Generate((int)numSpots.Value);

            if (result.Item2)
            {
                tbHistory.AppendText(String.Format("Sudoku generated succesfully after {0} tries\r\n", result.Item1));
                tbHistory.AppendText("Sudoku with " + numSpots.Value + " spots\r\n");

                d = s.Data;
                SetData(d);
            }
            else
            {
                tbHistory.AppendText(String.Format("Sudoku not found after {0} tries.\r\n Press generate to try again.\r\n", result.Item1));
            }

            Cursor.Current = oldCursor;
        }
Ejemplo n.º 2
0
    public static string Generate()
    {
        SudokuModel.Sudoku sudoku = new SudokuModel.Sudoku();
        sudoku.Data = new byte[, ] {
            { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 0, 0, 0, 0 }
        };

        while (!(sudoku.Generate(30).second&& sudoku.Solve()))
        {
        }
        char[] rawData = new char[81];
        for (int i = 0; i < 9; i++)
        {
            for (int j = 0; j < 9; j++)
            {
                rawData[i * 9 + j] = sudoku.Data[i, j].ToString()[0];
            }
        }

        return(new string(rawData));
    }
Ejemplo n.º 3
0
        public static void Main()
        {
            while (true)
            {
                Sudoku s = new Sudoku();

                s.Data = new byte[, ] {
                    { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                    { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                    { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                    { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                    { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                    { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                    { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                    { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                    { 0, 0, 0, 0, 0, 0, 0, 0, 0 }
                };

                s.Generate(30);
                if (s.Solve())
                {
                    Console.Write("\"");
                    for (int i = 0; i < 9; i++)
                    {
                        for (int j = 0; j < 9; j++)
                        {
                            Console.Write(s.Data[i, j]);
                        }
                    }
                    Console.WriteLine("\",");
                }
            }
        }
Ejemplo n.º 4
0
        // Generate
        private void btnGenerate_Click(object sender, System.EventArgs e)
        {
            Sudoku s = new Sudoku();
            byte[,] d = GetData();
            s.Data = d;

            Cursor oldCursor = Cursor.Current;
            Cursor.Current = Cursors.WaitCursor;
            tbHistory.AppendText("-------------------------------\r\n");
            var result = s.Generate((int)numSpots.Value);
            if(result.Item2)
            {
                tbHistory.AppendText(String.Format("Sudoku generated succesfully after {0} tries\r\n", result.Item1));
                tbHistory.AppendText("Sudoku with " + numSpots.Value + " spots\r\n");

                d = s.Data;
                SetData(d);
            }
            else
            {
                tbHistory.AppendText(String.Format("Sudoku not found after {0} tries.\r\n Press generate to try again.\r\n", result.Item1));
            }

            Cursor.Current = oldCursor;
        }