def test_convert_surge__on_rolled_dice_pool():
    rolled_dice_pool = dce.RolledDicePool.from_rolled_dice_list(
        [
            dse.RolledDouse(
                douse=att_dse.BlackAttackDouse(),
                symbol=sym.Surge(),
            ),
            dse.RolledDouse(
                douse=att_dse.RedAttackDouse(),
                symbol=sym.Hit(),
            ),
            dse.RolledDouse(
                douse=att_dse.WhiteAttackDouse(),
                symbol=sym.Crit(),
            ),
        ]
    )
    rolled_dice_pool_target = dce.RolledDicePool.from_rolled_dice_list(
        [
            dse.RolledDouse(
                douse=att_dse.RedAttackDouse(),
                symbol=sym.Hit(),
            ),
            dse.RolledDouse(
                douse=att_dse.BlackAttackDouse(),
                symbol=sym.Crit(),
            ),
            dse.RolledDouse(
                douse=att_dse.WhiteAttackDouse(),
                symbol=sym.Crit(),
            ),
        ]
    )
    assert actions.convert_all_surges_to_crit.on(rolled_dice_pool) == rolled_dice_pool_target
def test_convert_surge__on_douse():
    douse = att_dse.WhiteAttackDouse()
    assert actions.convert_all_surges_to_crit.on(douse).as_dict[
               dse.RolledDouse(
                   douse=douse,
                   symbol=sym.Crit()
               )
           ] == fractions.Fraction(2, 8)
    assert actions.convert_all_surges_to_crit.on(douse).as_dict[
               dse.RolledDouse(
                   douse=douse,
                   symbol=sym.Surge()
               )
           ] == fractions.Fraction(0, 8)
Example #3
0
def run_examples_with_raw_dice_probabilities():
    rebel_troopers = dce.DicePool.from_dice_list(
        [
            att_dse.BlackAttackDouse(),
            att_dse.BlackAttackDouse(),
            att_dse.BlackAttackDouse(),
            att_dse.BlackAttackDouse(),
        ]
    )
    print('rebel troopers')
    pprint(count.CountSymbols().on(rebel_troopers).get_best(3))

    rebel_troopers_with_z6_with_trooper = dce.DicePool.from_dice_list(
        [
            att_dse.WhiteAttackDouse(),
            att_dse.WhiteAttackDouse(),
            att_dse.WhiteAttackDouse(),
            att_dse.WhiteAttackDouse(),
            att_dse.WhiteAttackDouse(),
            att_dse.WhiteAttackDouse(),
            att_dse.BlackAttackDouse(),
            att_dse.BlackAttackDouse(),
            att_dse.BlackAttackDouse(),
            att_dse.BlackAttackDouse(),
            att_dse.BlackAttackDouse(),
        ]
    )
    print('rebel troopers with Z6 and trooper')
    pprint(count.CountSymbols().on(rebel_troopers_with_z6_with_trooper).get_best(3))

    droid_toopers_with_gun_with_trooper = dce.DicePool.from_dice_list(
        [
            att_dse.WhiteAttackDouse(),
            att_dse.WhiteAttackDouse(),
            att_dse.WhiteAttackDouse(),
            att_dse.WhiteAttackDouse(),
            att_dse.WhiteAttackDouse(),
            att_dse.WhiteAttackDouse(),
            att_dse.WhiteAttackDouse(),
            att_dse.WhiteAttackDouse(),
            att_dse.BlackAttackDouse(),
            att_dse.BlackAttackDouse(),
            att_dse.BlackAttackDouse(),
        ]
    )
    print('droid troopers')
    pprint(count.CountSymbols().on(droid_toopers_with_gun_with_trooper).get_best(3))
from legion_dice_probs.events import count_symbols as count
from legion_dice_probs.stochastic_objects import attack_douse as att_dse
from legion_dice_probs.stochastic_objects import dice_pool as dce

if __name__ == '__main__':
    rebel_troopers = dce.DicePool.from_dice_list([
        att_dse.BlackAttackDouse(),
        att_dse.BlackAttackDouse(),
        att_dse.BlackAttackDouse(),
        att_dse.BlackAttackDouse(),
    ])
    print('rebel troopers')
    pprint(count.CountSymbols().on(rebel_troopers))

    rebel_troopers_with_z6_with_trooper = dce.DicePool.from_dice_list([
        att_dse.WhiteAttackDouse(),
        att_dse.WhiteAttackDouse(),
        att_dse.WhiteAttackDouse(),
        att_dse.WhiteAttackDouse(),
        att_dse.WhiteAttackDouse(),
        att_dse.WhiteAttackDouse(),
        att_dse.BlackAttackDouse(),
        att_dse.BlackAttackDouse(),
        att_dse.BlackAttackDouse(),
        att_dse.BlackAttackDouse(),
        att_dse.BlackAttackDouse(),
    ])
    print('rebel troopers with Z6 and trooper')
    pprint(count.CountSymbols().on(rebel_troopers_with_z6_with_trooper))

    droid_toopers_with_gun_with_trooper = dce.DicePool.from_dice_list([
def test_convert_symbols__conversion_order__symbols(n_converts, symbols,
                                                    symbols_target):
    conversion = conv_syms.ConvertSymbols(
        conversion_policy=conv_pol.ConversionPolicyAttackAnyToCrit(),
        conversion_limit=n_converts,
    )
    assert conversion.on(syms.Symbols.from_symbols_list(
        symbols)) == syms.Symbols.from_symbols_list(symbols_target)


@pytest.mark.parametrize(
    "conversion_policy, n_converts, rolled_dice, rolled_dice_target", (
        (conv_pol.ConversionPolicyAttackAnyToCrit(), 2, [
            dse.RolledDouse(att_dse.RedAttackDouse(), sym.Blank()),
            dse.RolledDouse(att_dse.BlackAttackDouse(), sym.Surge()),
            dse.RolledDouse(att_dse.WhiteAttackDouse(), sym.Hit()),
        ], [
            dse.RolledDouse(att_dse.RedAttackDouse(), sym.Crit()),
            dse.RolledDouse(att_dse.BlackAttackDouse(), sym.Crit()),
            dse.RolledDouse(att_dse.WhiteAttackDouse(), sym.Hit()),
        ]),
        (conv_pol.ConversionPolicyAttackAnyToCrit(), 1, [
            dse.RolledDouse(att_dse.RedAttackDouse(), sym.Blank()),
            dse.RolledDouse(att_dse.BlackAttackDouse(), sym.Surge()),
            dse.RolledDouse(att_dse.WhiteAttackDouse(), sym.Hit()),
        ], [
            dse.RolledDouse(att_dse.RedAttackDouse(), sym.Crit()),
            dse.RolledDouse(att_dse.BlackAttackDouse(), sym.Surge()),
            dse.RolledDouse(att_dse.WhiteAttackDouse(), sym.Hit()),
        ]),
        (conv_pol.ConversionPolicyAttackAnyToCrit(), 3, [
def test_convert_surge__on_rolled_douse__no_surge():
    rolled_douse = dse.RolledDouse(
        douse=att_dse.WhiteAttackDouse(),
        symbol=sym.Crit(),
    )
    assert actions.convert_all_surges_to_hit.on(rolled_douse) == rolled_douse
def test_convert_surge__on_dice_pool():
    dice_pool = dce.DicePool.from_dice_list(
        [
            att_dse.WhiteAttackDouse(),
            att_dse.RedAttackDouse(),
            att_dse.BlackAttackDouse(),
        ]
    )
    result_all_surge = dce.RolledDicePool.from_rolled_dice_list(
        [
            dse.RolledDouse(
                douse=att_dse.WhiteAttackDouse(),
                symbol=sym.Surge()
            ),
            dse.RolledDouse(
                douse=att_dse.BlackAttackDouse(),
                symbol=sym.Surge()
            ),
            dse.RolledDouse(
                douse=att_dse.RedAttackDouse(),
                symbol=sym.Surge()
            ),
        ]
    )
    assert dice_pool.get_probability_distribution().as_dict[result_all_surge] == fractions.Fraction(
        numerator=1,
        denominator=8 ** 3,
    ), "No conversion sanity check."
    result_all_hit = dce.RolledDicePool.from_rolled_dice_list(
        [
            dse.RolledDouse(
                douse=att_dse.WhiteAttackDouse(),
                symbol=sym.Hit()
            ),
            dse.RolledDouse(
                douse=att_dse.BlackAttackDouse(),
                symbol=sym.Hit()
            ),
            dse.RolledDouse(
                douse=att_dse.RedAttackDouse(),
                symbol=sym.Hit()
            ),
        ]
    )
    assert dice_pool.get_probability_distribution().as_dict[result_all_hit] == fractions.Fraction(
        numerator=1 * 3 * 5,
        denominator=8 ** 3,
    ), "No conversion sanity check."

    dice_pool_converted_to_hit_prob_dist = actions.convert_all_surges_to_hit.on(dice_pool)
    assert dice_pool_converted_to_hit_prob_dist.as_dict[result_all_surge] == 0
    assert dice_pool_converted_to_hit_prob_dist.as_dict[result_all_hit] == fractions.Fraction(
        numerator=2 * 4 * 6,
        denominator=8 ** 3,
    )

    dice_pool_converted_to_hit_prob_dist = actions.convert_all_surges_to_crit.on(dice_pool)
    assert dice_pool_converted_to_hit_prob_dist.as_dict[result_all_surge] == 0
    assert dice_pool_converted_to_hit_prob_dist.as_dict[result_all_hit] == fractions.Fraction(
        numerator=1 * 3 * 5,
        denominator=8 ** 3,
    )
Example #8
0
import pytest

from legion_dice_probs.events import roll as rll
from legion_dice_probs.events.tools import roll_policy as rll_pol
from legion_dice_probs.stochastic_objects import attack_douse as att_dse
from legion_dice_probs.stochastic_objects import dice_pool as dce
from legion_dice_probs.stochastic_objects import douse as dse
from legion_dice_probs.stochastic_states import symbol as sym


@pytest.mark.parametrize("policy, douse_cls, symbol, target_prob_dist", (
    (
        rll_pol.RollPolicyAttack(),
        att_dse.WhiteAttackDouse,
        sym.Blank(),
        att_dse.WhiteAttackDouse().get_probability_distribution(),
    ),
    (
        rll_pol.RollPolicyAttack(),
        att_dse.BlackAttackDouse,
        sym.Surge(),
        att_dse.BlackAttackDouse().get_probability_distribution(),
    ),
    (
        rll_pol.RollPolicyAttackBlanksOnly(),
        att_dse.RedAttackDouse,
        sym.Surge(),
        dse.RolledDouse(att_dse.RedAttackDouse(),
                        sym.Surge()).get_probability_distribution(),
    ),
    (