feat: Create a helper function for the d666 special die

This commit is contained in:
2025-06-03 19:03:19 +02:00
parent 4d92935fda
commit 43f6b61a72
2 changed files with 67 additions and 1 deletions

View File

@@ -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 dont 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