コード例 #1
0
        private void check_Click(object sender, EventArgs e)
        {
            ConvertTextBoxToInt(false, null);// It Will Initialize Sudoku Matrix
            bool CantSolve = false;

            for (int Row = 0; Row < 9; Row++)
            {
                for (int Column = 0; Column < 9; Column++)
                {
                    if (!OperationsSeq.Is_Save(new Point(Row, Column), OperationsSeq.sudoku[Row, Column]))
                    {
                        CantSolve  = true;
                        Valid.Text = "False Sudoku";
                        break;
                    }
                }
                if (CantSolve)
                {
                    break;
                }
            }
            if (!CantSolve)
            {
                Valid.Text = "True Sudoku";
            }
        }
コード例 #2
0
        /*
         *              Radwan
         * Should Call After Initialize suduku matrix in OperationsSeq
         * Take Row and Col That Will Begin Cheeck From Them
         * in first call should called SolveSudoku(0, 0) ;
         * To begain From Start Of Matrix
         *
         */
        public virtual bool SolveSudoku(int lastRow, int lastCol)
        {
            Point point = new Point();

            int [,] s = OperationsSeq.sudoku;
            point     = Find_Unassigned_Location(lastRow, lastCol);
            if (!point.Flage)
            {
                return(true);
            }
            for (int i = 1; i <= size; i++)
            {
                if (OperationsSeq.Is_Save(point, i)) // Check if can Put This Number in this Box Or Not
                {
                    OperationsSeq.sudoku[point.row, point.col] = i;
                    if (SolveSudoku(point.row, point.col)) // recursive statment
                    {
                        return(true);
                    }
                    OperationsSeq.sudoku[point.row, point.col] = 0;
                }
            }
            return(false);
        }