Untitled

html 2 views Created:
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
<!DOCTYPE html>
<html lang="es">
<head>
  <meta charset="UTF-8">
  <title>Combinaciones de manos</title>
  <style>
    body { font-family: sans-serif; padding: 20px; }
    button { padding: 10px 20px; font-size: 16px; }
    #resultado { margin-top: 20px; font-family: monospace; font-size: 18px; }
    #lista { margin-top: 30px; }
    #lista h2 { margin-bottom: 10px; }
    #lista ul { line-height: 1.6; }
  </style>
</head>
<body>
  <h1>Combinación aleatoria válida</h1>
  <button onclick="mostrarCombinacion()">Generar combinación</button>
  <div id="resultado"></div>
  <div id="lista">
    <h2>Significado de cada tipo de mano</h2>
    <ul>
      <li><strong>0</strong> — mano vacía sin anillo</li>
      <li><strong>1</strong> — mano con cubo blanco sin anillo</li>
      <li><strong>2</strong> — mano con cubo negro sin anillo</li>
      <li><strong>3</strong> — mano que señala sin anillo</li>
      <li><strong>01</strong> — mano vacía con anillo amarillo</li>
      <li><strong>11</strong> — mano con cubo blanco con anillo amarillo</li>
      <li><strong>21</strong> — mano con cubo negro con anillo amarillo</li>
      <li><strong>31</strong> — mano que señala con anillo amarillo</li>
    </ul>
  </div>
  <script>
    const tipos = ["0","1","2","3","01","11","21","31"];
    const cabezas = ["RI","RD","AI","AD"];
    function esNegro(t) { return t === "2" || t === "21"; }
    function esBlanco(t) { return t === "1" || t === "11"; }
    function tieneAnillo(t) {
      return t === "01" || t === "11" || t === "21" || t === "31";
    }
    function manosValidas(m) {
      const negros = m.filter(esNegro).length;
      const blancos = m.filter(esBlanco).length;
      const anillos = m.filter(tieneAnillo).length;
      if (negros < 1 || negros > 3) return false;
      if (blancos < 1 || blancos > 3) return false;
      if (anillos < 0 || anillos > 3) return false;
      const pares = [
        [m[0], m[1]], // 1A, 1B
        [m[2], m[3]], // 2A, 2B
        [m[4], m[5]]  // 3A, 3B
      ];
      for (const [a, b] of pares) {
        if (esNegro(a) && esNegro(b)) return false;
      }
      return true;
    }
    function cabezaValida(cabeza, m) {
      const ladoA = [m[0], m[2], m[4]]; // 1A, 2A, 3A
      const ladoB = [m[1], m[3], m[5]]; // 1B, 2B, 3B
      if (cabeza === "AI") {
        return ladoA.every(x => !(tieneAnillo(x) && x === "21"));
      }
      if (cabeza === "AD") {
        return ladoB.every(x => !(tieneAnillo(x) && x === "21"));
      }
      if (cabeza === "RI") {
        return ladoB.every(x => !(tieneAnillo(x) && x === "21"));
      }
      if (cabeza === "RD") {
        return ladoA.every(x => !(tieneAnillo(x) && x === "21"));
      }
      return false;
    }
    const validas = [];
    function generarTodas() {
      function productoTipos(n, prefix = []) {
        if (n === 0) {
          if (manosValidas(prefix)) {
            for (const h of cabezas) {
              if (cabezaValida(h, prefix)) {
                validas.push({ cabeza: h, manos: prefix.slice() });
              }
            }
          }
          return;
        }
        for (const t of tipos) {
          prefix.push(t);
          productoTipos(n - 1, prefix);
          prefix.pop();
        }
      }
      productoTipos(6);
    }
    generarTodas();
    function mostrarCombinacion() {
      if (validas.length === 0) {
        document.getElementById("resultado").textContent =
          "No hay combinaciones válidas calculadas.";
        return;
      }
      const idx = Math.floor(Math.random() * validas.length);
      const { cabeza, manos } = validas[idx];
      const texto = `${cabeza} | M1A=${manos[0]}, M1B=${manos[1]}, ` +
                    `M2A=${manos[2]}, M2B=${manos[3]}, ` +
                    `M3A=${manos[4]}, M3B=${manos[5]}`;
      document.getElementById("resultado").textContent = texto;
    }
  </script>
</body>
</html>

Embed this paste

Please confirm