-
Notifications
You must be signed in to change notification settings - Fork 110
Expand file tree
/
Copy pathutils.py
More file actions
49 lines (37 loc) · 1.69 KB
/
utils.py
File metadata and controls
49 lines (37 loc) · 1.69 KB
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
import textwrap
from datetime import datetime, timedelta
from enums import Variant
ALIASES = {
Variant.STANDARD: ["Standard", "Chess", "Classical", "Normal", "Std"],
Variant.ANTICHESS: ["Antichess", "Anti"],
Variant.ATOMIC: ["Atomic", "Atom"],
Variant.CHESS960: ["Chess960", "960", "FRC"],
Variant.CRAZYHOUSE: ["Crazyhouse", "House", "ZH"],
Variant.HORDE: ["Horde"],
Variant.KING_OF_THE_HILL: ["KOTH", "kingOfTheHill", "Hill"],
Variant.RACING_KINGS: ["Racing", "Race", "racingkings"],
Variant.THREE_CHECK: ["Three-check", "Threecheck", "3-check", "3check"],
}
def find_variant(name: str) -> Variant | None:
for variant, aliases in ALIASES.items():
if any(name.lower() == alias.lower() for alias in aliases):
return variant
def get_future_timestamp(seconds: int) -> str:
return (datetime.now() + timedelta(seconds=seconds)).isoformat(sep=" ", timespec="seconds")
def ml_print(prefix: str, suffix: str) -> None:
if len(prefix) + len(suffix) <= 123:
print(prefix + suffix)
return
width = 123 - len(prefix)
indentation = " " * len(prefix)
lines = textwrap.wrap(suffix, width=width, break_long_words=False, break_on_hyphens=False)
print(prefix + lines[0])
remaining_text = " ".join(lines[1:])
subsequent_lines = textwrap.wrap(remaining_text, width=width, break_long_words=False, break_on_hyphens=False)
for line in subsequent_lines:
print(indentation + line)
def parse_time_control(time_control: str) -> tuple[int, int]:
initial_time_str, increment_str = time_control.split("+")
initial_time = int(float(initial_time_str) * 60)
increment = int(increment_str)
return initial_time, increment