Skip to content

Commit

Permalink
Merge a1fad41 into 1f21814
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-s-s committed Apr 3, 2019
2 parents 1f21814 + a1fad41 commit 5f5ed0d
Show file tree
Hide file tree
Showing 50 changed files with 877 additions and 320 deletions.
11 changes: 11 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[run]
branch = True
source = .
omit =
tests/*
.tox/*
setup.py
venv/*
time_trials/*
doctests.py

4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
/*.egg

# other
tox.ini
*.npy
*.spec
*.txt
.coverage
.tox
.idea
/time_trials/best_time_data
Expand All @@ -24,3 +24,5 @@ tox.ini
/docs/_build
/_build
run_sphinx.sh
venv/

4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ install:

script:

- coverage run --source=dicetables setup.py test
- COVERALLS_PARALLEL=true
- coverage run -a --source=dicetables setup.py test
- coverage report -m
# Run the doctests
- python doctests.py

after_success:
- COVERALLS_PARALLEL=true
- coveralls
13 changes: 12 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


#################
dicetables v2.5.0
dicetables v2.6.0
#################

Calculate the Combinations For Any Set of Dice
Expand Down Expand Up @@ -139,6 +139,13 @@ StatsStrings(query_values='8-19, 35, 50-62',
5999: 1,000
6000: 1

You can now roll events with a `Roller`

>>> events = dt.DiceTable.new().add_die(dt.Die(6))
>>> roller = dt.Roller(events)
>>> roller.roll() in [1, 2, 3, 4, 5, 6]
True

That should get you started. For details see
`<http://dice-tables.readthedocs.io/en/latest/>`_

Expand Down Expand Up @@ -180,6 +187,10 @@ v2.5.0
- `Parser().add_die_size_limit_kwarg` and `Parser().add_explosions_limit_kwarg` are removed. Use
`Parser().add_limits_kwarg`

v2.6.0

- added `Roller`

.. _`The Dice` : http://dice-tables.readthedocs.io/en/latest/the_dice.html
.. _`DicePool` : http://dice-tables.readthedocs.io/en/latest/the_dice.html#module-dicetables.bestworstmid
7 changes: 4 additions & 3 deletions dicetables/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from __future__ import absolute_import

from dicetables.additiveevents import AdditiveEvents
from dicetables.bestworstmid import BestOfDicePool, WorstOfDicePool, UpperMidOfDicePool, LowerMidOfDicePool
from dicetables.dicerecord import DiceRecord
from dicetables.dicetable import DiceTable, DetailedDiceTable
from dicetables.dieevents import Die, ModDie, WeightedDie, ModWeightedDie, StrongDie, Modifier, ExplodingOn, Exploding
from dicetables.dicerecord import DiceRecord
from dicetables.eventsbases.eventerrors import DiceRecordError, InvalidEventsError
from dicetables.parser import Parser, ParseError, LimitsError
from dicetables.eventsinfo import (EventsCalculations, EventsInformation,
events_range, mean, stddev, percentage_points, percentage_axes, stats,
full_table_string)
from dicetables.bestworstmid import BestOfDicePool, WorstOfDicePool, UpperMidOfDicePool, LowerMidOfDicePool
from dicetables.parser import Parser, ParseError, LimitsError
from dicetables.roller import Roller
3 changes: 1 addition & 2 deletions dicetables/additiveevents.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
"""
from __future__ import absolute_import


from dicetables.eventsbases.integerevents import IntegerEvents
from dicetables.factory.eventsfactory import EventsFactory
from dicetables.tools.dictcombiner import DictCombiner
from dicetables.eventsbases.integerevents import IntegerEvents


def scrub_zeroes(dictionary):
Expand Down
8 changes: 6 additions & 2 deletions dicetables/bestworstmid.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from dicetables.tools.orderedcombinations import ordered_combinations_of_events

from dicetables.dieevents import ProtoDie
from dicetables.tools.orderedcombinations import ordered_combinations_of_events


class DicePool(ProtoDie):
Expand All @@ -9,6 +8,7 @@ class DicePool(ProtoDie):
rolls are selected from the pool of total rolls. Different implementations determine which particular rolls
to select.
"""

def __init__(self, input_die, pool_size, select):
"""
Expand Down Expand Up @@ -65,6 +65,7 @@ class BestOfDicePool(DicePool):
Take the best [select] rolls from a pool of [pool_size] * [input_die].
BestOfDicePool(Die(6), 4, 3) is the best 3 rolls from four six-sided dice.
"""

def __init__(self, input_die, pool_size, select):
super(BestOfDicePool, self).__init__(input_die, pool_size, select)

Expand All @@ -80,6 +81,7 @@ class WorstOfDicePool(DicePool):
Take the worst [select] rolls from a pool of [pool_size] * [input_die].
WorstOfDicePool(Die(6), 4, 3) is the worst 3 rolls from four six-sided dice.
"""

def __init__(self, input_die, pool_size, select):
super(WorstOfDicePool, self).__init__(input_die, pool_size, select)

Expand All @@ -98,6 +100,7 @@ class UpperMidOfDicePool(DicePool):
If there is no perfect middle, take the higher of two choices. For five dice that roll
(1, 1, 2, 3, 4), select=3 takes (1, 2, 3) and select=2 takes (2, 3).
"""

def __init__(self, input_die, pool_size, select):
super(UpperMidOfDicePool, self).__init__(input_die, pool_size, select)

Expand All @@ -117,6 +120,7 @@ class LowerMidOfDicePool(DicePool):
If there is no perfect middle, take the lower of two choices. For five dice that roll
(1, 1, 2, 3, 4), select=3 takes (1, 2, 3) and select=2 takes (1, 2).
"""

def __init__(self, input_die, pool_size, select):
super(LowerMidOfDicePool, self).__init__(input_die, pool_size, select)

Expand Down
3 changes: 1 addition & 2 deletions dicetables/dicerecord.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
"""
from sys import version_info

from dicetables.eventsbases.protodie import ProtoDie
from dicetables.eventsbases.eventerrors import DiceRecordError

from dicetables.eventsbases.protodie import ProtoDie

if version_info[0] < 3:
from dicetables.tools.py2funcs import is_int
Expand Down
1 change: 0 additions & 1 deletion dicetables/dicetable.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"""
from __future__ import absolute_import


from dicetables.additiveevents import AdditiveEvents, EventsDictCreator
from dicetables.eventsinfo import EventsCalculations
from dicetables.factory.eventsfactory import EventsFactory
Expand Down
6 changes: 5 additions & 1 deletion dicetables/dieevents.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"""
import itertools


from dicetables.eventsbases.protodie import ProtoDie


Expand All @@ -13,6 +12,7 @@ class Modifier(ProtoDie):
:code:`Modifier(-3)` rolls -3 and only -3. A Modifier's size and weight are
always 0.
"""

def __init__(self, modifier):
self._mod = modifier
super(Modifier, self).__init__()
Expand Down Expand Up @@ -47,6 +47,7 @@ class Die(ProtoDie):
stores and returns info for a basic Die.
:code:`Die(4)` rolls 1, 2, 3, 4 with equal weight
"""

def __init__(self, die_size):
"""
Expand Down Expand Up @@ -83,6 +84,7 @@ class ModDie(Die):
that changes the values of the rolls.
:code:`ModDie(4, -1)` rolls 0, 1, 2, 3 with equal weight
"""

def __init__(self, die_size, modifier):
"""
Expand Down Expand Up @@ -113,6 +115,7 @@ class WeightedDie(ProtoDie):
stores and returns info for die with different chances for different rolls.
:code:`WeightedDie({1:1, 2:5})` rolls 1 once for every five times that 2 is rolled.
"""

def __init__(self, dictionary_input):
"""
Expand Down Expand Up @@ -350,6 +353,7 @@ class ExplodingOn(ProtoDie):
instantiation VERY slow. Time is proportional to explosion**(len(explodes_on)). It's also linear
with size which gets overshadowed by the first factor.
"""

def __init__(self, input_die, explodes_on, explosions=2):
"""
Expand Down
5 changes: 3 additions & 2 deletions dicetables/eventsbases/protodie.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class ProtoDie(IntegerEvents):
- __repr__
- __str__
"""

def __init__(self):
super(ProtoDie, self).__init__()

Expand Down Expand Up @@ -53,8 +54,8 @@ def __hash__(self):

def __lt__(self, other):
return (
(self.get_size(), self.get_weight(), sorted(self.get_dict().items()), repr(self)) <
(other.get_size(), other.get_weight(), sorted(other.get_dict().items()), repr(other))
(self.get_size(), self.get_weight(), sorted(self.get_dict().items()), repr(self)) <
(other.get_size(), other.get_weight(), sorted(other.get_dict().items()), repr(other))
)

def __eq__(self, other):
Expand Down
11 changes: 6 additions & 5 deletions dicetables/eventsinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@
Can be accessed through objects or wrapper functions.
"""


from __future__ import absolute_import

from collections import namedtuple
from decimal import Decimal

from math import log10
from collections import namedtuple
from dicetables.tools.numberforamtter import NumberFormatter

from dicetables.tools.listtostring import get_string_from_list_of_ints
from dicetables.tools.numberforamtter import NumberFormatter


def safe_true_div(numerator, denominator):
Expand Down Expand Up @@ -69,7 +70,7 @@ def biggest_event(self):
:return: (event, occurrences) for first event with highest occurrences
"""
highest_occurrences = max(self._dict.values())
for event, occurrences in sorted(self._dict.items()):
for event, occurrences in sorted(self._dict.items()): # pragma: no branch
if occurrences == highest_occurrences:
return event, highest_occurrences

Expand All @@ -80,7 +81,7 @@ def biggest_events_all(self):
"""
highest_occurrences = max(self._dict.values())
output = []
for event, occurrences in sorted(self._dict.items()):
for event, occurrences in self._dict.items():
if occurrences == highest_occurrences:
output.append((event, occurrences))
return sorted(output)
Expand Down
34 changes: 12 additions & 22 deletions dicetables/factory/errorhandler.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


class EventsFactoryError(AssertionError):
pass

Expand All @@ -26,7 +24,7 @@ def create_format_kwargs(self, error_code, params):
}
"""
self._assign_parameters(error_code, params)
self._assign_additional_kwargs(error_code)
self._assign_kwargs_from_factory_class()

def _assign_parameters(self, error_code, params):
param_values = {
Expand All @@ -39,26 +37,18 @@ def _assign_parameters(self, error_code, params):
for index, key_name in enumerate(param_values[error_code]):
self._format_kwargs[key_name] = params[index]

def _assign_additional_kwargs(self, error_code):
additional_params = {
'CLASS OVERWRITE': 'class_keys',
'MISSING GETTER': 'current_getters',
'GETTER OVERWRITE': 'factory_getter',
'SIGNATURES DIFFERENT': 'class_keys',
'WTF': 'factory_classes'
def _assign_kwargs_from_factory_class(self):
factory_classes, current_getters = self._factory.get_keys()
kwargs_from_factory = {
'factory_classes': factory_classes,
'current_getters': current_getters
}
new_key = additional_params[error_code]
new_value = None
if new_key == 'class_keys':
new_value = self._factory.get_class_params(self._format_kwargs['events_class'])
elif new_key == 'factory_getter':
new_value = self._factory.get_getter_string(self._format_kwargs['getter_key'])
elif new_key == 'factory_classes':
new_value = self._factory.get_keys()[0]
elif new_key == 'current_getters':
new_value = self._factory.get_keys()[1]

self._format_kwargs[new_key] = new_value
if 'events_class' in self._format_kwargs:
kwargs_from_factory['class_keys'] = self._factory.get_class_params(self._format_kwargs['events_class'])
if 'getter_key' in self._format_kwargs:
kwargs_from_factory['factory_getter'] = self._factory.get_getter_string(self._format_kwargs['getter_key'])

self._format_kwargs.update(kwargs_from_factory)

def create_header(self, error_code, bad_param):
msg_start = 'Error Code: {}\nFactory: {}\nError At: '.format(error_code, self._factory)
Expand Down
3 changes: 1 addition & 2 deletions dicetables/factory/eventsfactory.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"""
A factory class for creating instances of AdditiveEvent and its descendants.
"""
from dicetables.dicerecord import DiceRecord
from dicetables.eventsbases.eventerrors import InvalidEventsError, DiceRecordError
from dicetables.factory.errorhandler import EventsFactoryErrorHandler
from dicetables.factory.factorytools import StaticDict, Getter
from dicetables.factory.warninghandler import EventsFactoryWarningHandler
from dicetables.dicerecord import DiceRecord


class LoaderError(AttributeError):
Expand All @@ -32,7 +32,6 @@ def load(self, new_class):


class EventsFactory(object):

__default_getters = {'get_dict': Getter('get_dict', {0: 1}),
'dice_data': Getter('dice_data', DiceRecord.new()),
'calc_includes_zeroes': Getter('calc_includes_zeroes', True, is_property=True)}
Expand Down

0 comments on commit 5f5ed0d

Please sign in to comment.