absfuyu 4.2.0__py3-none-any.whl → 5.0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of absfuyu might be problematic. Click here for more details.
- absfuyu/__init__.py +4 -4
- absfuyu/__main__.py +13 -1
- absfuyu/cli/__init__.py +2 -2
- absfuyu/cli/color.py +9 -2
- absfuyu/cli/config_group.py +2 -2
- absfuyu/cli/do_group.py +2 -37
- absfuyu/cli/game_group.py +2 -2
- absfuyu/cli/tool_group.py +7 -7
- absfuyu/config/__init__.py +17 -34
- absfuyu/core/__init__.py +49 -0
- absfuyu/core/baseclass.py +299 -0
- absfuyu/core/baseclass2.py +165 -0
- absfuyu/core/decorator.py +67 -0
- absfuyu/core/docstring.py +166 -0
- absfuyu/core/dummy_cli.py +67 -0
- absfuyu/core/dummy_func.py +49 -0
- absfuyu/dxt/__init__.py +42 -0
- absfuyu/dxt/dictext.py +201 -0
- absfuyu/dxt/dxt_support.py +79 -0
- absfuyu/dxt/intext.py +586 -0
- absfuyu/dxt/listext.py +508 -0
- absfuyu/dxt/strext.py +530 -0
- absfuyu/extra/__init__.py +12 -0
- absfuyu/extra/beautiful.py +252 -0
- absfuyu/{extensions → extra}/data_analysis.py +51 -82
- absfuyu/fun/__init__.py +110 -135
- absfuyu/fun/tarot.py +11 -19
- absfuyu/game/__init__.py +8 -2
- absfuyu/game/game_stat.py +8 -2
- absfuyu/game/sudoku.py +9 -3
- absfuyu/game/tictactoe.py +14 -7
- absfuyu/game/wordle.py +16 -10
- absfuyu/general/__init__.py +8 -81
- absfuyu/general/content.py +24 -38
- absfuyu/general/human.py +108 -228
- absfuyu/general/shape.py +1334 -0
- absfuyu/logger.py +10 -15
- absfuyu/pkg_data/__init__.py +137 -100
- absfuyu/pkg_data/deprecated.py +133 -0
- absfuyu/sort.py +6 -130
- absfuyu/tools/__init__.py +2 -2
- absfuyu/tools/checksum.py +33 -22
- absfuyu/tools/converter.py +51 -48
- absfuyu/{general → tools}/generator.py +17 -42
- absfuyu/tools/keygen.py +25 -30
- absfuyu/tools/obfuscator.py +246 -112
- absfuyu/tools/passwordlib.py +100 -30
- absfuyu/tools/shutdownizer.py +68 -47
- absfuyu/tools/web.py +4 -11
- absfuyu/util/__init__.py +17 -17
- absfuyu/util/api.py +10 -15
- absfuyu/util/json_method.py +7 -24
- absfuyu/util/lunar.py +5 -11
- absfuyu/util/path.py +22 -27
- absfuyu/util/performance.py +43 -67
- absfuyu/util/shorten_number.py +65 -14
- absfuyu/util/zipped.py +11 -17
- absfuyu/version.py +59 -42
- {absfuyu-4.2.0.dist-info → absfuyu-5.0.1.dist-info}/METADATA +41 -14
- absfuyu-5.0.1.dist-info/RECORD +68 -0
- absfuyu/core.py +0 -57
- absfuyu/everything.py +0 -32
- absfuyu/extensions/__init__.py +0 -12
- absfuyu/extensions/beautiful.py +0 -188
- absfuyu/fun/WGS.py +0 -134
- absfuyu/general/data_extension.py +0 -1796
- absfuyu/tools/stats.py +0 -226
- absfuyu/util/pkl.py +0 -67
- absfuyu-4.2.0.dist-info/RECORD +0 -59
- {absfuyu-4.2.0.dist-info → absfuyu-5.0.1.dist-info}/WHEEL +0 -0
- {absfuyu-4.2.0.dist-info → absfuyu-5.0.1.dist-info}/entry_points.txt +0 -0
- {absfuyu-4.2.0.dist-info → absfuyu-5.0.1.dist-info}/licenses/LICENSE +0 -0
absfuyu/fun/__init__.py
CHANGED
|
@@ -3,28 +3,24 @@ Absfuyu: Fun
|
|
|
3
3
|
------------
|
|
4
4
|
Some fun or weird stuff
|
|
5
5
|
|
|
6
|
-
Version:
|
|
7
|
-
Date updated:
|
|
6
|
+
Version: 5.0.0
|
|
7
|
+
Date updated: 22/02/2025 (dd/mm/yyyy)
|
|
8
8
|
"""
|
|
9
9
|
|
|
10
10
|
# Library
|
|
11
|
-
|
|
12
|
-
import subprocess
|
|
13
|
-
import sys
|
|
11
|
+
# ---------------------------------------------------------------------------
|
|
14
12
|
from datetime import date
|
|
15
13
|
|
|
14
|
+
from absfuyu.core import deprecated, versionadded, versionchanged
|
|
16
15
|
from absfuyu.logger import logger
|
|
17
|
-
from absfuyu.
|
|
16
|
+
from absfuyu.tools.shutdownizer import ShutDownizer
|
|
18
17
|
from absfuyu.util.lunar import LunarCalendar
|
|
19
18
|
|
|
20
19
|
|
|
21
20
|
# Function
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
month: int,
|
|
26
|
-
zodiac13: bool = False,
|
|
27
|
-
) -> str:
|
|
21
|
+
# ---------------------------------------------------------------------------
|
|
22
|
+
@versionchanged("5.0.0", reason="Updated functionality")
|
|
23
|
+
def zodiac_sign(day: int, month: int, zodiac13: bool = False) -> str:
|
|
28
24
|
"""
|
|
29
25
|
Calculate zodiac sign
|
|
30
26
|
|
|
@@ -46,137 +42,74 @@ def zodiac_sign(
|
|
|
46
42
|
"""
|
|
47
43
|
|
|
48
44
|
# Condition check
|
|
49
|
-
|
|
50
|
-
0 < day < 32,
|
|
51
|
-
0 < month < 13,
|
|
52
|
-
]
|
|
53
|
-
if not all(conditions):
|
|
45
|
+
if not 1 <= month <= 12 or not 1 <= day <= 31:
|
|
54
46
|
raise ValueError("Value out of range")
|
|
55
47
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
), # 21/5-20/6
|
|
72
|
-
"Cancer (W)": any(
|
|
73
|
-
[month == 6 and day >= 21, month == 7 and day <= 22]
|
|
74
|
-
), # 21/6-22/7
|
|
75
|
-
"Leo (F)": any(
|
|
76
|
-
[month == 7 and day >= 23, month == 8 and day <= 22]
|
|
77
|
-
), # 23/7-22/8
|
|
78
|
-
"Virgo (E)": any(
|
|
79
|
-
[month == 8 and day >= 23, month == 9 and day <= 22]
|
|
80
|
-
), # 23/8-22/9
|
|
81
|
-
"Libra (A)": any(
|
|
82
|
-
[month == 9 and day >= 23, month == 10 and day <= 22]
|
|
83
|
-
), # 23/9-22/10
|
|
84
|
-
"Scorpio (W)": any(
|
|
85
|
-
[month == 10 and day >= 23, month == 11 and day <= 21]
|
|
86
|
-
), # 23/10-21/11
|
|
87
|
-
"Sagittarius (F)": any(
|
|
88
|
-
[month == 11 and day >= 22, month == 12 and day <= 21]
|
|
89
|
-
), # 22/11-21/12
|
|
90
|
-
"Capricorn (E)": any(
|
|
91
|
-
[month == 12 and day >= 22, month == 1 and day <= 19]
|
|
92
|
-
), # 22/12-19/1
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
if zodiac13: # 13 zodiac signs
|
|
96
|
-
zodiac = {
|
|
97
|
-
"Aquarius": any(
|
|
98
|
-
[month == 2 and day >= 17, month == 3 and day <= 11]
|
|
99
|
-
), # 17/2-11/3
|
|
100
|
-
"Pisces": any(
|
|
101
|
-
[month == 3 and day >= 12, month == 4 and day <= 18]
|
|
102
|
-
), # 12/3-18-4
|
|
103
|
-
"Aries": any(
|
|
104
|
-
[month == 4 and day >= 19, month == 5 and day <= 13]
|
|
105
|
-
), # 19/4-13-5
|
|
106
|
-
"Taurus": any(
|
|
107
|
-
[month == 5 and day >= 14, month == 6 and day <= 21]
|
|
108
|
-
), # 14/5-21/6
|
|
109
|
-
"Gemini": any(
|
|
110
|
-
[month == 6 and day >= 22, month == 7 and day <= 20]
|
|
111
|
-
), # 22/6-20/7
|
|
112
|
-
"Cancer": any(
|
|
113
|
-
[month == 7 and day >= 21, month == 8 and day <= 10]
|
|
114
|
-
), # 21/7-10/8
|
|
115
|
-
"Leo": any(
|
|
116
|
-
[month == 8 and day >= 11, month == 9 and day <= 16]
|
|
117
|
-
), # 11/8-16/9
|
|
118
|
-
"Virgo": any(
|
|
119
|
-
[month == 9 and day >= 17, month == 10 and day <= 30]
|
|
120
|
-
), # 17/9-30/10
|
|
121
|
-
"Libra": any(
|
|
122
|
-
[month == 10 and day >= 31, month == 11 and day <= 23]
|
|
123
|
-
), # 31/10-23/11
|
|
124
|
-
"Scorpio": any(
|
|
125
|
-
[month == 11 and day >= 24, month == 11 and day <= 29]
|
|
126
|
-
), # 24/11-29/11
|
|
127
|
-
"Ophiuchus": any(
|
|
128
|
-
[month == 11 and day >= 30, month == 12 and day <= 17]
|
|
129
|
-
), # 30/11-17/12
|
|
130
|
-
"Sagittarius": any(
|
|
131
|
-
[month == 12 and day >= 18, month == 1 and day <= 20]
|
|
132
|
-
), # 18/12-20/1
|
|
133
|
-
"Capricorn": any(
|
|
134
|
-
[month == 1 and day >= 21, month == 2 and day <= 16]
|
|
135
|
-
), # 21/1-16/2
|
|
48
|
+
if zodiac13:
|
|
49
|
+
zodiac_dates = {
|
|
50
|
+
"Capricorn": ((1, 21), (2, 16)),
|
|
51
|
+
"Aquarius": ((2, 17), (3, 11)),
|
|
52
|
+
"Pisces": ((3, 12), (4, 18)),
|
|
53
|
+
"Aries": ((4, 19), (5, 13)),
|
|
54
|
+
"Taurus": ((5, 14), (6, 21)),
|
|
55
|
+
"Gemini": ((6, 22), (7, 20)),
|
|
56
|
+
"Cancer": ((7, 21), (8, 10)),
|
|
57
|
+
"Leo": ((8, 11), (9, 16)),
|
|
58
|
+
"Virgo": ((9, 17), (10, 30)),
|
|
59
|
+
"Libra": ((10, 31), (11, 23)),
|
|
60
|
+
"Scorpio": ((11, 24), (11, 29)),
|
|
61
|
+
"Ophiuchus": ((11, 30), (12, 17)),
|
|
62
|
+
"Sagittarius": ((12, 18), (1, 20)),
|
|
136
63
|
}
|
|
64
|
+
else:
|
|
65
|
+
zodiac_dates = {
|
|
66
|
+
"Capricorn (E)": ((12, 22), (1, 19)),
|
|
67
|
+
"Aquarius (A)": ((1, 20), (2, 18)),
|
|
68
|
+
"Pisces (W)": ((2, 19), (3, 20)),
|
|
69
|
+
"Aries (F)": ((3, 21), (4, 19)),
|
|
70
|
+
"Taurus (E)": ((4, 20), (5, 20)),
|
|
71
|
+
"Gemini (A)": ((5, 21), (6, 20)),
|
|
72
|
+
"Cancer (W)": ((6, 21), (7, 22)),
|
|
73
|
+
"Leo (F)": ((7, 23), (8, 22)),
|
|
74
|
+
"Virgo (E)": ((8, 23), (9, 22)),
|
|
75
|
+
"Libra (A)": ((9, 23), (10, 22)),
|
|
76
|
+
"Scorpio (W)": ((10, 23), (11, 21)),
|
|
77
|
+
"Sagittarius (F)": ((11, 22), (12, 21)),
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
result = ""
|
|
81
|
+
for sign, (start_date, end_date) in zodiac_dates.items():
|
|
82
|
+
start_month, start_day = start_date
|
|
83
|
+
end_month, end_day = end_date
|
|
137
84
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
85
|
+
if (month == start_month and day >= start_day) or (
|
|
86
|
+
month == end_month and day <= end_day
|
|
87
|
+
):
|
|
88
|
+
result = sign
|
|
89
|
+
break
|
|
90
|
+
return result
|
|
141
91
|
|
|
142
92
|
|
|
93
|
+
@deprecated("5.0.0", reason="API shutdown, will be removed later")
|
|
143
94
|
def im_bored() -> str:
|
|
144
95
|
"""
|
|
145
96
|
Get random activity from ``boredapi`` website
|
|
146
97
|
|
|
147
|
-
|
|
98
|
+
Returns
|
|
99
|
+
-------
|
|
100
|
+
str
|
|
101
|
+
Random activity
|
|
148
102
|
"""
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
def force_shutdown():
|
|
157
|
-
"""Force the computer to shutdown"""
|
|
158
|
-
# Get operating system
|
|
159
|
-
os_name = sys.platform
|
|
160
|
-
|
|
161
|
-
# Shutdown
|
|
162
|
-
shutdown = {
|
|
163
|
-
# Windows
|
|
164
|
-
"win32": "shutdown -f -s -t 0".split(),
|
|
165
|
-
"cygwin": "shutdown -f -s -t 0".split(),
|
|
166
|
-
# Mac OS
|
|
167
|
-
"darwin": ["osascript", "-e", 'tell app "System Events" to shut down'],
|
|
168
|
-
# Linux
|
|
169
|
-
"linux": "shutdown -h now".split(),
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
if os_name in shutdown:
|
|
173
|
-
return subprocess.run(shutdown[os_name])
|
|
174
|
-
else:
|
|
175
|
-
return subprocess.run(shutdown["linux"])
|
|
103
|
+
raise SystemExit("API shuted down")
|
|
104
|
+
# try:
|
|
105
|
+
# api = APIRequest("https://www.boredapi.com/api/activity")
|
|
106
|
+
# return api.fetch_data_only().json()["activity"] # type: ignore
|
|
107
|
+
# except Exception:
|
|
108
|
+
# return "FAILED"
|
|
176
109
|
|
|
177
110
|
|
|
178
111
|
# For new year only
|
|
179
|
-
def happy_new_year(forced: bool = False, include_lunar: bool = False):
|
|
112
|
+
def happy_new_year(forced: bool = False, include_lunar: bool = False) -> None:
|
|
180
113
|
"""
|
|
181
114
|
Only occurs on 01/01 every year
|
|
182
115
|
|
|
@@ -190,7 +123,7 @@ def happy_new_year(forced: bool = False, include_lunar: bool = False):
|
|
|
190
123
|
"""
|
|
191
124
|
|
|
192
125
|
if forced:
|
|
193
|
-
return
|
|
126
|
+
return ShutDownizer().shutdown()
|
|
194
127
|
|
|
195
128
|
today = date.today()
|
|
196
129
|
m = today.month
|
|
@@ -207,12 +140,54 @@ def happy_new_year(forced: bool = False, include_lunar: bool = False):
|
|
|
207
140
|
|
|
208
141
|
if solar_new_year or lunar_new_year:
|
|
209
142
|
print("Happy New Year! You should take rest now.")
|
|
210
|
-
return
|
|
143
|
+
return ShutDownizer().shutdown()
|
|
211
144
|
else:
|
|
212
145
|
raise SystemExit("The time has not come yet")
|
|
213
146
|
|
|
214
147
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
148
|
+
@versionadded("5.0.0")
|
|
149
|
+
def human_year_to_dog_year(
|
|
150
|
+
human_year: int | float, is_small: bool = True
|
|
151
|
+
) -> int | float:
|
|
152
|
+
"""
|
|
153
|
+
Convert human's year to dog's year
|
|
154
|
+
|
|
155
|
+
General Guidelines:
|
|
156
|
+
1. First Year: The first year of a dog's life
|
|
157
|
+
is roughly equal to 15 human years.
|
|
158
|
+
2. Second Year: The second year adds about 9 human years,
|
|
159
|
+
making a 2-year-old dog equivalent to about 24 human years.
|
|
160
|
+
3. Subsequent Years: After the second year,
|
|
161
|
+
each additional yeartypically equals about 4-5 human years,
|
|
162
|
+
depending on the dog's size and breed. (Small-4, Large-5)
|
|
163
|
+
|
|
164
|
+
Parameters
|
|
165
|
+
----------
|
|
166
|
+
human_year : int | float
|
|
167
|
+
Dog's age in human year
|
|
168
|
+
|
|
169
|
+
is_small : bool, optional
|
|
170
|
+
Is the dog small or not, by default ``True``
|
|
171
|
+
|
|
172
|
+
Returns
|
|
173
|
+
-------
|
|
174
|
+
int | float
|
|
175
|
+
Dog's year/age
|
|
176
|
+
|
|
177
|
+
Raises
|
|
178
|
+
------
|
|
179
|
+
ValueError
|
|
180
|
+
When ``human_year`` < 0
|
|
181
|
+
"""
|
|
182
|
+
|
|
183
|
+
if human_year < 0:
|
|
184
|
+
raise ValueError("Value must be positive")
|
|
185
|
+
if human_year <= 1:
|
|
186
|
+
return human_year * 15
|
|
187
|
+
elif human_year <= 2:
|
|
188
|
+
return 15 + (human_year - 1) * 9
|
|
189
|
+
else:
|
|
190
|
+
if is_small:
|
|
191
|
+
return 24 + (human_year - 2) * 4
|
|
192
|
+
else:
|
|
193
|
+
return 24 + (human_year - 2) * 5
|
absfuyu/fun/tarot.py
CHANGED
|
@@ -4,8 +4,8 @@ Absfuyu: Tarot
|
|
|
4
4
|
Tarot stuff
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
Version:
|
|
8
|
-
Date updated:
|
|
7
|
+
Version: 5.0.0
|
|
8
|
+
Date updated: 22/02/2025 (dd/mm/yyyy)
|
|
9
9
|
|
|
10
10
|
Usage:
|
|
11
11
|
------
|
|
@@ -14,21 +14,22 @@ Usage:
|
|
|
14
14
|
"""
|
|
15
15
|
|
|
16
16
|
# Module level
|
|
17
|
-
|
|
17
|
+
# ---------------------------------------------------------------------------
|
|
18
18
|
__all__ = ["Tarot", "TarotCard"]
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
# Library
|
|
22
|
-
|
|
22
|
+
# ---------------------------------------------------------------------------
|
|
23
23
|
import random
|
|
24
24
|
|
|
25
|
+
from absfuyu.core import BaseClass, versionadded
|
|
25
26
|
from absfuyu.logger import logger
|
|
26
|
-
from absfuyu.pkg_data import DataList
|
|
27
|
-
from absfuyu.util.pkl import Pickler
|
|
27
|
+
from absfuyu.pkg_data import DataList, DataLoader
|
|
28
28
|
|
|
29
29
|
|
|
30
30
|
# Class
|
|
31
|
-
|
|
31
|
+
# ---------------------------------------------------------------------------
|
|
32
|
+
@versionadded("2.6.0")
|
|
32
33
|
class TarotCard:
|
|
33
34
|
"""Tarot card"""
|
|
34
35
|
|
|
@@ -55,7 +56,8 @@ class TarotCard:
|
|
|
55
56
|
return self.__str__()
|
|
56
57
|
|
|
57
58
|
|
|
58
|
-
|
|
59
|
+
@versionadded("2.6.0")
|
|
60
|
+
class Tarot(BaseClass):
|
|
59
61
|
"""Tarot data"""
|
|
60
62
|
|
|
61
63
|
def __init__(self) -> None:
|
|
@@ -64,9 +66,6 @@ class Tarot:
|
|
|
64
66
|
def __str__(self) -> str:
|
|
65
67
|
return f"{self.__class__.__name__}()"
|
|
66
68
|
|
|
67
|
-
def __repr__(self) -> str:
|
|
68
|
-
return self.__str__()
|
|
69
|
-
|
|
70
69
|
@property
|
|
71
70
|
def tarot_deck(self) -> list[TarotCard]:
|
|
72
71
|
"""
|
|
@@ -74,7 +73,7 @@ class Tarot:
|
|
|
74
73
|
|
|
75
74
|
:rtype: list[TarotCard]
|
|
76
75
|
"""
|
|
77
|
-
tarot_data: list =
|
|
76
|
+
tarot_data: list = DataLoader(self.data_location).load()
|
|
78
77
|
logger.debug(f"{len(tarot_data)} tarot cards loaded")
|
|
79
78
|
return [
|
|
80
79
|
TarotCard(
|
|
@@ -98,10 +97,3 @@ class Tarot:
|
|
|
98
97
|
Random Tarot card
|
|
99
98
|
"""
|
|
100
99
|
return random.choice(self.tarot_deck)
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
# Run
|
|
104
|
-
###########################################################################
|
|
105
|
-
if __name__ == "__main__":
|
|
106
|
-
logger.setLevel(10)
|
|
107
|
-
pass
|
absfuyu/game/__init__.py
CHANGED
|
@@ -3,21 +3,27 @@ Absfuyu: Game
|
|
|
3
3
|
-------------
|
|
4
4
|
Contain some game that can be played on terminal
|
|
5
5
|
|
|
6
|
-
Version:
|
|
7
|
-
Date updated:
|
|
6
|
+
Version: 5.0.0
|
|
7
|
+
Date updated: 22/02/2025 (dd/mm/yyyy)
|
|
8
8
|
"""
|
|
9
9
|
|
|
10
|
+
# Module level
|
|
11
|
+
# ---------------------------------------------------------------------------
|
|
10
12
|
__all__ = [
|
|
11
13
|
"game_escapeLoop",
|
|
12
14
|
"game_RockPaperScissors",
|
|
13
15
|
]
|
|
14
16
|
|
|
15
17
|
|
|
18
|
+
# Library
|
|
19
|
+
# ---------------------------------------------------------------------------
|
|
16
20
|
import random
|
|
17
21
|
import time
|
|
18
22
|
|
|
19
23
|
from .game_stat import GameStats
|
|
20
24
|
|
|
25
|
+
# Game
|
|
26
|
+
# ---------------------------------------------------------------------------
|
|
21
27
|
# Escape loop
|
|
22
28
|
_ESCAPE_LOOP_GAME_MSG = """\
|
|
23
29
|
Are you sure about this?
|
absfuyu/game/game_stat.py
CHANGED
|
@@ -1,17 +1,23 @@
|
|
|
1
1
|
"""
|
|
2
2
|
Game: Game Stat
|
|
3
3
|
|
|
4
|
-
Version:
|
|
5
|
-
Date updated:
|
|
4
|
+
Version: 5.0.0
|
|
5
|
+
Date updated: 22/02/2025 (dd/mm/yyyy)
|
|
6
6
|
"""
|
|
7
7
|
|
|
8
|
+
# Module level
|
|
9
|
+
# ---------------------------------------------------------------------------
|
|
8
10
|
__all__ = ["GameStats"]
|
|
9
11
|
|
|
10
12
|
|
|
13
|
+
# Library
|
|
14
|
+
# ---------------------------------------------------------------------------
|
|
11
15
|
from dataclasses import dataclass, field
|
|
12
16
|
from typing import Literal
|
|
13
17
|
|
|
14
18
|
|
|
19
|
+
# Class
|
|
20
|
+
# ---------------------------------------------------------------------------
|
|
15
21
|
@dataclass
|
|
16
22
|
class GameStats:
|
|
17
23
|
win: int = field(default=0)
|
absfuyu/game/sudoku.py
CHANGED
|
@@ -3,8 +3,8 @@ Game: Sudoku
|
|
|
3
3
|
------------
|
|
4
4
|
Sudoku 9x9 Solver
|
|
5
5
|
|
|
6
|
-
Version:
|
|
7
|
-
Date updated:
|
|
6
|
+
Version: 5.0.0
|
|
7
|
+
Date updated: 22/02/2025 (dd/mm/yyyy)
|
|
8
8
|
|
|
9
9
|
Credit:
|
|
10
10
|
-------
|
|
@@ -12,12 +12,18 @@ Credit:
|
|
|
12
12
|
- [Solve algo](https://www.techwithtim.net/tutorials/python-programming/sudoku-solver-backtracking/)
|
|
13
13
|
"""
|
|
14
14
|
|
|
15
|
+
# Module level
|
|
16
|
+
# ---------------------------------------------------------------------------
|
|
15
17
|
__all__ = ["Sudoku"]
|
|
16
18
|
|
|
17
19
|
|
|
20
|
+
# Library
|
|
21
|
+
# ---------------------------------------------------------------------------
|
|
18
22
|
from typing import Literal
|
|
19
23
|
|
|
20
24
|
|
|
25
|
+
# Class
|
|
26
|
+
# ---------------------------------------------------------------------------
|
|
21
27
|
class Sudoku:
|
|
22
28
|
|
|
23
29
|
def __init__(self, sudoku_data: list[list[int]]) -> None:
|
|
@@ -284,7 +290,7 @@ class Sudoku:
|
|
|
284
290
|
|
|
285
291
|
|
|
286
292
|
# Run
|
|
287
|
-
|
|
293
|
+
# ---------------------------------------------------------------------------
|
|
288
294
|
if __name__ == "__main__":
|
|
289
295
|
test = Sudoku.hardest_sudoku()
|
|
290
296
|
print(test.solve().to_board_form())
|
absfuyu/game/tictactoe.py
CHANGED
|
@@ -2,22 +2,31 @@
|
|
|
2
2
|
Game: Tic Tac Toe
|
|
3
3
|
-----------------
|
|
4
4
|
|
|
5
|
-
Version:
|
|
6
|
-
Date updated:
|
|
5
|
+
Version: 5.0.0
|
|
6
|
+
Date updated: 22/02/2025 (dd/mm/yyyy)
|
|
7
7
|
"""
|
|
8
8
|
|
|
9
|
+
|
|
10
|
+
# Module level
|
|
11
|
+
# ---------------------------------------------------------------------------
|
|
9
12
|
__all__ = ["TicTacToe", "GameMode"]
|
|
10
13
|
|
|
11
14
|
|
|
15
|
+
# Library
|
|
16
|
+
# ---------------------------------------------------------------------------
|
|
12
17
|
import random
|
|
13
18
|
import time
|
|
14
19
|
from typing import Literal, NamedTuple
|
|
15
20
|
|
|
16
|
-
from absfuyu.core import CLITextColor
|
|
21
|
+
from absfuyu.core import BaseClass, CLITextColor, versionadded
|
|
17
22
|
|
|
23
|
+
# Type
|
|
24
|
+
# ---------------------------------------------------------------------------
|
|
18
25
|
BoardGame = list[list[str]]
|
|
19
26
|
|
|
20
27
|
|
|
28
|
+
# Class
|
|
29
|
+
# ---------------------------------------------------------------------------
|
|
21
30
|
class Pos(NamedTuple):
|
|
22
31
|
"""Position"""
|
|
23
32
|
|
|
@@ -37,7 +46,8 @@ class GameStateResult(NamedTuple):
|
|
|
37
46
|
pos: int
|
|
38
47
|
|
|
39
48
|
|
|
40
|
-
|
|
49
|
+
@versionadded("3.3.3")
|
|
50
|
+
class TicTacToe(BaseClass):
|
|
41
51
|
"""Tic Tac Toe game"""
|
|
42
52
|
|
|
43
53
|
def __init__(
|
|
@@ -79,9 +89,6 @@ class TicTacToe:
|
|
|
79
89
|
def __str__(self) -> str:
|
|
80
90
|
return f"{self.__class__.__name__}(game_size={self.row_size})"
|
|
81
91
|
|
|
82
|
-
def __repr__(self) -> str:
|
|
83
|
-
return self.__str__()
|
|
84
|
-
|
|
85
92
|
# Game
|
|
86
93
|
def _gen_board(self) -> BoardGame:
|
|
87
94
|
"""
|
absfuyu/game/wordle.py
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Game: Wordle Solver
|
|
3
3
|
-------------------
|
|
4
4
|
|
|
5
|
-
Version:
|
|
6
|
-
Date updated:
|
|
5
|
+
Version: 5.0.0
|
|
6
|
+
Date updated: 22/02/2025 (dd/mm/yyyy)
|
|
7
7
|
|
|
8
8
|
Usage:
|
|
9
9
|
------
|
|
@@ -15,16 +15,22 @@ Credit:
|
|
|
15
15
|
- [Words](https://raw.githubusercontent.com/dwyl/english-words/master/words_dictionary.json)
|
|
16
16
|
"""
|
|
17
17
|
|
|
18
|
+
# Module level
|
|
19
|
+
# ---------------------------------------------------------------------------
|
|
18
20
|
__all__ = ["Wordle"]
|
|
19
21
|
|
|
22
|
+
|
|
23
|
+
# Library
|
|
24
|
+
# ---------------------------------------------------------------------------
|
|
20
25
|
import operator
|
|
21
26
|
import string
|
|
22
27
|
from collections import Counter
|
|
23
28
|
from itertools import chain
|
|
24
|
-
from typing import List, Set, Tuple
|
|
25
29
|
|
|
26
30
|
import requests
|
|
27
31
|
|
|
32
|
+
# Class
|
|
33
|
+
# ---------------------------------------------------------------------------
|
|
28
34
|
OFFLINE_WORDS = """\
|
|
29
35
|
aahed,aalii,aargh,aaron,abaca,abaci,aback,abada,abaff,abaft,abaka,abama,abamp,aband,abase,abash,abask,abate,abaue,abave,abaze,abbas,abbes,abbey,abbie,abbot,abdal,abdat,abdom,abeam,abear,abede,abele,abend,aberr,abets,abhor,abide,abidi,abies,abilo,abime,abkar,abler,ables,ablet,ablow,abmho,abner,abnet,abode,abody,abohm,aboil,aboma,aboon,abord,abort,abote,about,above,abram,abray,abret,abrim,abrin,abris,abrus,absee,absey,absis,absit,abstr,abuna,abune,abura,abuse,abush,abuta,abuts,abuzz,abwab,abyes,abysm,abyss,acale,acana,acapu,acara,acari,acast,acate,accel,accoy,accra,accts,accum,accur,accus,acedy,acerb,aceta,achar,ached,achen,acher,aches,achoo,achor,acids,acidy,acier,acies,acing,acini,ackee,acker,ackey,aclys,acmes,acmic,acned,acnes,acock,acoin,acold,acoma,acone,acool,acorn,acost,acoup,acrab,acred,acres,acrid,acroa,acron,acrux,acryl,acted,actin,acton,actor,actos,actus,acuan,acute,acyls,adage,adagy,adams,adapa,adapt,adati,adaty,adawe,adawn,adays,adcon,addax,addda,added,adder,addie,addio,addis,addle,addnl,adead,adeem,adeep,adela,adeps,adept,adfix,adiel,adieu,adion,adios,adits,adjag,adlai,adlay,adlet,adman,admen,admin,admit,admix,admov,admrx,adnex,adobe,adobo,adolf,adopt,adore,adorn,adown,adoxa,adoxy,adoze,adpao,adrad,adret,adrip,adrop,adrue,adsum,adult,adunc,adure,adusk,adust,adyta,adzer,adzes,aecia,aedes,aeger,aegir,aegis,aegle,aeons,aequi,aeric,aerie,aeron,aesir,aesop,aetat,aevia,aevum,aface,afara,afars,afear,affix,afgod,afifi,afire,aflat,afley,aflow,afoam,afoot,afore,afoul,afray,afret,afric,afrit,afros,after,agada,agade,again,agama,agami,agamy,agape,agars,agasp,agast,agata,agate,agaty,agave,agaze,agena,agend,agene,agent,agers,agete,agger,aggie,aggro,aggry,aggur,aghan,aghas,agiel,agile,aging,agios,agism,agist,aglee,aglet,agley,aglow,agmas,agnat,agnel,agnes,agnus,agoge,agoho,agone,agons,agony,agora,agrah,agral,agree,agria,agric,agrin,agrom,agron,agsam,agues,aguey,agura,agush,agust,ahead,aheap,ahems,ahind,ahint,ahmed,ahmet,ahold,aholt,ahong,ahsan,ahull,ahunt,ahura,ahush,ahwal,aided,aider,aides,aiery,aiger,aigre,ailed,ailie,aillt,aimak,aimed,aimee,aimer,ainee,ainoi,ainus,aioli,airan,aired,airer,airns,airth,airts,aisle,aitch,aitis,aiver,aiwan,aizle,ajaja,ajari,ajava,ajhar,ajiva,ajuga,akala,akali,akasa,akebi,akees,akeki,akela,akene,aking,akkad,aknee,aknow,akpek,akron,akule,akund,alack,alada,alain,alaki,alala,alamo,aland,alane,alang,alani,alans,alant,alapa,alarm,alary,alate,alawi,alban,albas,albee,albin,album,albus,albyn,alcae,alces,alcid,alcor,alday,aldea,alden,alder,aldim,aldol,aldus,aleak,
|
|
30
36
|
aleck,alecs,alefs,aleft,alenu,aleph,alert,aleut,alfas,alfet,alfin,alfur,algae,algal,algas,algic,algid,algin,algol,algor,algum,alhet,alias,alibi,alice,alick,alida,alids,alien,aliet,alife,alifs,align,alike,alima,aline,alish,aliso,alisp,alist,alite,ality,alive,aliya,alkes,alkin,alkyd,alkyl,allah,allan,allay,allen,aller,alley,allez,allie,allis,allod,alloo,allot,allow,alloy,allyl,almah,alman,almas,almeh,almes,almon,almud,almug,alnus,alody,aloed,aloes,aloft,alogy,aloha,aloid,aloin,alois,aloma,alone,along,aloof,alosa,alose,aloud,alout,alowe,alpax,alpen,alpha,alpid,altar,alter,altho,altin,altos,altun,altus,aluco,alula,alums,alure,aluta,alvah,alvan,alvar,alvia,alvin,alvus,alway,amaas,amadi,amaga,amahs,amain,amala,amalg,amang,amani,amant,amapa,amara,amass,amate,amati,amaut,amaze,amban,ambar,ambas,ambay,amber,ambit,amble,ambon,ambos,ambry,ameba,ameed,ameen,ameer,amelu,amend,amene,amens,ament,amess,amhar,amias,amice,amici,amide,amido,amids,amies,amiga,amigo,amine,amini,amino,amins,amire,amirs,amish,amiss,amita,amity,amlet,amman,ammer,ammos,amnia,amnic,amoke,amoks,amole,among,amora,amort,amour,amove,amowt,amper,amphi,ample,amply,ampul,ampyx,amrit,amsel,amuck,amula,amuse,amuze,amvis,amylo,amyls,amzel,anabo,anack,anama,anana,anasa,ancha,ancle,ancon,ancor,ancre,andes,andia,andor,andre,anear,anele,anend,anent,angas,angel,anger,angia,angie,angka,angle,anglo,angor,angry,angst,angus,anhyd,aniba,anice,anigh,anile,anils,anima,anime,animi,animo,anion,anise,anita,anjan,anjou,ankee,anker,ankhs,ankle,ankou,ankus,anlas,anlet,anlia,anmia,annal,annam,annas,annat,annet,annex,annie,anniv,annot,annoy,annul,annum,annus,anoas,anode,anoia,anoil,anole,anoli,anomy,anorn,anour,anous,anova,ansae,ansar,ansel,anser,antae,antal,antar,antas,anted,antes,antic,antiq,antis,anton,antra,antre,antsy,antum,anura,anury,anvil,anzac,aoife,aorta,aotea,aotes,aotus,aouad,apace,apaid,apair,apama,apart,apass,apast,apeak,apeek,apers,apert,aperu,apery,aphid,aphis,aphra,apian,apiin,apili,apina,aping,apiol,apios,apish,apism,apium,apnea,apoda,apods,apoop,aport,apout,appal,appar,appay,appel,appet,apple,apply,appmt,appro,apptd,appui,apres,april,apron,apses,apsid,apsis,aptal,apter,aptly,aquae,aquas,araba,arabs,araby,araca,arace,arach,arado,arage,arain,arake,araks,aramu,arank,arara,araru,arase,arati,araua,arawa,arber,arbor,arcae,arced,arces,archd,arche,archt,archy,arcos,arcus,ardea,ardeb,arder,ardor,ardri,aread,areae,areal,arean,arear,areas,areca,areek,areel,arefy,areic,arena,arend,areng,arent,arere,arest,arete,argal,argan,argas,argel,argid,argil,
|
|
@@ -92,7 +98,7 @@ class Wordle:
|
|
|
92
98
|
self._ALLOWED_ATTEMPTS = 6
|
|
93
99
|
self._WORD_LENGTH = 5
|
|
94
100
|
|
|
95
|
-
self._WORDS:
|
|
101
|
+
self._WORDS: list[str] = list(set(OFFLINE_WORDS.replace("\n", "").split(",")))
|
|
96
102
|
|
|
97
103
|
self._LETTER_COUNTER = Counter(chain.from_iterable(self._WORDS))
|
|
98
104
|
|
|
@@ -138,7 +144,7 @@ class Wordle:
|
|
|
138
144
|
score += self._LETTER_FREQUENCY[char]
|
|
139
145
|
return score / (self._WORD_LENGTH - len(set(word)) + 1)
|
|
140
146
|
|
|
141
|
-
def _sort_by_word_commonality(self) ->
|
|
147
|
+
def _sort_by_word_commonality(self) -> list[tuple[str, float]]:
|
|
142
148
|
sort_by = operator.itemgetter(1)
|
|
143
149
|
return sorted(
|
|
144
150
|
[(word, self._calculate_word_commonality(word)) for word in self._WORDS],
|
|
@@ -146,7 +152,7 @@ class Wordle:
|
|
|
146
152
|
reverse=True,
|
|
147
153
|
)
|
|
148
154
|
|
|
149
|
-
def _display_word_table(self, word_commonalities:
|
|
155
|
+
def _display_word_table(self, word_commonalities: list[tuple[str, float]]) -> None:
|
|
150
156
|
for word, freq in word_commonalities:
|
|
151
157
|
print(f"{word:<10} | {freq:<5.2}")
|
|
152
158
|
|
|
@@ -176,7 +182,7 @@ class Wordle:
|
|
|
176
182
|
return "win"
|
|
177
183
|
return response
|
|
178
184
|
|
|
179
|
-
def _match_word_vector(self, word: str, word_vector:
|
|
185
|
+
def _match_word_vector(self, word: str, word_vector: list[set[str]]) -> bool:
|
|
180
186
|
assert len(word) == len(word_vector)
|
|
181
187
|
for letter, v_letter in zip(word, word_vector):
|
|
182
188
|
if letter not in v_letter:
|
|
@@ -184,8 +190,8 @@ class Wordle:
|
|
|
184
190
|
return True
|
|
185
191
|
|
|
186
192
|
def _match(
|
|
187
|
-
self, word_vector:
|
|
188
|
-
) ->
|
|
193
|
+
self, word_vector: list[set[str]], possible_words: list[str]
|
|
194
|
+
) -> list[str]:
|
|
189
195
|
return [
|
|
190
196
|
word
|
|
191
197
|
for word in possible_words
|
|
@@ -225,7 +231,7 @@ class Wordle:
|
|
|
225
231
|
|
|
226
232
|
|
|
227
233
|
# Run
|
|
228
|
-
|
|
234
|
+
# ---------------------------------------------------------------------------
|
|
229
235
|
if __name__ == "__main__":
|
|
230
236
|
test = Wordle()
|
|
231
237
|
test.solve()
|