Ejemplo n.º 1
0
        public void TestGenerate1()
        {
            const int number = 10;

            int[][,] result = new int[number][, ];

            SudokuFounctionLibrary.generate(number, ref result);

            for (int i = 0; i < number; i++)
            {
                Assert.AreEqual(true, TestValid(result[i]));
            }
        }
Ejemplo n.º 2
0
        public void TestGenerateUnique()
        {
            int[][,] result = null;
            const int number = 1;
            const int lower  = 50;
            const int upper  = 55;
            const int size   = 9;

            int[] keys = new int[number];
            int[] digs = new int[number];
            SudokuFounctionLibrary.generate(number, lower, upper, true, ref result);

            // test
            for (int i = 0; i < number; i++)
            {
                int[,] puzzle = result[i];

                // 测试挖空数目
                int count = 0;

                for (int j = 0; j < size; j++)
                {
                    for (int k = 0; k < size; k++)
                    {
                        if (puzzle[j, k] == 0)
                        {
                            count++;
                        }
                    }
                }
                digs[i] = count;
                bool real     = (count <= upper && count >= lower);
                bool expected = true;

                Assert.AreEqual(expected, real);

                // 测试唯一解
                Solver s = new Solver(puzzle);
                s.Solve();
                real = s.IsUniqueSolution();

                //Assert.AreEqual(expected, real);

                /*Table t = new Table();
                 * t.creat(puzzle);
                 * keys[i] = t.solve();
                 * Assert.AreEqual(1, keys[i]);*/
            }
            //Assert.AreEqual(1, keys[0]);
            //Assert.AreEqual(true, digs[0] <= upper && digs[0] >= lower);
        }
Ejemplo n.º 3
0
        public void TestFillSuccess1()
        {
            int[,] grid = new int[, ] {
                { 2, 6, 8, 4, 7, 3, 9, 5, 1 },
                { 3, 4, 1, 9, 6, 5, 2, 7, 8 },
                { 7, 9, 5, 8, 1, 2, 3, 6, 4 },
                { 5, 7, 4, 6, 2, 1, 8, 3, 9 },
                { 1, 3, 9, 5, 4, 8, 6, 2, 7 },
                { 8, 2, 6, 3, 9, 7, 4, 1, 5 },
                { 9, 1, 7, 2, 8, 6, 5, 4, 3 },
                { 6, 8, 3, 1, 5, 4, 7, 9, 2 },
                { 4, 5, 2, 7, 3, 9, 1, 8, 6 }
            };

            Assert.AreEqual(true, SudokuFounctionLibrary.FillSuccess(grid, 2, 2));
        }
Ejemplo n.º 4
0
        public void TestGenerateFillList1()
        {
            var list1 = SudokuFounctionLibrary.GenerateFillList();
            var list2 = SudokuFounctionLibrary.GenerateFillList();

            Assert.AreEqual(false, list1.SequenceEqual(list2));

            var expect = new List <int> {
                1, 2, 3, 4, 5, 6, 7, 8, 9
            };

            Assert.AreEqual(false, expect.SequenceEqual(list1));
            Assert.AreEqual(false, expect.SequenceEqual(list2));

            list1.Sort();
            list2.Sort();

            Assert.AreEqual(true, expect.SequenceEqual(list1));
            Assert.AreEqual(true, expect.SequenceEqual(list2));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 测试一个数独的有效性
        /// </summary>
        public bool TestValid(int[,] puzzle)
        {
            const int SIZE = 9;

            for (int i = 0; i < SIZE; i++)
            {
                for (int j = 0; j < SIZE; j++)
                {
                    var real = SudokuFounctionLibrary.FillSuccess(puzzle, i, j);
                    if (real == false)
                    {
                        using (System.IO.StreamWriter outputfile =
                                   new System.IO.StreamWriter(@"ErrorLog.txt", true))
                        {
                            outputfile.Write("i = {0}, j = {1};", i, j);
                        }
                        return(false);
                    }
                }
            }
            return(true);
        }
Ejemplo n.º 6
0
        private void BeginGameButton_Click(object sender, RoutedEventArgs e)
        {
            if (EasyComboBoxItem.IsSelected)
            {
                mode = 1;
            }
            if (MediumComboBoxItem.IsSelected)
            {
                mode = 2;
            }
            if (HardComboBoxItem.IsSelected)
            {
                mode = 3;
            }

            SudokuFounctionLibrary.generate(1, mode, ref GUIpuzzle);

            NavigationWindow window = new NavigationWindow();

            window.Source = new Uri("Gaming.xaml", UriKind.Relative);
            window.Height = 750;
            window.Width  = 600;
            window.Show();
        }