GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — BotLi/utils.py at main · Torom/BotLi

Expand file tree

/

utils.py

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
112 lines (87 loc) · 3.45 KB
/

utils.py

Copy path

File metadata and controls

112 lines (87 loc) · 3.45 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import builtins
import sys
import textwrap
from contextvars import ContextVar
from datetime import datetime, timedelta
from typing import Any
import chess
import chess.variant
from rich.console import Console
from enums import Variant
GAME_COLORS = (None, "cyan", "green", "yellow", "magenta", "blue", "bright_red")
game_color: ContextVar[str | None] = ContextVar("game_color", default=None)
_original_print = builtins.print
def install_colored_print() -> None:
console = Console(markup=False, highlight=False, emoji=False, soft_wrap=True)
def colored_print(
*values: object, sep: str | None = " ", end: str | None = "\n", file: Any = None, flush: bool = False
) -> None:
if (color := game_color.get()) and file is None and console.is_terminal:
separator = " " if sep is None else sep
ending = "\n" if end is None else end
console.print(separator.join(map(str, values)), end=ending, style=color)
if flush:
sys.stdout.flush()
return
_original_print(*values, sep=sep, end=end, file=file, flush=flush)
builtins.print = colored_print
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"],
}
PRIORITIES = {
"BOT": 1,
"LM": -1,
"WNM": -2,
"WCM": -3,
"CM": -4,
"NM": -5,
"WFM": -6,
"FM": -7,
"WIM": -8,
"IM": -9,
"WGM": -10,
"GM": -11,
}
UCI_VARIANTS: dict[str, type[chess.Board]] = {
"chess": chess.Board,
"antichess": chess.variant.AntichessBoard,
"atomic": chess.variant.AtomicBoard,
"crazyhouse": chess.variant.CrazyhouseBoard,
"horde": chess.variant.HordeBoard,
"kingofthehill": chess.variant.KingOfTheHillBoard,
"racingkings": chess.variant.RacingKingsBoard,
"3check": chess.variant.ThreeCheckBoard,
}
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_estimated_game_duration(initial: int, increment: int) -> float:
return max(initial, 3) * 1.33 + increment * 104.77
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
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.