Ejemplo n.º 1
0
def sorted_attributes(roll_expr: str='3d6') -> None:
    accum = [([o], p) for o, p in odds.dice_notation_rv(roll_expr)]
    for _ in range(1, 6):
        accum = odds.dedupe_mrv(odds.sorted_mrv(
            odds.cartesian_product_mrv(accum,
                                       odds.dice_notation_rv(roll_expr))))
    for _class, min_attributes in sorted(dice.classes.MIN_ATTRIBUTES.items(),
                                         key=operator.itemgetter(0)):
        sorted_min_attributes = sorted(min_attributes)
        cumulative_p = 0.0
        for a, p in accum:
            if list_greater_or_equal(a, sorted_min_attributes):
                cumulative_p += p
        print('{}: ({}%)'.format(_class, PROB_FMT % (100.0 * cumulative_p)))
Ejemplo n.º 2
0
def best_of(roll_expr: str='3d6', best_of: int=12) -> None:
    assert(best_of >= 6)
    accum = [([o], p) for o, p in odds.dice_notation_rv(roll_expr)]
    for _ in range(1, best_of):
        prod = odds.cartesian_product_mrv(accum, odds.dice_notation_rv(roll_expr))
        sort = odds.sorted_mrv(prod)
        short = odds.tail_mrv(sort, 6)
        dedupe = odds.dedupe_mrv(short)
        accum = dedupe
    for _class, min_attributes in sorted(dice.classes.MIN_ATTRIBUTES.items(),
                                         key=operator.itemgetter(0)):
        sorted_min_attributes = sorted(min_attributes)
        cumulative_p = 0.0
        for a, p in accum:
            if list_greater_or_equal(a[:6], sorted_min_attributes):
                cumulative_p += p
        print('{}: ({}%)'.format(_class, PROB_FMT % (100.0 * cumulative_p)))
Ejemplo n.º 3
0
 def test_multiply_scalar_rv(self) -> None:
     d6_odds = odds.dice_notation_rv('d6')
     multiply_scalar_odds = odds.multiply_scalar_rv(d6_odds, 4)
     self.assertEqual(6, len(multiply_scalar_odds))
     for i, p in multiply_scalar_odds:
         if i == 4:
             self.assertAlmostEqual(p, 1 / 6)
         if i == 8:
             self.assertAlmostEqual(p, 1 / 6)
Ejemplo n.º 4
0
 def test_sum_rv(self) -> None:
     d6_odds = odds.dice_notation_rv('d6')
     sum_odds = odds.sum_rv(d6_odds, d6_odds)
     self.assertEqual(11, len(sum_odds))
     for i, p in sum_odds:
         if i == 2:
             self.assertAlmostEqual(p, 1 / 36)
         if i == 3:
             self.assertAlmostEqual(p, 2 / 36)
Ejemplo n.º 5
0
 def test_dice_notation_rv(self) -> None:
     d6_odds = odds.dice_notation_rv('d6')
     for i, pair in enumerate(d6_odds, start=1):
         self.assertEqual(i, pair[0])
         self.assertEqual(fractions.Fraction(1, 6), pair[1])