Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from collections import namedtuple
- # dice format:
- Atk = namedtuple('Atk', ['damage', 'surges'])
- RED_DICE = [Atk(1,0), Atk(2,0), Atk(2,0), Atk(2,1), Atk(3,0), Atk(3,0)]
- GREEN_DICE = [Atk(0,1), Atk(1,1), Atk(2,0), Atk(1,1), Atk(2,0), Atk(2,0)]
- YELLOW_DICE = [Atk(0,1), Atk(1,2), Atk(2,0), Atk(1,1), Atk(0,1), Atk(1,0)]
- Def = namedtuple('Def', ['blocks', 'evades'])
- BLACK_DICE = [Def(1,0), Def(1,0), Def(2,0), Def(2,0), Def(3,0), Def(0,1)]
- def eval(attack, defense):
- total = attack.damage
- if (attack.surges - defense.evades) >= 1:
- total += 2
- total -= defense.blocks
- return max(0, total)
- class Roll:
- def __init__(this):
- this.combinations = [[]]
- def add(this, atk_dice):
- this.combinations = [existing + [new] for new in atk_dice for existing in this.combinations]
- def results_against(this, def_dice):
- rolls = []
- for roll in this.combinations:
- current = Atk(0,0)
- for side in roll:
- current = Atk(current.damage + side.damage, current.surges + side.surges)
- rolls += [current]
- results = [eval(atk, defense) for atk in rolls for defense in def_dice]
- return results
- def summarize(results):
- total = len(results)
- print('total: %d rolls' % (total))
- for level in range(0, 8):
- absolute = sum(1 for each in results if each >= level)
- print('>= {} damage: {:.3%} ({})'.format(level, absolute / float(total), absolute))
- if __name__ == '__main__':
- sim = Roll()
- sim.add(RED_DICE)
- sim.add(GREEN_DICE)
- sim.add(YELLOW_DICE)
- summarize(sim.results_against(BLACK_DICE))
Add Comment
Please, Sign In to add comment