-
Notifications
You must be signed in to change notification settings - Fork 0
/
body.py
38 lines (32 loc) · 1.36 KB
/
body.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
import chess
import chess.engine
# Создаем экземпляр движка Stockfish
engine = chess.engine.SimpleEngine.popen_uci('C:\\Users\dania\Downloads\stockfish_15.1_win_x64_popcnt')
# Создаем доску
board = chess.Board()
# Определяем, кто играет первым
human_color = input("Выберите цвет: 'w' для белых, 'b' для черных: ")
if human_color == 'w':
is_human_turn = True
else:
is_human_turn = False
# Играем до конца игры
while not board.is_game_over():
if is_human_turn:
print("Ход человека:")
move_str = input("Введите свой ход (например, e2e4): ")
move = chess.Move.from_uci(move_str)
# Проверяем, является ли ход допустимым
if move in board.legal_moves:
board.push(move)
is_human_turn = False
else:
print("Недопустимый ход. Попробуйте еще раз.")
continue
else:
print("Ход компьютера:")
result = engine.play(board, chess.engine.Limit(time=2.0))
board.push(result.move)
is_human_turn = True
# Выводим результат игры
print("Игра окончена. Результат:", board.result())