Now computing casting probability over turns

This commit is contained in:
Correl Roush 2010-06-30 15:30:55 -04:00
parent e7a14dafc1
commit 21c40b275a

View file

@ -39,6 +39,24 @@ def mana_curve(deck):
for c in costs:
data[c] += 1
return data
def rampup(deck, type=None):
print '{0} Rampup'.format((type if type else 'spell').title())
print '-' * 80
land = [c for c in deck if 'land' in c.type.split(' ')]
cards = [c for c in deck if c.cost.converted() > 0]
if type:
cards = [c for c in cards if type in c.type.split(' ')]
avgCost = sum([c.cost.converted() for c in cards]) / float(len(cards))
maxCost = sorted([c.cost.converted() for c in cards]).pop()
print 'Average {0} cost: {1:.3f}'.format(type if type else 'spell', avgCost)
avgCost = int(round(avgCost))
for turn in range(avgCost, maxCost + 1):
castable = [c for c in cards if c.cost.converted() <= turn]
pm = 1 - draw_probability(len(land), deck, avgCost, turn)
pc = 1 - draw_probability(len(castable), deck, 1, turn, avgCost)
p = 1 - pm - pc
print 'Probability of drawing {0} mana in {1} turns with a castable {3}: {2:.3f}'.format(avgCost, turn, p * 100, type if type else 'spell')
def types(deck):
return {
'Lands': len([c for c in deck if 'land' in c.type.split(' ')]),
@ -103,5 +121,7 @@ if __name__ == '__main__':
graph(colors(deck), '\nColors')
graph(rarities(deck), '\nRarities')
print '\nProbability of drawing 4 mana in 4 turns: {0:.3f}'.format(100 * draw_probability(len([c for c in deck if 'land' in c.type.split(' ')]), deck, 4, 4))
print 'Probability of drawing a creature costing 4 or fewer mana in 4 turns: {0:.3f}'.format(100 * draw_probability(len([c for c in deck if 'creature' in c.type.split(' ') and c.cost.converted() <= 4]), deck, 1, 4, 4))
print
rampup(deck)
print
rampup(deck, 'creature');