-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutil.py
71 lines (61 loc) · 1.48 KB
/
util.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
67
68
69
70
71
from enum import IntEnum
import numpy as np
import ctypes
class Cell(IntEnum):
TYPE_0 = 0
TYPE_1 = 1
TYPE_2 = 2
TYPE_3 = 3
TYPE_4 = 4
TYPE_5 = 5
TYPE_6 = 6
TYPE_7 = 7
TYPE_8 = 8
CLOSED = 9
FLAG = 10
BOMB = 11
START = 12
UNKNOWN = 13
def is_number(self) -> bool:
return int(self) <= 8
def __str__(self):
value_to_str = [
'0',
'1', #\033[36m1\033[0m',
'2', #'\033[32m2\033[0m',
'3', #'\033[31m3\033[0m',
'4', #'\033[34m4\033[0m',
'5',
'6',
'7',
'8',
'.', # closed
'|', # flag
'@', # bomb
's', # start
'x' # unknown
]
return value_to_str[int(self)]
class Dir8(IntEnum):
RN = 0
RD = 1
ND = 2
LD = 3
RU = 4
NU = 5
LU = 6
LN = 7
def reverse(self):
return Dir8(7 - self)
def to_numpy(self) -> np.ndarray:
return np.array([self.x, self.y])
def to_tuple(self) -> tuple[int, int]:
return self.x, self.y
@property
def x(self) -> int:
return [1, 1, 0, -1, 1, 0, -1, -1][int(self)]
@property
def y(self) -> int:
return [0, 1, 1, 1, -1, -1, -1, 0][int(self)]
def is_key_pressed(key: str) -> None:
return(bool(ctypes.windll.user32.GetAsyncKeyState(ord(key)) & 0x8000))