our contestants:
def makestrat(mindo = 0, maxtake = float('inf'), minval = 0, phide = 0.0):
def strat(send, recv, val):
if random.random() < phide:
return 2
elif recv > maxtake:
return 2
elif mindo > send:
return 1
elif minval > val:
return 1
else:
return 0
return strat
def lincom(objlst):
results = []
for o, n in objlst:
results.extend([copy.deepcopy(o) for x in xrange(n)])
return results
fixstrat = lambda s: (lambda x, y, z: s)
def nullstrat(dmgsend, dmgtake, val):
if dmgtake > 1.025:
return 2
elif dmgsend < 0.51 and val < 100:
return 1
else:
return 0
null = Obj([0.35,0.35],[0.0,0.0],1.05,2.05,nullstrat,side='K',id='null')
def nilstrat(dmgsend, dmgtake, val):
if random.random() < 1./3:
return 2
elif dmgtake > 2:
return 2
elif dmgsend < 0.55 or val > 100:
return 1
else:
return 0
nil0 = Obj([0.25, 0.25],[1.1,0.0],1.05,4.05,nilstrat,side='K',id='nil*')
nil1 = Obj([0.25, 0.25],[0.0,1.1],1.05,4.05,nilstrat,side='K',id='nil~')
void0 = Obj([0.0,0.0],[1.5,0.0],0.0,8.0,makestrat(phide = 0.1),side='K',id='void*')
void1 = Obj([0.0,0.0],[0.0,1.5],0.0,8.0,makestrat(phide = 0.1),side='K',id='void~')
KOM = lincom([(null,268),(nil0,54),(nil1,54),(void0,16),(void1,15)])
corn = Obj([0.2,0.2],[0.1,0.1],2.0,1.0,makestrat(minval = 1.),side='D',id='corn')
DAR = lincom([(corn,432)])
def nuestrat(x, y, z):
q = random.random()
if q < .75:
return 0
elif q < .95:
return 2
else:
return 1
miniships = Obj([0.9,0.9],[0.9,0.7],8.5,5.0,nuestrat,side='N',id='miniships')
NUE = lincom([(miniships,12)])
def fiahstrat(x,y,z):
if z > 2:
return 1
elif not(0.4 < z < 0.51):
return (1 if random.random() > .5 else 0)
else:
return 0
pure = Obj([0.305,0.305],[.0,.0],.9, .732, fiahstrat, side = 'F', id='pure')
FIA = lincom([(pure,1000)])
def checkcost(objs):
return sum((o.getcost() for o in objs))
assert checkcost(KOM) <= 1000
assert checkcost(NUE) <= 1200
assert checkcost(DAR) <= 1200
assert checkcost(FIA) <= 1000
allobjs = KOM+DAR+NUE+FIA
refset = {o.id:copy.deepcopy(o) for o in set(allobjs)}