Esempio n. 1
0
    def reroll(self, hunger_dice, regular_dice, max_reroll_size=3) -> int:
        self.results.clear()

        for die in hunger_dice:
            self.results.append(Die(die_type=DieType.HUNGER, die_value=die))

        reroll_count = 0
        for die in regular_dice:
            if reroll_count >= max_reroll_size:
                self.results.append(
                    Die(die_type=DieType.REGULAR, die_value=die))
                continue

            if die > 5:
                self.results.append(
                    Die(die_type=DieType.REGULAR, die_value=die))
                continue

            value = random.choice(range(1, 10 + 1))
            die = Die(DieType.REGULAR, value)
            self.results.append(die)
            reroll_count += 1

        self.state = self.determineState()
        return reroll_count
Esempio n. 2
0
def test_get_critical_dice():
    dicePool = DicePool()
    dicePool.results.append(Die(DieType.REGULAR, 5))
    dicePool.results.append(Die(DieType.REGULAR, 10))
    dicePool.results.append(Die(DieType.REGULAR, 10))

    actual = dicePool.getCriticalDice()
    assert len(actual) == 2
Esempio n. 3
0
def test_regular_successes():
    dicePool = DicePool()
    for value in range(1, 10 + 1):
        dicePool.results.append(Die(DieType.REGULAR, value))

    successes = dicePool.Successes()
    assert successes == 5
Esempio n. 4
0
def test_get_success_dice():
    dicePool = DicePool()
    for value in range(1, 10 + 1):
        dicePool.results.append(Die(DieType.REGULAR, value))

    actual = dicePool.getSuccessDice()
    assert len(actual) == 5
Esempio n. 5
0
def test_get_beastial_dice():
    dicePool = DicePool()
    for value in range(1, 10 + 1):
        dicePool.results.append(Die(DieType.HUNGER, value))

    actual = dicePool.getBeastialDice()
    assert len(actual) == 1
Esempio n. 6
0
    def roll(self, pool_size: int, hunger_size: int):
        if (hunger_size == None):
            hunger_size = 0

        pool_results = []
        for index in range(pool_size):
            dieType = DieType.HUNGER if index + 1 <= hunger_size else DieType.REGULAR
            value = random.choice(range(1, 10 + 1))
            die = Die(dieType, value)
            pool_results.append(die)

        self.results = pool_results
        self.state = self.determineState()
Esempio n. 7
0
import pygal

from die.die import Die

die = Die()

# 郑几次筛子将其结果放到列表中
results = []
for row_num in range(1000):
    result = die.roll()
    results.append(result)

# 分析结果
frequencies = []
for value in range(1, die.num_sides + 1):
    count = results.count(value)
    frequencies.append(count)

# 可视化图
hist = pygal.Bar()
hist.title = "Results of rolling one D 1000 times"
hist.x_labels = [value for value in range(1, 7)]
hist.x_title = "Result"
hist.y_title = "Frequency of Result"
hist.add('D6', frequencies)
hist.render_to_file("die_visual.svg")
    pytest.param(DicePoolState.SUCCESS, Colours.GREEN),
    pytest.param(DicePoolState.CRITICAL, Colours.PURPLE),
    pytest.param(DicePoolState.MESSY, Colours.PURPLE),
])
def test_get_message_colour(state: DicePoolState, colour):
    dice_pool = DicePool()
    dice_pool.state = state

    message = DicePoolMessage(dice_pool)
    message_colour = message.getMessageColour()

    assert message_colour == colour


@pytest.mark.parametrize("results,expected", [
    pytest.param([Die(die_type=DieType.REGULAR, die_value=10)], '10'),
    pytest.param([
        Die(die_type=DieType.REGULAR, die_value=10),
        Die(die_type=DieType.HUNGER, die_value=3)
    ], '10'),
    pytest.param([
        Die(die_type=DieType.REGULAR, die_value=10),
        Die(die_type=DieType.REGULAR, die_value=1),
        Die(die_type=DieType.HUNGER, die_value=3)
    ], '10,~~1~~'),
])
def test_get_regular_dice_as_text(results, expected):
    dice_pool = DicePool()
    dice_pool.results = results

    message = DicePoolMessage(dice_pool)
Esempio n. 9
0
    actual = dicePool.getCriticalDice()
    assert len(actual) == 2


def test_regular_successes():
    dicePool = DicePool()
    for value in range(1, 10 + 1):
        dicePool.results.append(Die(DieType.REGULAR, value))

    successes = dicePool.Successes()
    assert successes == 5


@pytest.mark.parametrize("results,expected_successes", [
    pytest.param([Die(die_value=10)], 1),
    pytest.param([Die(die_value=10), Die(die_value=10)], 4),
    pytest.param([Die(die_value=10),
                  Die(die_value=10),
                  Die(die_value=10)], 5),
    pytest.param([
        Die(die_value=10),
        Die(die_value=10),
        Die(die_value=10),
        Die(die_value=10)
    ], 8)
])
def test_critical_successes(results, expected_successes):
    dicePool = DicePool()
    dicePool.results = results
Esempio n. 10
0
def test_init_default():
    die = Die()

    assert die.die_type == DieType.REGULAR
    assert die.die_value == 0
Esempio n. 11
0
def test_init_empty_dice_pool(die_type: DieType, die_value: int):
    die = Die(die_type, die_value)

    assert die.die_type == die_type
    assert die.die_value == die_value