/// <summary> /// 随机填充小九宫格数据 /// </summary> /// <param name="sudoku"></param> private void AddZNum() { RandomNum randomNum = new RandomNum(); int[] value = new int[9] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; int[] randomNumArr = randomNum.GetRandomNum(value, 9); for (int i = 5, z = 8; i >= 3; i--) { for (int j = 5; j >= 3 && z >= 0; j--, z--) { sudoku[j, i] = randomNumArr[z]; } } }
/// <summary> /// 添加Z1方块的数据 /// </summary> /// <param name="sudoku"></param> public void AddZ1Num() { sudoku[0, 0] = firstNum; RandomNum randomNum = new RandomNum(); int[] value = new int[8] { 1, 2, 3, 4, 6, 7, 8, 9 }; int[] randomNumArr = randomNum.GetRandomNum(value, 8); for (int i = 2, z = 7; i >= 0; i--) { for (int j = 2; j >= 0 && z >= 0; j--, z--) { sudoku[j, i] = randomNumArr[z]; } } }
/// <summary> /// 挖空 /// </summary> public void scoop() { int[] temps = new int[81]; for (int i = 0; i < 81; i++) { temps[i] = i; } RandomNum rn = new RandomNum(); Random r = new Random(); int[] result = rn.GetRandomNum(temps, r.Next(35, 60)); for (int i = 0; i < result.Length; i++) { Y[result[i] / 9].Add(sudokuB[result[i] / 9, result[i] % 9]); X[result[i] % 9].Add(sudokuB[result[i] / 9, result[i] % 9]); Z[result[i] / 9 / 3 * 3 + result[i] % 9 / 3].Add(sudokuB[result[i] / 9, result[i] % 9]); sudokuB[result[i] / 9, result[i] % 9] = 0; } }