private void AttemptToSubmit(byte submission)
        {
            if (selectedCell == null)
            {
                return;
            }

            selectedCell.Background = ShouldColorCellAt(selectedRow, selectedColumn) ? Brushes.LightGray : Brushes.Transparent;

            if (solution[selectedRow, selectedColumn] == submission)
            {
                // Submission success.
                SetCell(selectedCell, submission);

                statusLeft.Content = $"Successfully placed a {submission}.";

                selectedCell = null;

                if (sudoku.IsSolved())
                {
                    MessageBox.Show("🎉 Congratulations 🎉\nYou've solved the Sudoku!", "Sudoku solved!", MessageBoxButton.OK, MessageBoxImage.Information);
                    statusLeft.Content = $"Congratulations! You've solved the Sudoku 🎉";
                }
            }
            else
            {
                // Submission failed.
                selectedCell.Background = Brushes.Pink;
                selectedCell.Content    = submission == 0 ? " " : submission.ToString();

                statusLeft.Content = $"Nope! That {submission} doesn't go there. Try something else.";
            }
        }
Exemple #2
0
        public void ButtonPressed(byte input)
        {
            int row    = int.Parse(selectedButton.Name[3] + "");
            int column = int.Parse(selectedButton.Name[4] + "");

            if (input == 0)
            {
                Stat.Text = "N***a, you cannot put 0 in a sudoku";
                return;
            }

            ISudoku tmpSudo = sudo.Clone();

            tmpSudo.SetNumberAt(column, row, input);

            if (tmpSudo.IsSolvable())
            {
                sudokuArray[column, row] = (int)input;
                selectedButton.Content   = input;
                selectedButton.IsEnabled = false;
                sudo.SetNumberAt(column, row, input);
                Stat.Text = "GJ N***A";
                if (sudo.IsSolved())
                {
                    Stat.Text = "YOU DONE DID N***A, FRIED CHICKEN FOR EVERYONE!";
                }
                return;
            }
            else
            {
                Stat.Text = "N***A YOU STUPID AS HELL";
                return;
            }
        }
Exemple #3
0
        public bool IsSolved(int[,] sudokuBoard)
        {
            List <ISudoku> algorithms = new List <ISudoku>()
            {
                new BruteForce(_sudokuBlock),
                //additional algorithms can be submitted here. (Demonstrates the interface.)
            };

            var startState  = _sudokuState.State(sudokuBoard);                                       //Once file is loaded generate state
            var finishState = _sudokuState.State(algorithms.FirstOrDefault().IsSolved(sudokuBoard)); //Next state is when the algorithm runs and the ending board is shown.

            //If Sudoku board is not solved the loop will keep running otherwise print out the ending State.
            while (!_sudokuState.SudokuSolved(sudokuBoard) && startState != finishState)
            {
                startState = finishState;
                for (int i = 0; i < algorithms.Count; i++)
                {
                    ISudoku a = algorithms[i];
                    finishState = _sudokuState.State(a.IsSolved(sudokuBoard));
                }
            }

            return(_sudokuState.SudokuSolved(sudokuBoard));
        }