A package of functions for rolling dice implented as a CLI.
The module contains functions that replicate rolling polyhedral dice with any number of faces and rolling them in different ways; as an array, at advantage; as a critical hit; at disadvantage and rolling an array of 6 ability scores.
This is acheived with the parse_die_string function, which takes a string and returns a dictionary of all the elements of a die string (number of dice, die type, symbol & modifier) used by other functions to roll dice.
The cli function packages all of the above into an installable command line interface called 'dice', implementing the various types of rolls through the --kind option.
To install the command line interface, download the package, navigate to the root folder and issue the following command:
pip install --editable .
You may wish to create a virtual environment before doing this, ensuring the package does not experience dependency conflicts.
Also included is a dockerfile that will allow you to install the app in a containerised linux terminal if you so wish.
The entry point for the dice command line tool.
The dice command returns the total for a roll of a DIESTRING of the format XdY?Z, where:
- X is the number of dice to be rolled
- dY is the kind of die to roll, Y being the number of faces
- ? is an optional operator which applies a modifier to the roll total
- Z is an optional modifier applied to the roll total
--kind can be used to roll the DIESTRING with the following options:
- advan: roll twice, ordered high to low
- disad: roll twice, ordered low to high
- array: roll list of x dice
- crit: roll with double the dice
- stand: standard roll of dice (default option)
Returns a dict of the constituents of a die roll from a given string.
Args:
- string (str): A string representing a die roll
- parsed_roll: A dictionary of the roll string's elements.
Return two calls to roll_string sorted highest to lowest.
Args:
- string (str): A string of a roll of a number of dice with modifiers
- roll_list (list): A list of rolls sorted from highest [0] to lowest [1]
- roll_list: A list of the roll result.
Return an array of a number of die rolls with modifiers.
Args:
- string (str): A string of die with modifiers to be rolled a number of times
- parsed_string (dict): A dictionary of the roll elements in the string
- num_dice (int): Int of the number of dice to be rolled, default 1
- die (str): String of type of die to be rolled
- symbol (str): String of operator to be appled, default +
- modifier (int): An int to be applied to roll with operator, default 0
- rolls (list): List of ints of all rolls with modifier applied to each
- rolls: An array of ints of die rolls
Return a list of 6 4d6 minus the lowest for each group.
Attributes:
- ability_die(func): Returns the total of 4d6 minus the lowest die
- abilities (list): An array of ints of all the scores rolled
- abilities: An array of 6 calls to ability_die sorted highest to lowest
Return an int of a roll with doubled dice and modifiers applied.
Args:
- string (str): A string of a roll of dice with modifiers
- roll: A int returned from a call to the roll_mult function.
Args:
- num (int): An int for the number of faces on the die
- roll (int): Int of the the number rolled.
Return call to roll_advantage sorted lowest to highest.
Args:
- string (str): A string of a roll of a number of dice with modifiers
- roll_list (list): A list of rolls sorted from lowest [0] to highest [1]
- roll_list: A list of the roll result.
Args:
- num (int): The number of dice to roll
- die (string): A string representing a die
- roll_total (int): An int for the total of all dice rolled
- faces (int): An int of the number of faces on the die
- roll_total: The combined total of all dice rolls.