Code:
import random
# Simple class definition
class Spell(object):
__slots__=('name', 'cost', 'cast', 'recharge', 'left')
def __init__(self, name, cost, cast, recharge, left=0):
self.name = name
self.cost = cost
self.cast = cast
self.recharge = recharge
self.left = left
def model(spells,
energyMax=55,
every=5,
reapingMax=13,
reapingAmt=13,
noMonsters=8,
noSpirits=2,
deathsStart=10,
deathsEnd=35):
'''
This runs the model based on the parameters passed in. Only
spells is required, the others are named parameters for convenience.
'''
lastDeath=0 # starting last death
deaths = [] # list of death pairs (when, reapValue)
# set up the no of monsters in the sample for the SR value
for n in range(noMonsters):
death = random.randint(deathsStart, deathsEnd)
if death > lastDeath: lastDeath = death
deaths.append([death, reapingAmt])
# set up the no of spirits in the sample for the SR value
for n in range(noSpirits):
death = random.randint(deathsStart, deathsEnd)
if death > lastDeath: lastDeath = death
deaths.append([death, reapingAmt / 2])
#sort the list for the print
deaths.sort()
print deaths
energy = energyMax
casting = 0
reaping = 0
#recharge on 4 pips is about 0.7 to 0.8
recharge = 0.8
battery = 0
for second in range(lastDeath):
for spell in spells:
if spell.left > 0: # if the spell is still recharging
spell.left -= 1
elif casting == 0: # if not in the process of casting
if spell.cost <= energy: # if there is enough energy to cast
print "%3d %-20s %2d %2d %2d %d" % (second, spell.name, spell.cost, spell.cast, energy, casting)
casting = spell.cast # HCT could be applied here
energy -= spell.cost
spell.left = spell.recharge # HSR could be applied here
if casting > 0:
casting -= 1
# recharge is not 1 pip a second
battery += recharge
if energy < max and battery > 1.0:
energy += 1
if battery > 1.0:
battery -= 1.0
# get the Soul Reaping for the monsters that died
for death in deaths:
if death[0] == second:
if reaping < reapingMax:
reaping += death[1]
if reaping > reapingMax:
reaping = reapingMax
# apply the SR value based on parameters
if second != 0 and second % every == 0:
x = energy + reaping
reaping = 0
if x > max:
energy = energyMax
else:
energy = x
# SAMPLE SPELL LIST
spells = [Spell('Insidious',15,1,12),
Spell('Suffering',15,1,5),
Spell('Spiteful',10,2,10),
Spell('Desecrate',10,2,15),
Spell('Defile',10,2,15),
Spell('Parasitic',5,1,2)]
#first test as per default values
random.seed(0)
model(spells)
#second test taking out the maxing and reaping every second
# kind of like how it used to be
spells[2] = Spell('Spiteful',15,2,10)
random.seed(0)
model(spells, reapingMax=55, every=1, noSpirits=1)
# the spirits dying exploit
random.seed(0)
model(spells, reapingMax=55, every=1, noSpirits=12)
