#!/usr/bin/python3 """ This module provides the Dice class (formula based random numbers) """ import sys from random import randint class Dice(object): """ This class supports formula based dice rolls. The formulae can be described in a few (fairly standard) formats: - DnD style ... D100, 3D6, 3D6+4 - ranges ... 4-12 - simple numbers ... 50 @ivar num_dice: (int) number of dice to be rolled, None if a range @ivar dice_type: (int) number of faces on each die, None if a range @ivar plus: (int) number to be added to the roll @ivar min_value: (int) lowest legal value in range, None if a formula @ivar max_value: (int) highest legal value range, None if a formula """ def __init__(self, formula): """ instantiate a roller for a specified formula @param formula: (string) description of roll @raise ValueError: illegal formula expression """ # formula must be a string (or integer) # if it is just a number, this is simple # figure out what kind of expression this is # see if it has known form and 2 values # process the values # there might be a plus after the dice type def str(self): """ return string representation of these dice" """ def roll(self): """ roll this set of dice and return result @return: (int) resulting value """