Last active
February 8, 2018 03:51
-
-
Save itacirgabral/213fc2a85ecc2aa8193c467a369b5087 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const dificuldadeCasas = [ | |
50, | |
55, | |
60, | |
70, | |
75, | |
80, | |
85, | |
90, | |
95, | |
100, | |
110, | |
120 | |
] | |
const poderCosmico = [ | |
1.5, | |
1.4, | |
1.3, | |
1.2, | |
1.1 | |
] | |
const poderCosmicoMedia = poderCosmico.reduce((a,b) => a+b, 0)/poderCosmico.length | |
const pontosEnergia = 5 | |
const quantosLutam = [5,5,5,1,1,1,1,1,1,1,1,1] | |
function tempoLutando(quantosLutam){ | |
return quantosLutam.reduce((a,b,i) => a+dificuldadeCasas[i]/b/poderCosmicoMedia, 0) | |
} | |
function maximoLutas(quantosLutam){ | |
return quantosLutam.reduce((a,b) => a+b, 0) === pontosEnergia*poderCosmico.length -1 | |
} | |
function moveCavaleiro(quantosLutam){ | |
let origem | |
while(quantosLutam[origem = Math.floor(12*Math.random()) ] === 1){ | |
// a origem não pode ser uma casa com apenas 1 cavaleiro | |
!void(0) | |
} | |
let destino | |
while(quantosLutam[destino = Math.floor(12*Math.random())] === pontosEnergia || destino === origem){ | |
// o destino não pode ser uma casa que já possui os 5 cavaleiros | |
// nem ser a mesma casa de origem | |
!void(0) | |
} | |
const novaLuta = quantosLutam.slice() | |
novaLuta[origem]-- | |
novaLuta[destino]++ | |
return novaLuta | |
} | |
const darwin = [] | |
for(let i=0; i<20; i++){ | |
const jgd = {} | |
jgd.quantosLutam = moveCavaleiro(quantosLutam) | |
jgd.tempoLutando = tempoLutando(jgd.quantosLutam) | |
darwin.push(jgd) | |
} | |
darwin.sort((a,b) => a.tempoLutando > b.tempoLutando) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
tempoLutando([2,2,2,2,2,2,2,2,2,2,2,2]) é igual a 380 minutos, considerando cosmos médio de 1,3