Ejemplo n.º 1
0
        private void Button_Click_A(object sender, RoutedEventArgs e)
        {
            int[,] board = MainWindow.initialization();
            if (MainWindow.checkTableRow(board) != null)
            {
                int[] i = MainWindow.checkTableRow(board);
                foreach (TextBox tb in grid.Children)
                {
                    if (tb.Name == "textBox" + i[0].ToString() + i[1].ToString())
                    {
                        tb.Background = Brushes.PaleVioletRed;
                        return;
                    }
                }
            }
            if (MainWindow.checkTableColomn(board) != null)
            {
                int[] l = MainWindow.checkTableColomn(board);
                foreach (TextBox tb in grid.Children)
                {
                    if (tb.Name == "textBox" + l[0].ToString() + l[1].ToString())
                    {
                        tb.Background = Brushes.PaleVioletRed;
                        return;
                    }
                }
            }
            if (MainWindow.checkTableSquere(board) != null)
            {
                int[] l = MainWindow.checkTableSquere(board);
                foreach (TextBox tb in grid.Children)
                {
                    if (tb.Name == "textBox" + l[0].ToString() + l[1].ToString())
                    {
                        tb.Background = Brushes.PaleVioletRed;
                        return;
                    }
                }
            }
            A_Star_Sudoku astar = new A_Star_Sudoku();
            List <Node>   steps_and_solution = astar.solve_A_Star(board);

            if (stop)
            {
                System.Threading.Thread thread = new Thread(new ParameterizedThreadStart(ThreadMethod));
                thread.Name = "UpdateThread";
                thread.Start(steps_and_solution);
            }

            return;
        }
Ejemplo n.º 2
0
        private void Button_Click_DFS(object sender, RoutedEventArgs e)
        {
            int[,] board = MainWindow.initialization();
            if (MainWindow.checkTableRow(board) != null)
            {
                int[] i = MainWindow.checkTableRow(board);
                foreach (TextBox tb in grid.Children)
                {
                    if (tb.Name == "textBox" + i[0].ToString() + i[1].ToString())
                    {
                        tb.Background = Brushes.PaleVioletRed;
                        return;
                    }
                }
            }
            if (MainWindow.checkTableColomn(board) != null)
            {
                int[] l = MainWindow.checkTableColomn(board);
                foreach (TextBox tb in grid.Children)
                {
                    if (tb.Name == "textBox" + l[0].ToString() + l[1].ToString())
                    {
                        tb.Background = Brushes.PaleVioletRed;
                        return;
                    }
                }
            }
            if (MainWindow.checkTableSquere(board) != null)
            {
                int[] l = MainWindow.checkTableSquere(board);
                foreach (TextBox tb in grid.Children)
                {
                    if (tb.Name == "textBox" + l[0].ToString() + l[1].ToString())
                    {
                        tb.Background = Brushes.PaleVioletRed;
                        return;
                    }
                }
            }

            // Pocetak algoritma
            DFS_Sudoku  dfs = new DFS_Sudoku();
            List <Node> steps_and_solution = dfs.solve_BFS(board);   // u matricu resenje smestamo rezultat

            /*  int[,] resenje = steps_and_solution[steps_and_solution.Count - 1].getState();
             * int r = 0;
             * int c = 0;
             *
             * foreach (TextBox tb in grid.Children)
             * {
             *    if (c == 9)
             *    {
             *        c = 0;
             *        r++;
             *        tb.Text = resenje[r, c].ToString();
             *        c++;
             *    }
             *    else
             *    {
             *        tb.Text = resenje[r, c].ToString();
             *        c++;
             *    }
             * }*/
            if (stop)
            {
                System.Threading.Thread thread = new Thread(new ParameterizedThreadStart(ThreadMethod));
                thread.Name = "UpdateThread";
                thread.Start(steps_and_solution);
            }
            return;
        }