def start(config: Config): PlayWithHumanConfig().update_play_config(config.play) config.play.thinking_loop = 1 chess_model = None env = ChessEnv().reset() while True: line = input() words = line.rstrip().split(" ", 1) if words[0] == "uci": print("id name ChessZero") print("id author ChessZero") print("uciok") elif words[0] == "isready": if chess_model is None: chess_model = PlayWithHuman(config) print("readyok") elif words[0] == "ucinewgame": env.reset() elif words[0] == "position": words = words[1].split(" ", 1) if words[0] == "startpos": env.reset() else: fen = words[0] for _ in range(5): words = words[1].split(' ', 1) fen += " "+words[0] env.update(fen) if len(words) > 1: words = words[1].split(" ", 1) if words[0] == "moves": for w in words[1].split(" "): env.step(w, False) elif words[0] == "go": action = chess_model.move_by_ai(env) print(f"bestmove {action}") elif words[0] == "stop": pass elif words[0] == "quit": break
def start(config: Config): PlayWithHumanConfig().update_play_config(config.play) chess_model = PlayWithHuman(config) env = ChessEnv().reset() human_is_black = random() < 0.5 chess_model.start_game(human_is_black) while not env.done: if (env.board.turn == chess.BLACK) == human_is_black: action = chess_model.move_by_human(env) print("You move to: " + action) else: action = chess_model.move_by_ai(env) print("AI moves to: " + action) board, info = env.step(action) env.render() print("Board FEN = " + board.fen()) print("\nEnd of the game.") #spaces after this? print("Game result:") #and this? print(env.board.result())