private void Initialize() { // initialize square constraint blocks for (int i = 0; i < m_squareConstraint.Length; i++) { m_squareConstraint[i] = new ConstraintBlock(); } }
private void GeneratePopulation() { for (int i = 0; i < Sudoku.DIMENSION; i++) { for (int j = 0; j < Sudoku.DIMENSION; j++) { if (!m_is_given[i, j]) { // find the square constraint block it belongs to and the possible values it is allowed to have ConstraintBlock currentBlock = m_squareConstraint[(i / 3) * SUBGRID_DIMENSION + (j / 3)]; int[] possibleNums = new int[currentBlock.NumOfPermissibles]; currentBlock.Permissibles.CopyTo(possibleNums); // Generate a random index of the possible int random = ((m_random.Next() % currentBlock.NumOfPermissibles)); m_puzzle[i, j] = possibleNums[random]; currentBlock.RemovePermissible(possibleNums[random]); } } } }