Spaces:
Runtime error
Runtime error
File size: 1,147 Bytes
3014f14 | 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 | """An engine mimics a UCI engine."""
import chess
import typing
if typing.TYPE_CHECKING:
from test_bot.test_games import scholars_mate
else:
from test_games import scholars_mate
assert input() == "uci"
def send_command(command: str) -> None:
"""Send UCI commands to lichess-bot without output buffering."""
print(command, flush=True) # noqa: T201 (print() found)
send_command("id name UCI_Test_Bot")
send_command("id author lichess-bot-devs")
send_command("uciok")
board = chess.Board()
while True:
command, *remaining = input().split()
if command == "quit":
break
elif command == "isready":
send_command("readyok")
elif command == "position":
spec_type, *remaining = remaining
assert spec_type == "startpos"
board = chess.Board()
if remaining:
moves_label, *move_list = remaining
assert moves_label == "moves"
for move in move_list:
board.push_uci(move)
elif command == "go":
move_count = len(board.move_stack)
move = scholars_mate[move_count]
send_command(f"bestmove {move}")
|