pypbe package

Submodules

pypbe.core module

pypbe.core

Intended for tabletop rpgs such as Pathfinder or D&D, this module contains code to run a Monte Carlo simulation to determine the Point Buy Equivalent (PBE) for a given type of ability score rolling method, such as “Roll 4d6 and drop the lowest”.

copyright:
  1. 2017 Eric Strong.
license:

Refer to LICENSE.txt for more information.

class pypbe.core.PBE(num_dice, dice_type, add_val=0, num_attribute=6, num_arrays=1, reroll=0, keep_dice=None, keep_attribute=6, pbe_map='pf', custom_pbe_map=None, roll_low_limit=None, roll_high_limit=None, pbe_low_limit=None, pbe_high_limit=None)

Initializes a Monte Carlo simulation to determine the equivalent Point Buy of an ability score rolling method.

get_results(title_prefix='', title_override='', rnd_dig=2)

Constructs a summary of the results as an array, which might be useful for writing the results of multiple algorithms to a table. NOTE- This method must be called AFTER “roll_mc”.

Parameters:
  • title_prefix – If desired, prefix the title (such as “Alg 1 “)
  • title_override – Override the title string entirely
  • rnd_dig – the number of digits to round to
Returns:

A tuple of the raw array results and PBE results, as: [Description, Typical Array, Mean, Std, 5%, 95%]

plot_histogram(title_prefix='', title_override='', figsize=(8, 6))

Plots a histogram of the results after the Monte Carlo simulation is run. NOTE- This method must be called AFTER “roll_mc”.

Parameters:
  • title_prefix – If desired, prefix the title (such as “Alg 1”)
  • title_override – Override the title string entirely
  • figsize – The size of the histogram plot
Returns:

a seaborn figure of the histogram

roll_mc(num_hist=100000)

Runs the initialized Monte Carlo simulation to determine the equivalent Point Buy of an ability score rolling method. NOTE- This method must be called BEFORE “plot_histogram”.

This method returns self, so you can stack the “plot_histogram” and “get_results” methods, like pbe1.roll_mc().plot_histogram()

Parameters:num_hist – Number of Monte Carlo histories to run. Suggest 10**5
pypbe.core.randint(low, high=None, size=None, dtype='l')

Return random integers from low (inclusive) to high (exclusive).

Return random integers from the “discrete uniform” distribution of the specified dtype in the “half-open” interval [low, high). If high is None (the default), then results are from [0, low).

low : int
Lowest (signed) integer to be drawn from the distribution (unless high=None, in which case this parameter is one above the highest such integer).
high : int, optional
If provided, one above the largest (signed) integer to be drawn from the distribution (see above for behavior if high=None).
size : int or tuple of ints, optional
Output shape. If the given shape is, e.g., (m, n, k), then m * n * k samples are drawn. Default is None, in which case a single value is returned.
dtype : dtype, optional

Desired dtype of the result. All dtypes are determined by their name, i.e., ‘int64’, ‘int’, etc, so byteorder is not available and a specific precision may have different C types depending on the platform. The default value is ‘np.int’.

New in version 1.11.0.

out : int or ndarray of ints
size-shaped array of random integers from the appropriate distribution, or a single such random int if size not provided.
random.random_integers : similar to randint, only for the closed
interval [low, high], and 1 is the lowest value if high is omitted. In particular, this other one is the one to use to generate uniformly distributed discrete non-integers.
>>> np.random.randint(2, size=10)
array([1, 0, 0, 0, 1, 1, 0, 0, 1, 0])
>>> np.random.randint(1, size=10)
array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0])

Generate a 2 x 4 array of ints between 0 and 4, inclusive:

>>> np.random.randint(5, size=(2, 4))
array([[4, 0, 2, 1],
       [3, 2, 2, 0]])

Module contents

pypbe Python Point Buy Equivalent —————————– Intended for tabletop rpgs such as Pathfinder or D&D, this module contains code to run a Monte Carlo simulation to determine the Point Buy Equivalent (PBE) for a given type of ability score rolling method, such as “Roll 4d6 and drop the lowest”.

copyright:
  1. 2017 Eric Strong.
license:

Refer to LICENSE.txt for more information.

pypbe.randint(low, high=None, size=None, dtype='l')

Return random integers from low (inclusive) to high (exclusive).

Return random integers from the “discrete uniform” distribution of the specified dtype in the “half-open” interval [low, high). If high is None (the default), then results are from [0, low).

low : int
Lowest (signed) integer to be drawn from the distribution (unless high=None, in which case this parameter is one above the highest such integer).
high : int, optional
If provided, one above the largest (signed) integer to be drawn from the distribution (see above for behavior if high=None).
size : int or tuple of ints, optional
Output shape. If the given shape is, e.g., (m, n, k), then m * n * k samples are drawn. Default is None, in which case a single value is returned.
dtype : dtype, optional

Desired dtype of the result. All dtypes are determined by their name, i.e., ‘int64’, ‘int’, etc, so byteorder is not available and a specific precision may have different C types depending on the platform. The default value is ‘np.int’.

New in version 1.11.0.

out : int or ndarray of ints
size-shaped array of random integers from the appropriate distribution, or a single such random int if size not provided.
random.random_integers : similar to randint, only for the closed
interval [low, high], and 1 is the lowest value if high is omitted. In particular, this other one is the one to use to generate uniformly distributed discrete non-integers.
>>> np.random.randint(2, size=10)
array([1, 0, 0, 0, 1, 1, 0, 0, 1, 0])
>>> np.random.randint(1, size=10)
array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0])

Generate a 2 x 4 array of ints between 0 and 4, inclusive:

>>> np.random.randint(5, size=(2, 4))
array([[4, 0, 2, 1],
       [3, 2, 2, 0]])