From 21c40b275a66221511b2c6f4d7d5629f6644ecc6 Mon Sep 17 00:00:00 2001 From: Correl Roush Date: Wed, 30 Jun 2010 15:30:55 -0400 Subject: [PATCH] Now computing casting probability over turns --- analyze.py | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/analyze.py b/analyze.py index da3084d..31fda1e 100644 --- a/analyze.py +++ b/analyze.py @@ -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(' ')]), @@ -102,6 +120,8 @@ if __name__ == '__main__': graph(types(deck), '\nCard Types') 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');