Algorithm.scramble constructor

Algorithm.scramble({
  1. int n = 20,
})

Generates an Algorithm with n random moves.

Implementation

factory Algorithm.scramble({
  int n = 20,
}) {
  final moves = <Move>[];
  const colors = Color.values;

  var move = Move.random();
  moves.add(move);

  for (var i = 1; i < n; i++) {
    final a = move;

    do {
      move = Move.random();
    } while (move.color == a.color || move.color == colors[a.color.index]);

    moves.add(move);
  }

  return Algorithm(moves: moves);
}