Created
January 20, 2020 00:07
-
-
Save avibryant/1c54760de6e1a58e3948146aad1b90cd 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
attacker = ARGV[0].to_i | |
defender = ARGV[1].to_i | |
def roll(k, n) | |
(1..k).map{rand(6)}.sort.reverse.first(n) | |
end | |
while attacker > 0 && defender > 0 | |
sleep 1 | |
attacker_dice = [attacker, 3].min | |
defender_dice = [defender, 2].min | |
kills = [attacker_dice, defender_dice].min | |
attack_rolls = roll(attacker_dice, kills) | |
defend_rolls = roll(defender_dice, kills) | |
attack_rolls.zip(defend_rolls).each do |a,d| | |
if a > d | |
defender -= 1 | |
else | |
attacker -= 1 | |
end | |
end | |
puts [attacker, defender].join("\t") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment