Last active
August 29, 2015 14:26
-
-
Save mlms13/9fabb150003e1cbdfa86 to your computer and use it in GitHub Desktop.
Attacker vs Defender with big armies in risk
This file contains hidden or 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
function roll() { | |
return Math.ceil(Math.random() * 6); | |
} | |
function compare() { | |
var one = [roll(), roll(), roll()].sort(function (a, b) { return b-a }).slice(0,2); | |
var two = [roll(), roll()].sort(function (a, b) { return b-a }); | |
var score = 0; | |
one.forEach(function (item, index) { | |
if (item > two[index]) { | |
score++; | |
} else { | |
score--; | |
} | |
}); | |
return score; | |
} | |
var wins = 0; | |
var losses = 0 | |
var ties = 0; | |
for (var i = 0; i < 1000000; i++) { | |
var result = compare(); | |
if (result > 0) { | |
wins++; | |
} else if (result < 0) { | |
losses++; | |
} else { | |
ties++ | |
} | |
} | |
console.log(wins, losses, ties); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment