Finish encounter, test, dice unittest, attack actions

This commit is contained in:
Matthew DeMartino
2021-05-23 14:52:18 -04:00
parent 4bc844a6bf
commit 89143c5cbc
10 changed files with 262 additions and 93 deletions
+9
View File
@@ -1,3 +1,4 @@
import random
import re
from collections import namedtuple
@@ -22,3 +23,11 @@ def read_dice_str(dice_str):
raise DiceError(f"Cannot interpret dice string {dice_str}")
dice = Dice(num=int(match.group(1)), faces=int(match.group(2)))
return dice
def roll(a, b=None):
"""roll(20) means roll 1d20, roll(2, 6) means roll 2d6"""
if b is None:
return random.randint(1, a)
else:
return sum([random.randint(1, b) for _ in range(a)])