-
Notifications
You must be signed in to change notification settings - Fork 8
/
tools.py
34 lines (30 loc) · 974 Bytes
/
tools.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
"""
工具函数
"""
def virtual(chesses: list[list], chess, step: list[bool, int, int], function, *args):
""" 虚拟操作 """
chesses[chess.y][chess.x] = None
chess.x += step[1]
chess.y += step[2]
temp = chesses[chess.y][chess.x]
chesses[chess.y][chess.x] = chess
value = function(chesses, *args)
chesses[chess.y][chess.x] = temp
chess.x -= step[1]
chess.y -= step[2]
chesses[chess.y][chess.x] = chess
return value
def print_chess(chesses: list[list], step: list[int] = [0]) -> None:
""" 输出当前棋局 """
step[0] += 1
print('\033[36mSTEP\033[0m:', step[0])
for line in chesses:
for chess in line:
if chess is None:
print('〇', end='')
elif chess.name in '将士象马车炮卒':
print(f'\033[32m{chess.name}\033[0m', end='')
else:
print(f'\033[31m{chess.name}\033[0m', end='')
print()
print()