Пример #1
0
        private void NewSudoku()
        {
            myCanvas.Children.Clear();

            GridMaker.AddRandomDigitsToGrid(ref grid, 81 - level);
            gridDrafter = new GridDrafter(grid);

            gridDrafter.CreateGridForSudoku(myCanvas);

            solved = new int[81];
            Array.Copy(grid, solved, 81);

            Solver.TrySolveSudoku(solved);

            gridDrafter.AddInputsForUser(myCanvas, grid);

            TextBox[] tbs = gridDrafter.GetInputs();
            foreach (TextBox tb in tbs)
            {
                if (tb != null)
                {
                    tb.KeyDown += Inputs_KeyDown;
                }
            }

            NextSudoku.IsEnabled  = false;
            CheckInputs.IsEnabled = true;
            SolveButton.IsEnabled = true;
            PointsText.Content    = $"Points: {points}";
        }
Пример #2
0
        private bool SolveGrid()
        {
            TextBox[] tbs = gridDrafter.GetInputs();

            for (int i = 0; i < 81; i++)
            {
                if (tbs[i] != null && tbs[i].Text.ToString().Length != 0)
                {
                    if (Solver.CheckNoConflict(grid, (int)(i / 9), (i % 9), Int32.Parse(tbs[i].Text.ToString())))
                    {
                        grid[i] = Int32.Parse(tbs[i].Text.ToString());
                    }
                    else
                    {
                        return(false);
                    }
                }
            }

            myCanvas.Children.Clear();

            if (Solver.TrySolveSudoku(grid))
            {
                gridDrafter = new GridDrafter(grid);

                gridDrafter.CreateGridForSudoku(myCanvas);
                gridDrafter.AddInputsForUser(myCanvas, grid);
            }
            else
            {
                return(false);
            }

            return(true);
        }
Пример #3
0
 private void MakeEmptySudoku()
 {
     NewEmptySudokuButton.IsEnabled = false;
     SolveButton.IsEnabled          = true;
     ErrorText.Content = "";
     GridMaker.AddRandomDigitsToGrid(ref grid, 0);
     gridDrafter = new GridDrafter(grid);
     gridDrafter.CreateGridForSudoku(myCanvas);
     gridDrafter.AddInputsForUser(myCanvas, grid);
 }
Пример #4
0
        private void SolveButton_Click(object sender, RoutedEventArgs e)
        {
            myCanvas.Children.Clear();
            Solver.TrySolveSudoku(grid);

            gridDrafter = new GridDrafter(grid);

            gridDrafter.CreateGridForSudoku(myCanvas);
            gridDrafter.AddInputsForUser(myCanvas, grid);

            CheckInputs.IsEnabled = false;
            SolveButton.IsEnabled = false;
            NextSudoku.IsEnabled  = true;
        }