-
Notifications
You must be signed in to change notification settings - Fork 38
/
dice_check.py
66 lines (53 loc) · 1.8 KB
/
dice_check.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# Source: https://gist.github.com/MasterGroosha/963c0a82df348419788065ab229094ac
from functools import lru_cache
from typing import List
from fluent.runtime import FluentLocalization
@lru_cache(maxsize=64)
def get_score_change(dice_value: int) -> int:
"""
Checks for the winning combination
:param dice_value: dice value (1-64)
:return: user score change (integer)
"""
# three-of-a-kind (except 777)
if dice_value in (1, 22, 43):
return 7
# starting with two 7's (again, except 777)
elif dice_value in (16, 32, 48):
return 5
# jackpot (777)
elif dice_value == 64:
return 10
else:
return -1
def get_combo_parts(dice_value: int) -> List[str]:
"""
Returns exact icons from dice (bar, grapes, lemon, seven).
Do not edit these values, since they are subject to be translated
by outer code.
:param dice_value: dice value (1-64)
:return: list of icons' texts
"""
# Alternative way (credits to t.me/svinerus):
# return [casino[(dice_value - 1) // i % 4]for i in (1, 4, 16)]
# Do not edit these values; they are actually translation keys
# 0 1 2 3
values = ["bar", "grapes", "lemon", "seven"]
dice_value -= 1
result = []
for _ in range(3):
result.append(values[dice_value % 4])
dice_value //= 4
return result
@lru_cache(maxsize=64)
def get_combo_text(dice_value: int, l10n: FluentLocalization) -> str:
"""
Returns localized string with dice result
:param dice_value: dice value (1-64)
:param l10n: Fluent localization object
:return: string with localized result
"""
parts: list[str] = get_combo_parts(dice_value)
for i in range(len(parts)):
parts[i] = l10n.format_value(parts[i])
return ", ".join(parts)