Skip to content

Instantly share code, notes, and snippets.

@avibryant
Created January 20, 2020 00:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avibryant/1c54760de6e1a58e3948146aad1b90cd to your computer and use it in GitHub Desktop.
Save avibryant/1c54760de6e1a58e3948146aad1b90cd to your computer and use it in GitHub Desktop.
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