コード例 #1
0
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
コード例 #2
0
def test_convert_surge__on_symbols__no_surge():
    symbols = syms.Symbols.from_symbols_list(
        [
            sym.Hit(),
            sym.Hit(),
            sym.Blank(),
        ]
    )
    assert actions.convert_all_surges_to_crit.on(symbols) == symbols
コード例 #3
0
 def get_sides(self) -> List[sym.Symbol]:
     return [
         sym.Crit(),
         sym.Surge(),
         sym.Hit(),
         sym.Hit(),
         sym.Hit(),
         sym.Blank(),
         sym.Blank(),
         sym.Blank(),
     ]
コード例 #4
0
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(),
        ),
        conversion_limit=
        k,  # Specified by actual number of available tokens in stochastic object/state.
    )
コード例 #5
0
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
コード例 #6
0
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
コード例 #7
0
from typing import Optional

from legion_dice_probs.events import convert_symbols as conv_syms
from legion_dice_probs.events import convert_surge_with_tokens as conv_srge_wtok
from legion_dice_probs.events import count_symbols as count_syms
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):
コード例 #8
0
 def __init__(
         self,
         conversion_target: sym.Symbol = sym.Hit(),
 ):
     super().__init__(conversion_target)
コード例 #9
0
import pytest

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(),
コード例 #10
0
def test_convert_surge__on_symbol__no_surge():
    symbol = sym.Hit()
    assert actions.convert_all_surges_to_crit.on(symbol) == symbol
コード例 #11
0
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,
    )
コード例 #12
0
        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(),
    ),
    (
        rll_pol.RollPolicyAttackCritFish(),
        att_dse.RedAttackDouse,
        sym.Hit(),
        att_dse.RedAttackDouse().get_probability_distribution(),
    ),
))
def test_roll__rolled_douse(policy, douse_cls, symbol, target_prob_dist):
    rolled_douse = dse.RolledDouse(
        douse=douse_cls(),
        symbol=symbol,
    )
    assert rll.Roll(roll_policy=policy, ).on(rolled_douse) == target_prob_dist


def test_roll__douse():
    douse = att_dse.BlackAttackDouse()
    rerolled_douse = rll.Roll(roll_policy=rll_pol.RollPolicyAttack()).on(douse)