careening = 1
foehn = 4
bonus = {}
bonus['atk'] = .1*foehn
bonus['fire'] = bonus['atk']
bonus['hp'] = .2*careening + .1*foehn
trials = 1000
navy = {
'Galley': {'n': 0, 'atk': 150, 'hp': 2000, 'fire': 0, 'chains': 0},
'Galleon': {'n': 4, 'atk': 500, 'hp': 15000, 'fire': 0, 'chains': 0},
'Fireship': {'n': 1, 'atk': 0, 'hp': 4000, 'fire': 100, 'chains': 0},
'Caravel': {'n': 7, 'atk': 200, 'hp': 6000, 'fire': 0, 'chains': 75}
}
enemies = {
'Boat': {'n': 0, 'atk': 50, 'hp': 300, 'fire': 0, 'chains': 0},
'Trireme': {'n': 26, 'atk': 200, 'hp': 3000, 'fire': 0, 'chains': 0},
'Turtle Ship': {'n': 13, 'atk': 150, 'hp': 10000, 'fire': 0, 'chains': 0},
'Blast Ship': {'n': 7, 'atk': 800, 'hp': 8000, 'fire': 0, 'chains': 0}
}
A = ['atk', 'hp', 'fire', 'chains']
enemy_totals = {}
for a in A: enemy_totals[a] = 0
for unit in enemies:
for a in A: enemy_totals[a] += enemies[unit]['n'] * enemies[unit][a]
#print enemy_totals
navy_totals = {}
for a in A: navy_totals[a] = 0
for unit in navy:
for a in A: navy_totals[a] += navy[unit]['n'] * navy[unit][a] * (1+bonus[a] if a in bonus else 1)
#print navy_totals
from numpy.random import rand
def randomize(n): return n * (1 + 1.0/3 * (rand() - rand()))
def fight(d):
my_hp = navy_totals['hp']
enemy_hp = enemy_totals['hp']
fire, chains = 0, 0
i = 0
while enemy_hp > 0 and i < 50:
i += 1
fire += randomize(navy_totals['fire'])
atk = randomize(navy_totals['atk'])
my_dmg = (fire + atk)
enemy_dmg = max(randomize(enemy_totals['atk']) - chains, 0)
enemy_hp -= my_dmg
my_hp -= enemy_dmg
chains += randomize(navy_totals['chains'])
return my_hp > 0 and i < 50
print sum(map(fight, range(trials))), "/", trials
Y2FyZWVuaW5nID0gMQpmb2VobiA9IDQKCmJvbnVzID0ge30KYm9udXNbJ2F0aydd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