generateScrambleMegaminx method

String generateScrambleMegaminx(
  1. int random
)

Genera un scramble aleatorio para el cubo Megaminx.

Este método crea una secuencia de movimientos basada en una distribución de las capas "R", "D" y "U", dando mayor probabilidad a "R" y "D", y menor a "U". Los movimientos generados incluyen variaciones como ++, --, y '.

Parámetros:

  • random: Número total de movimientos que debe tener el scramble generado.

Retorna:

  • Un String con los movimientos del scramble separados por espacios.

Características:

  • "R" y "D" tienen el doble de probabilidad de aparecer.
  • "U" aparece con probabilidad normal.
  • Cada movimiento puede tener una variación aleatoria:
    • 50% de probabilidad de que sea ++ (doble giro horario).
    • 50% de probabilidad de que sea -- (doble giro antihorario).
    • Si el movimiento es "U", se convierte en un '.

Implementation

String generateScrambleMegaminx(int random) {
  List<String> scramble = [];
  List<String> ponderadaMov = [];

  for (var move in movesMegaminx) {
    if (move == "R" || move == "D") {
      // R Y D TIENEN UN 10-20% MAS DE PROBABILIDADES DE SALIR
      // APARECEN DOS VECES
      ponderadaMov.add(move);
      ponderadaMov.add(move);
    } else if (move == "U") {
      // U TIENE UN 10-20% MENOS DE PROBABILIDADES, NO SE DUPLICA
      ponderadaMov.add(move);
    }
  }

  for (int i = 0; i < random; i++) {
    // SE COGE UNA CAPA ALEATORIAMENTE
    String move = ponderadaMov[Random().nextInt(ponderadaMov.length)];

    //AGRGAMOS UN GIRO ADICIONAL OPCIONAL (como U', R++, D--...)
    int randomMove = Random().nextInt(100);
    if (randomMove <= 50) {
      // SI ES MENOR O IGUAL A 50 SE LE COLOCA ++
      // SI EL MOVIMIENTO ES U ENTONCES SE LE PONE UN '
      move == "U" ? scramble.add("$move'") : scramble.add("$move++");
    } else {
      scramble.add("$move--");
    }
  }
  return scramble.join(" ");
}