From 219fe44d61d61dc3beb89bc9423edab7676a00d3 Mon Sep 17 00:00:00 2001 From: Patrick Hurst Date: Sat, 14 Aug 2010 17:07:17 -0400 Subject: [PATCH] add fudge dice fudge dice are dF's, and are either -1, 0, or +1 --- plugins/dice.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/plugins/dice.py b/plugins/dice.py index 0ed6c03..c7f8649 100644 --- a/plugins/dice.py +++ b/plugins/dice.py @@ -9,10 +9,10 @@ from util import hook whitespace_re = re.compile(r'\s+') -valid_diceroll_re = re.compile(r'^[+-]?(\d+|\d*d\d+)([+-](\d+|\d*d\d+))*$', +valid_diceroll_re = re.compile(r'^[+-]?(\d+|\d*d(\d+|F))([+-](\d+|\d*d(\d+|F)))*$', re.I) -sign_re = re.compile(r'[+-]?(?:\d*d)?\d+', re.I) -split_re = re.compile(r'([\d+-]*)d?(\d*)', re.I) +sign_re = re.compile(r'[+-]?(?:\d*d)?(?:\d+|F)', re.I) +split_re = re.compile(r'([\d+-]*)d?(F|\d*)', re.I) def nrolls(count, n): @@ -43,10 +43,15 @@ def dice(inp): groups = sign_re.findall(spec) for roll in groups: count, side = split_re.match(roll).groups() - if side == "": - sum += int(count) + count = int(count) if count not in " +-" else 1 + if side.lower() == "f": + if count > 0: + sum += nrolls(count, 3) - 2 * count + else: + sum -= nrolls(count, 3) + 2 * count + elif side == "": + sum += count else: - count = int(count) if count not in" +-" else 1 side = int(side) try: if count > 0: