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 get_impact(k: int):
    return conv_syms.ConvertSymbols(
        conversion_policy=conv_pol.get_conversion_policy_attack(
            convertible_symbols=(sym.Hit, ),
            conversion_target=sym.Crit(),
        ),
        conversion_limit=k,
    )
Exemple #3
0
 def get_sides(self) -> List[sym.Symbol]:
     return [
         sym.Crit(),
         sym.Surge(),
         sym.Hit(),
         sym.Blank(),
         sym.Blank(),
         sym.Blank(),
         sym.Blank(),
         sym.Blank(),
     ]
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)
def test_roll__douse():
    douse = att_dse.BlackAttackDouse()
    rerolled_douse = rll.Roll(roll_policy=rll_pol.RollPolicyAttack()).on(douse)

    crit_prob = fractions.Fraction(1, 8) * fractions.Fraction(3, 2)
    assert rerolled_douse.as_dict[dse.RolledDouse(douse,
                                                  sym.Crit())] == crit_prob

    hit_prob = fractions.Fraction(3, 8) * fractions.Fraction(3, 2)
    assert rerolled_douse.as_dict[dse.RolledDouse(douse,
                                                  sym.Hit())] == hit_prob

    blank_prob = fractions.Fraction(3, 8) * fractions.Fraction(1, 2)
    assert rerolled_douse.as_dict[dse.RolledDouse(douse,
                                                  sym.Blank())] == blank_prob
def test_convert_surge__on_symbols():
    symbols = syms.Symbols.from_symbols_list(
        [
            sym.Hit(),
            sym.Surge(),
            sym.Blank(),
        ]
    )
    symbols_target = syms.Symbols.from_symbols_list(
        [
            sym.Hit(),
            sym.Crit(),
            sym.Blank(),
        ]
    )
    assert actions.convert_all_surges_to_crit.on(symbols) == symbols_target
from legion_dice_probs.stochastic_states import symbols as syms
from prob_dist_api import probability_distribution as pd


@pytest.mark.parametrize(
    "output, prob",
    (
            (
                    dse.RolledDouse(douse=att_dse.BlackAttackDouse(), symbol=sym.Blank()),
                    fractions.Fraction(3, 8) * fractions.Fraction(1, 2),  # 3 / 16
            ),
            (
                    dse.RolledDouse(douse=att_dse.BlackAttackDouse(), symbol=sym.Surge()),
                    fractions.Fraction(1, 8) * fractions.Fraction(1, 2),  # 1 / 16
            ),
            (
                    dse.RolledDouse(douse=att_dse.BlackAttackDouse(), symbol=sym.Hit()),
                    fractions.Fraction(3, 8) * (1 + fractions.Fraction(1, 2)),  # 9 / 16
            ),
            (
                    dse.RolledDouse(douse=att_dse.BlackAttackDouse(), symbol=sym.Crit()),
                    fractions.Fraction(1, 8) * (1 + fractions.Fraction(1, 2)),  # 3 / 16
            ),
    )
)
def test_aim__black_attack_douse(output, prob):
    douse = att_dse.BlackAttackDouse()
    rerolled_douse_prob_dist: pd.ProbabilityDistribution = actions.aim.on(douse)
    print(rerolled_douse_prob_dist)
    assert rerolled_douse_prob_dist.as_dict[output] == prob
from legion_dice_probs.events import roll as rll
from legion_dice_probs.events import aim_reroll as aim_rerll
from legion_dice_probs.events.tools import conversion_policy as conv_pol
from legion_dice_probs.events.tools import roll_policy as rll_pol
from legion_dice_probs.stochastic_states import symbol as sym

convert_all_surges_to_hit = conv_syms.ConvertSymbols(
    conversion_policy=conv_pol.get_conversion_policy_attack(
        convertible_symbols=(sym.Surge, ),
        conversion_target=sym.Hit(),
    ))

convert_all_surges_to_crit = conv_syms.ConvertSymbols(
    conversion_policy=conv_pol.get_conversion_policy_attack(
        convertible_symbols=(sym.Surge, ),
        conversion_target=sym.Crit(),
    ))

convert_all_surges_to_block = conv_syms.ConvertSymbols(
    conversion_policy=conv_pol.get_conversion_policy_defence(
        convertible_symbols=(sym.Surge, ),
        conversion_target=sym.Block(),
    ))


def get_use_surge_tokens_attack(k: Optional[int] = None):
    return conv_srge_wtok.ConvertSurgeWithTokens(
        conversion_policy=conv_pol.get_conversion_policy_attack(
            convertible_symbols=(sym.Surge, ),
            conversion_target=sym.Hit(),
        ),
 def __init__(
         self,
         conversion_target: sym.Symbol = sym.Crit(),
 ):
     super().__init__(conversion_target)
from legion_dice_probs.events import convert_symbols as conv_syms
from legion_dice_probs.events.tools import conversion_policy as conv_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
from legion_dice_probs.stochastic_states import symbols as syms


@pytest.mark.parametrize("n_converts, symbols, symbols_target", ((2, [
    sym.Hit(),
    sym.Hit(),
    sym.Blank(),
    sym.Surge(),
    sym.Surge(),
    sym.Crit(),
], [
    sym.Hit(),
    sym.Crit(),
    sym.Crit(),
    sym.Surge(),
    sym.Crit(),
    sym.Hit(),
]), (1, [
    sym.Hit(),
    sym.Hit(),
    sym.Blank(),
    sym.Surge(),
    sym.Surge(),
    sym.Crit(),
], [
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_rolled_douse__surge():
    rolled_douse = dse.RolledDouse(
        douse=att_dse.RedAttackDouse(),
        symbol=sym.Surge(),
    )
    assert actions.convert_all_surges_to_crit.on(rolled_douse).symbol == sym.Crit()
                                                  sym.Hit())] == hit_prob

    blank_prob = fractions.Fraction(3, 8) * fractions.Fraction(1, 2)
    assert rerolled_douse.as_dict[dse.RolledDouse(douse,
                                                  sym.Blank())] == blank_prob


@pytest.mark.parametrize('symbols_before, symbols_after, prob', (
    (
        [sym.Blank(), sym.Blank(), sym.Blank()],
        [sym.Blank(), sym.Blank(), sym.Blank()],
        fractions.Fraction(1, 64),
    ),
    (
        [sym.Blank(), sym.Blank(), sym.Blank()],
        [sym.Blank(), sym.Hit(), sym.Crit()],
        fractions.Fraction(5, 64) * 2,
    ),
    (
        [sym.Blank(), sym.Blank(), sym.Blank()],
        [sym.Hit(), sym.Hit(), sym.Hit()],
        0,
    ),
    (
        [sym.Blank(), sym.Hit(), sym.Blank()],
        [sym.Hit(), sym.Hit(), sym.Hit()],
        fractions.Fraction(25, 64),
    ),
))
def test_roll__rolled_dice_pool__aim__red_dice(symbols_before, symbols_after,
                                               prob):