bootstrap method

List<Cell> bootstrap(
  1. LevelConfig level
)

Implementation

List<Cell> bootstrap(LevelConfig level) {
  final cells = <Cell>[];

  final List<int> guaranteedPairs = [];
  if (level.difficulty == 1) {
    return level1;

  } else if (level.difficulty == 2) {
    return level2;

  }

  int gpIndex = 0;

  for (int r = 0; r < level.rows; r++) {
    for (int c = 0; c < level.cols; c++) {
      final idx = r * level.cols + c;
      final bool shouldFill = r >= (level.rows - level.initialFilledRows);

      int? value;
      if (shouldFill) {
        if (gpIndex < guaranteedPairs.length) {
          value = guaranteedPairs[gpIndex++];
        } else {
          value = LevelPresets.randomAllowed(level.allowedNumbers, _rng);
        }
      }
      cells.add(Cell(index: idx, row: r, col: c, value: value));
    }
  }

  return cells;
}