Skip to content

Instantly share code, notes, and snippets.

@cesjam7
Created March 30, 2016 02:55
Show Gist options
  • Save cesjam7/3b62412173ecf839f8b08c92933a9155 to your computer and use it in GitHub Desktop.
Save cesjam7/3b62412173ecf839f8b08c92933a9155 to your computer and use it in GitHub Desktop.
Jugar yankenpo! con la maquina
<script>
// Leer http://www.xatakaciencia.com/computacion/alphago-su-victoria-en-el-go-nos-encamina-a-un-nuevo-mundo-de-inteligencia-artifical
function randomIntervalo(numeroInicio, numeroFin) {
var aleatorio = Math.random();
var diferencia = numeroFin - numeroInicio;
var numero = aleatorio * diferencia;
return Math.round(numero) + numeroInicio;
}
var p1 = randomIntervalo(1, 3);
var p2 = prompt("Elige\r1: Piedra\r2: Papel\r3: Tijera");
if (p1 == 1 && p2 == 1) {
document.write("Quedaron empate porque eligio piedra");
} else if (p1 == 1 && p2 == 2) {
document.write("Gane porque la maquina eligio piedra");
} else if (p1 == 1 && p2 == 3) {
document.write("Gana la maquina porque eligio piedra");
} else if (p1 == 2 && p2 == 1) {
document.write("Gana la maquina porque eligio papel");
} else if (p1 == 2 && p2 == 2) {
document.write("Quedaron empates porque eligio papel");
} else if (p1 == 2 && p2 == 3) {
document.write("Gane porque la maquina eligio papel");
} else if (p1 == 3 && p2 == 1) {
document.write("Gano porque la maquina eligio tijera");
} else if (p1 == 3 && p2 == 2) {
document.write("Gana la maquina porque eligio tijera");
} else if (p1 == 3 && p2 == 3) {
document.write("Quedaron empates porque eligio tijera");
} else {
document.write("No seas chistoso, solo deben ser numeros entre 1 y 3");
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment