API

When you import dicehancis you get the following imported

dicechanics.d(inpt, **kwards)

Function that creates a die from various input types Currently takes int, str, Iterable, Die which it copies, and a dict

Parameters:
  • inpt (Iterable | Int | Die | dict) – the input for the function

  • **kwards – Rounding: Callable

Returns:

out – The die created from the input

Return type:

Die

dicechanics.z(inpt, **kwards)

Function that creates a z-die from various input types

A z-die is a die which starts from 0. So a z9 is a die going from [0..9]

Parameters:

inpt (int) – the input for the function

Returns:

out – The die created from the input

Return type:

Die

dicechanics.pool(inpt)

Creates a pool from a list of number and/or dice.

Parameters:

inpt (list) – list of numbers or dice

Returns:

out – The pool containing the elements of the input

Return type:

Pool

dicechanics.d4

A 4 sided die

dicechanics.d6

A 6 sided die

dicechanics.d8

A 8 sided die

dicechanics.d10

A 10 sided die

dicechanics.d12

A 12 sided die

dicechanics.d20

A 20 sided die

dicechanics.d100

A 100 sided die

dicechanics.z9

A 10 sided die with values [0..9]

class dicechanics.Die

The class that represents a statistical presentation of a die.

__init__(faces, /, rounding=<function Die.<lambda>>)

Initializes the Die, its recommended to use d() interface.

Parameters:
  • faces (Iterable[float])

  • rounding (PureFunc_T)

classmethod from_dict(data, rounding=<function Die.<lambda>>)

Constructor that creates a die directly from a dict.

Parameters:
  • data (dict) – The data in the form of a dict.

  • rounding (Callable) – A function that determines how to round outcomes.

Returns:

out

Return type:

Die

property f: list

Returns the faces of the die

Returns:

out – The faces of the die.

Return type:

list

property p: list

Returns the probability of the die

Returns:

out – The probability of the die.

Return type:

list

property c: list

Returns the count list of the die

Returns:

out – The number pr face of the die.

Return type:

list

property mean: float

Returns the mean of the die

Returns:

out – The mean of the die.

Return type:

float

property cdf: list

Returns the cumulative probability of the die

Returns:

out – The cumulative probability of the die.

Return type:

List

property var: float

Returns the variance of the die

Returns:

out – The variance of the die.

Return type:

float

property std: float

Returns the standard deviation of the die

Returns:

out – The standard deviations of the die.

Return type:

float

max()

Returns the maximum face of the die.

Parameters:

out (float) – The maximum face of the die.

Return type:

float

min()

Returns the minimum faces of the die

Parameters:

out (float) – The minimum face of the die

Return type:

float

copy()

Function that creates a copy of the die

Returns:

out – The copy

Return type:

Die

keys()

Get the keys of the internal dict.

Returns:

out – The keys if the internal data.

Return type:

KeysView

values()

Get the values of the internal dict.

Returns:

out – The values if the internal data.

Return type:

ValuesView

items()

Get the items (keys and values) of the internal dict.

Returns:

out – The items if the internal data.

Return type:

ValuesView

reroll(*redo, depth=1)

Function that rerolls on a given set of values

Parameters:
  • *redo – Faces to reroll

  • depth (int) – the number of rerolls allowed

  • Returns

  • out (Die) – A die that represents the rerolled properbilites

  • -------

Return type:

Die_T

explode(*exploder, depth=1)

Function that explodes the die. Ie. Reroll on a value and add it to the rolled face.

Parameters:
  • *exploder – The numbers that need to be rerolled

  • depth (int) – How many times do we reroll

Returns:

out – A die representing the operation

Return type:

Die

implode(*imploder, depth=1)

Function that implodes the die. Ie. Reroll on a value and sub it from the rolled face.

Parameters:
  • *imploder – The numbers that need to be rerolled

  • depth (int) – How many times do we reroll

Returns:

out – A die representing the operation

Return type:

Die

count(*count)

Function that counts the given number of faces results in a true or false die

Parameters:

count (args) – The faces we want to count

Returns:

out – The die representing the operation

Return type:

Die

equal(rhs)

Function that checks if equality of objects. If its not a Die object then it always return false.

Parameters:

rhs (object) – The object thats we compare the die to.

Returns:

out – Bool representing if the object is equal to the die.

Return type:

bool

folding(rhs, ops, into)

Function that takes values of the die, that are evaluated true when compared with @rhs through @ops. It them puts the counts into the value defined by @into

Parameters:
  • rhs (object) – The object we compare in relation to

  • ops (Callable) – The comparison operation

  • into (object) – Where we store the evaluated numbers

Returns:

out – The new die that with the values folded into @into

Return type:

Die

fold_over(rhs, /, into=None)

Function that folds values over @rhs and puts them into @into

Parameters:
  • rhs (object) – The object we compare in relation to

  • into (object) – Where we store the evaluated numbers

Returns:

out – The new die that with the values folded into @into

Return type:

Die

fold_under(rhs, /, into=None)

Function that folds values under @rhs and puts them into @into

Parameters:
  • rhs (object) – The object we compare in relation to

  • into (object) – Where we store the evaluated numbers

Returns:

out – The new die that with the values folded into @into

Return type:

Die

map(func)

Maps a function onto the die

Parameters:

func (Callable) – The function to be mapped

Returns:

out – The die with the results of the mapping

Return type:

Die

__hash__()

The hashing method

Return type:

int

__call__(func)

Used to wrap die in as a decorator. It used the map function.

Parameters:

func (PureFunc_T) – The function to wrap.

Returns:

out – A function that returns a die of the mapped function

Return type:

callable

__add__(rhs)

Return self + value

Parameters:

rhs (object)

Return type:

Die_T

__radd__(lhs)

Return value + self

Parameters:

lhs (object)

Return type:

Die_T

__sub__(rhs)

Return self - value

Parameters:

rhs (object)

Return type:

Die_T

__rsub__(lhs)

Return value - self

Parameters:

lhs (object)

Return type:

Die_T

__mul__(rhs)

Return self * value

Parameters:

rhs (object)

Return type:

Die_T

__rmul__(lhs)

Return value * self

Parameters:

lhs (object)

Return type:

Die_T

__truediv__(rhs)

Return self / value

Parameters:

rhs (object)

Return type:

Die_T

__floordiv__(rhs)

Return self // value

Parameters:

rhs (object)

Return type:

Die_T

__lt__(rhs)

Return self < value

Parameters:

rhs (object)

Return type:

Die_T

__le__(rhs)

Return self <= value

Parameters:

rhs (object)

Return type:

Die_T

__ge__(rhs)

Return self => value

Parameters:

rhs (object)

Return type:

Die_T

__gt__(rhs)

Return self > value

Parameters:

rhs (object)

Return type:

Die_T

__eq__(rhs)

Return self == value

Parameters:

rhs (object)

Return type:

BooleanDie_T

__ne__(rhs)

Return self != value

Parameters:

rhs (object)

Return type:

BooleanDie_T

__rmatmul__(lhs)

Return self @ value

Parameters:

lhs (int)

Return type:

Die_T

__matmul__(rhs)

Return value @ self

Return type:

Die_T

__neg__()

Return -self

Return type:

Die_T

__pos__()

Return +self

Return type:

Die_T

class dicechanics.Die.BooleanDie

Bases: Die

__init__(faces, truth)

Initializes the Die, its recommended to use d() interface.

Parameters:

truth (bool)

classmethod from_dice(dice, truth)

Constructor that creates a BooleanDie directly from a dict.

Parameters:
  • data (dict) – The data in the form of a dict.

  • rounding (Callable) – A function that determines how to round outcomes.

  • dice (Die)

  • truth (bool)

Returns:

out

Return type:

BooleanDie

class dicechanics.Pool

Class that represents a pool of dice.

__init__(dice)

Initializes the pool.It is recommend to use pool() interface.

Parameters:

dice (list)

perform(func)

Function that applies a given function to the elements in the pool. The function must have the form f(x, y) -> z, and its operation must be linear, ie. the order in which the values are calculated doesn’t matter.

Parameters:

func (Callable) – Function with the form f(x, y) -> z. It must apply a linear operation

Return type:

Die

copy()

Function that creates a copy of the pool

Returns:

out – A copy of the current pool

Return type:

Pool

__getitem__(idx)

Get in this function defines which faces in sorted outcomes of rolling the back needs to be selected and operated on in the perform method

Parameters:

idx (list | slice)

Returns:

out – A pool copy with which die to keep set

Return type:

pool

__call__(func)

A wrapper for perform, allows the pool to be used as a decorator

__add__(rhs)

Return self + value