Esempio n. 1
0
        /// <summary>
        /// Make New Sudoku Grid
        /// </summary>
        /// <returns></returns>
        public int[,] Make()
        {
            _Grid = new int[_GridNum, _GridNum];
            for (int i = 0; i < _GridNum / _BoxNum; i++) {
                int row = i*_BoxNum;
                int[] nums = new int[_GridNum];
                nums = RandomMethods.UniqueRange(1, _GridNum+1);
                for (int j = 0; j < _BoxNum; j++)
                {
                    for (int k = 0; k < _BoxNum; k++)
                    {
                        _Grid[row + j, row + k] = nums[j * _BoxNum + k];
                    }
                }

            }

            if (_Solve(_Grid))
            {
                return _Grid;
            }
            else
            {
                return null;
            }
;
        }
Esempio n. 2
0
        /// <summary>
        /// Remove K amount of places from grid.
        /// </summary>
        /// <param name="K"></param>
        /// <param name="grid"></param>
        /// <returns></returns>
        public int[,] RemoveKPlaces(int K,int[,] grid) {

            if (grid == null) { return null; }

            int[] nums = new int[_GridNum * _GridNum];
            nums = RandomMethods.UniqueRange(0, nums.Length);

            for (int i = 0; i < K; i++)
            {
                int row = nums[i] / _GridNum;
                int col = nums[i] % _GridNum;
                grid[row, col] = 0;
            }

            return grid;

        }