feat: Create a helper function for the d666 special die
This commit is contained in:
@@ -8,6 +8,7 @@ import random
|
||||
import re
|
||||
|
||||
DICE_DESCRIPTOR_PATTERN = re.compile(r"^([0-9]*d[0-9]+)([+-]([0-9]+|[0-9]*d[0-9]+))*$")
|
||||
D666_COMBINATIONS = [(0, 1, 2), (0, 2, 1), (1, 0, 2), (1, 2, 0), (2, 0, 1), (2, 1, 0)]
|
||||
|
||||
|
||||
class Die:
|
||||
@@ -96,3 +97,26 @@ class Die:
|
||||
result += self.modifier
|
||||
|
||||
return result
|
||||
|
||||
|
||||
def d666(strict_order: bool = False) -> list[int]:
|
||||
"""Roll three six sided dice and use them as separate digits
|
||||
|
||||
“d666” is a special die type often used in random tables; here you don’t roll one 666 sided die, but three 6-sided
|
||||
ones, then use the three values of the three digits of the final result.
|
||||
|
||||
:param strict_order: if ``True``, use the dics in strict order. Otherwise, return all possible combinations.
|
||||
:returns: the list of all valid combinations
|
||||
"""
|
||||
|
||||
roll_values = [random.randint(1, 6) for _ in range(3)]
|
||||
results = []
|
||||
|
||||
combinations = [(0, 1, 2)] if strict_order else D666_COMBINATIONS
|
||||
|
||||
for a, b, c in combinations:
|
||||
result = roll_values[a] * 100 + roll_values[b] * 10 + roll_values[c]
|
||||
if result not in results:
|
||||
results.append(result)
|
||||
|
||||
return results
|
||||
|
||||
Reference in New Issue
Block a user