addSetExits function

dynamic addSetExits(
  1. List<Cell> row,
  2. List<Cell> nextRow,
  3. Function random
)

internal function randomly add an exit to each set

Implementation

addSetExits(List<Cell> row, List<Cell> nextRow, Function random) {
  // Randomly add bottom exit for each set
  List<dynamic> setsInRow = [];

  groupBy(row, (item) => (item).set!.round()).forEach((key, value) {
    setsInRow.add(value);
  });

  setsInRow.forEach((set) {
    List<dynamic> exits =
        sampleSize(set, (random() * set.length).ceil().toDouble(), random);
    exits.forEach((exit) {
      //if (exit) {
      Cell below = nextRow[exit.x.round()];
      exit.bottom = false;
      below.top = false;
      below.set = exit.set;
      //}
    });
  });

  return setsInRow;
}