Esempio n. 1
0
        private void CreateSudokuGrid(Sudoku sudoku, int[,] sudokuArray)
        {
            dgv_Sudoku.Font   = new Font("Calibri", 21);
            dgv_Sudoku.Width  = sudoku.fieldsPerRowAmount * 50 + 3;
            dgv_Sudoku.Height = sudoku.fieldsPerRowAmount * 50 + 3;
            this.Width        = sudoku.fieldsPerRowAmount * 50 + 2 + 190;
            this.Height       = sudoku.fieldsPerRowAmount * 50 + 2 + 90;
            for (int i = 0; i < sudoku.fieldsPerRowAmount; i++)
            {
                dgv_Sudoku.Columns.Add(i.ToString(), i.ToString());
                dgv_Sudoku.Columns[i].Width = 50;
                dgv_Sudoku.Rows.Add();
                dgv_Sudoku.Rows[i].Height = 50;
            }

            var colorList   = CreateBackColorList();
            var colorAmount = 1;

            if (!sudoku.randomBoxFormation)
            {
                colorAmount = sudoku.boxPerRowAmount - 1;
            }

            for (int x = 0; x < sudoku.fieldsPerRowAmount; x++)
            {
                for (int y = 0; y < sudoku.fieldsPerRowAmount; y++)
                {
                    dgv_Sudoku[x, y].Style.BackColor = colorList[sudoku.GetBoxNumberOfCoordinate(new int[2] {
                        x, y
                    }) % colorAmount];
                    dgv_Sudoku[x, y].Style.Alignment = DataGridViewContentAlignment.MiddleCenter;

                    if (sudokuArray[x, y] != 0)
                    {
                        dgv_Sudoku[x, y].ReadOnly        = true;
                        dgv_Sudoku[x, y].Style.ForeColor = Color.DarkGray;
                        dgv_Sudoku[x, y].Value           = sudokuArray[x, y];
                    }
                    else
                    {
                        if (showMarks)
                        {
                            dgv_Sudoku[x, y].Value = String.Join(", ", fieldArray[x, y]);
                        }
                        dgv_Sudoku[x, y].Style.Font     = new Font("Calibri", 10);
                        dgv_Sudoku[x, y].Style.WrapMode = DataGridViewTriState.True;
                    }
                }
            }
            btn_Highlight.Enabled = showMarks;
            btn_Mark.Visible      = !showMarks;
            btn_RuleOut.Visible   = showMarks;
        }
Esempio n. 2
0
        private string GetFieldCode(Sudoku sudoku, int[] coordinate)
        {
            var coordinateString = $"{coordinate[0]}.{coordinate[1]}";
            var visibleNumber    = sudoku.GetIntegerOfIncompleteArray(coordinate);

            if (visibleNumber == 0)
            {
                visibleNumber = sudoku.GetIntegerOfFilledInArray(coordinate);
            }
            var    solutionNumber   = sudoku.GetIntegerOfCompleteArray(coordinate);
            string isReadOnlyString = DetermineIfFieldIsReadOnly(sudoku, coordinate).ToString();
            var    boxID            = sudoku.GetBoxNumberOfCoordinate(coordinate);

            return($"{coordinateString},{visibleNumber},{solutionNumber},{isReadOnlyString},{boxID}");
        }
Esempio n. 3
0
        private void CreateSudokuGrid()
        {
            dgv_Sudoku.Font   = new Font("Calibri", 21);
            dgv_Sudoku.Width  = CurrentSudoku.fieldsPerRowAmount * 50 + 3;
            dgv_Sudoku.Height = CurrentSudoku.fieldsPerRowAmount * 50 + 3;
            this.Width        = CurrentSudoku.fieldsPerRowAmount * 50 + 2 + 190;
            this.Height       = CurrentSudoku.fieldsPerRowAmount * 50 + 2 + 90;
            for (int i = 0; i < CurrentSudoku.fieldsPerRowAmount; i++)
            {
                dgv_Sudoku.Columns.Add(i.ToString(), i.ToString());
                dgv_Sudoku.Columns[i].Width = 50;
                dgv_Sudoku.Rows.Add();
                dgv_Sudoku.Rows[i].Height = 50;
            }

            var colorList   = CreateBackColorList();
            var colorAmount = 1;

            if (!CurrentSudoku.randomBoxFormation)
            {
                colorAmount = CurrentSudoku.boxPerRowAmount - 1;
            }

            for (int x = 0; x < CurrentSudoku.fieldsPerRowAmount; x++)
            {
                for (int y = 0; y < CurrentSudoku.fieldsPerRowAmount; y++)
                {
                    dgv_Sudoku[x, y].Style.BackColor = colorList[CurrentSudoku.GetBoxNumberOfCoordinate(new int[2] {
                        x, y
                    }) % colorAmount];
                    dgv_Sudoku[x, y].Style.Alignment = DataGridViewContentAlignment.MiddleCenter;

                    if (CurrentSudoku.SudokuIncompleteArray[x, y] != 0)
                    {
                        dgv_Sudoku[x, y].ReadOnly        = true;
                        dgv_Sudoku[x, y].Style.ForeColor = Color.DarkGray;
                        dgv_Sudoku[x, y].Value           = CurrentSudoku.SudokuIncompleteArray[x, y];
                    }
                    else
                    {
                        if (CurrentSudoku.SudokuFilledInArray[x, y] != 0)
                        {
                            dgv_Sudoku[x, y].Value = CurrentSudoku.SudokuFilledInArray[x, y];
                        }
                    }
                }
            }
        }
Esempio n. 4
0
        public static string ConvertSudokuIntoSeed(Sudoku sudoku)
        {
            var completeArray   = sudoku.GetCopyOfCompleteSudokuArray();
            var incompleteArray = sudoku.SudokuIncompleteArray;
            var fieldSeedList   = new List <string>();

            for (int x = 0; x < completeArray.GetLength(0); x++)
            {
                for (int y = 0; y < completeArray.GetLength(1); y++)
                {
                    var s = $"{Convert.ToChar(64 + incompleteArray[x, y])}{Convert.ToChar(64 + completeArray[x, y])}{Convert.ToChar(64 + sudoku.GetBoxNumberOfCoordinate(new int[2] { x, y }))}";
                    fieldSeedList.Add(s);
                }
            }

            var fieldSeed = String.Join(".", fieldSeedList);
            var gridSeed  = $"{sudoku.rating}";

            return($"{gridSeed}|{fieldSeed}");
        }