From eb1c897b96cf421ad55b6a8ccaf35eb847076a8d Mon Sep 17 00:00:00 2001 From: Anna Wiggins Date: Wed, 21 Mar 2012 10:57:59 -0400 Subject: [PATCH] dice.py: renamed program, cleaned up both input and output formats --- diceroller.py => dice.py | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) rename diceroller.py => dice.py (84%) diff --git a/diceroller.py b/dice.py similarity index 84% rename from diceroller.py rename to dice.py index 80c8be7..2020f3c 100755 --- a/diceroller.py +++ b/dice.py @@ -62,17 +62,16 @@ class Dice(): # Get the results total = sum(results) + self.mod - # fixme - verbose mode could use slightly better formatting re: drop_info and reroll_info... if verbose: drop_info = '' reroll_info = '' if dropped: - drop_info = '[dropped {}]'.format(','.join(['{}'.format(x) for x in dropped])) + drop_info = ' [dropped {}]'.format(','.join(['{}'.format(x) for x in dropped])) if rerolled: - reroll_info = '[rerolled {}]'.format(','.join(['{}'.format(x) for x in rerolled])) + reroll_info = ' [rerolled {}]'.format(','.join(['{}'.format(x) for x in rerolled])) - print('{dice}: {results} {drop} {reroll} {total}'.format(dice=self, results=results, total=total, drop=drop_info, reroll=reroll_info)) + print('{dice}: {results}{drop}{reroll} {total}'.format(dice=self, results=results, total=total, drop=drop_info, reroll=reroll_info)) else: print('{dice}: {total}'.format(dice=self, total=total)) @@ -86,15 +85,15 @@ class Dice(): mod_info = '' if self.reroll: - reroll_info = ', reroll <= {}'.format(self.reroll) - + reroll_info = ' [reroll {}'.format(self.reroll) if self.reroll_times: - reroll_info = reroll_info + ' up to {} times'.format(self.reroll_times) + reroll_info = reroll_info + 'x{}'.format(self.reroll_times) + reroll_info = reroll_info + ']' if self.drop_low: - drop_info = drop_info + ', drop low {}'.format(self.drop_low) + drop_info = drop_info + ' [drop low {}]'.format(self.drop_low) if self.drop_high: - drop_info = drop_info + ', drop high {}'.format(self.drop_high) + drop_info = drop_info + ' [drop high {}]'.format(self.drop_high) if self.mod > 0: mod_info = '+{}'.format(self.mod) @@ -123,14 +122,14 @@ def parse_input(args): reroll = 0 reroll_times = 0 - for m in re.findall(r'[hl+-]\d+', arg): + for m in re.findall(r'[dD+-]\d+', arg): if m[0] == '-': mod += int(m) elif m[0] == '+': mod += int(m[1:]) - elif m[0] == 'h': + elif m[0] == 'D': dhigh = int(m[1:]) - elif m[0] == 'l': + elif m[0] == 'd': dlow = int(m[1:]) m = re.search(r'r(\d+)(x\d+)?', arg) @@ -159,8 +158,8 @@ This will roll X Y-sided dice and apply the specified modifiers. Modifiers can be any of the following (where N and M are integers): (+|-)N Add or subtract N from the total -lN Drop the lowest-rolling N dice from the total -hN Drop the highest-rolling N dice from the total +dN Drop the lowest-rolling N dice from the total +DN Drop the highest-rolling N dice from the total rN[xM] Any dice that roll <= N will be rerolled. If the optional 'xM' option is specified, dice will be rerolled a maximum of M times. Otherwise each die will be rerolled until the result is > N