Created
August 15, 2011 14:43
-
-
Save sma/1146893 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
import random | |
def d6(): return random.randrange(6) + 1 | |
def fight(heroes, rabbles): | |
while heroes and rabbles: | |
#print heroes, "vs", rabbles | |
for h in heroes: | |
foe = random.choice(rabbles) | |
att = d6()+d6() | |
dam = d6()+2 | |
if att == 12: | |
random.shuffle(rabbles) | |
rabbles = rabbles[dam:] | |
if not rabbles: break | |
elif att + h.a - foe.d >= 9: | |
foe.lb -= dam | |
rabbles = [r for r in rabbles if r.lb > 0] | |
if not rabbles: break | |
for r in rabbles: | |
foe = random.choice(heroes) | |
att = d6()+d6() | |
dam = d6()+1 | |
if att == 12 or att + r.a - foe.d >= 9: | |
dam -= d6()-1 | |
foe.lb -= dam | |
heroes = [h for h in heroes if h.lb > 0] | |
if not heroes: break | |
return bool(heroes) | |
class Char: | |
def __init__(self, a=0, d=0, lb=3): | |
self.a, self.d, self.lb = a, d, lb | |
def __repr__(self): | |
return "%d" % self.lb | |
wins = 0 | |
for i in range(1000): | |
heroes = [Char(3, 2, 12) for _ in range(3)] | |
rabbles = [Char(1) for _ in range(20)] | |
wins += fight(heroes, rabbles) | |
print wins |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment