Ejemplo n.º 1
0
        public Sudoku getSudoku(Sudoku.DifficultyLevel diffLevel)
        {
            List <int> numbers = new List <int>();

            foreach (int[] list in Cells)
            {
                if (list.Length != 0)
                {
                    numbers.Add(list[0]);
                }
            }
            int[] sudokuNumbers = new int[numbers.Count];
            for (int sectionId = 0; sectionId < Sudoku.SectionCount; sectionId++)
            {
                for (int fieldY = 0; fieldY < Sudoku.SectionRowCount; fieldY++)
                {
                    for (int fieldX = 0; fieldX < Sudoku.SectionRowCount; fieldX++)
                    {
                        int id = sectionId * Sudoku.SectionCount + fieldY * Sudoku.SectionRowCount + fieldX;

                        int rowId = (sectionId / Sudoku.SectionRowCount) * Sudoku.SectionRowCount + fieldY;
                        int colId = sectionId % Sudoku.SectionRowCount * Sudoku.SectionRowCount + fieldX;
                        int value = numbers[rowId * 9 + colId];
                        sudokuNumbers[id] = value;
                    }
                }
            }

            int[] blankedList = blankFields(diffLevel, sudokuNumbers);
            int   empty       = blankedList.Count(i => i == Sudoku.EmptyFieldMarker);

            return(new Sudoku(blankedList));
        }
Ejemplo n.º 2
0
        private void generateButton_Click(object sender, EventArgs e)
        {
            generateButton.IsAccessible = false;
            String origText = generateButton.Text;

            generateButton.Text = "Getting your sudoku, stay put";
            Sudoku.DifficultyLevel diffLevel = (Sudoku.DifficultyLevel)diffLevelComboBox.SelectedValue;
            SudokuPuzzle           generator = SudokuPuzzle.generatePuzzle(9);

            sudoku       = generator.getSudoku(diffLevel);
            solvedSudoku = generator.getSudoku(Sudoku.DifficultyLevel.None);
            sudokuBoardViewController.updateBoardView(sudoku);
            generateButton.IsAccessible = true;
            generateButton.Text         = origText;
        }
Ejemplo n.º 3
0
        private int[] blankFields(Sudoku.DifficultyLevel diffLevel, int[] initialValues)
        {
            int minId         = 0;
            int maxId         = minId + Sudoku.ColumsCount;
            int difflevel     = (int)diffLevel;
            int indexToRemove = 0;

            for (int i = 0; i < (int)diffLevel; i++)
            {
                do
                {
                    indexToRemove = Randomizer.Instance.GetRandomInt(minId, maxId);
                } while (initialValues[indexToRemove] == Sudoku.EmptyFieldMarker);
                minId  = maxId;
                maxId += Sudoku.ColumsCount;
                if (maxId > initialValues.Length)
                {
                    minId = 0;
                    maxId = minId + Sudoku.ColumsCount;
                }
                initialValues[indexToRemove] = Sudoku.EmptyFieldMarker;
            }
            return(initialValues);
        }