def convert_to_cheating_data(data): """ :param data: format is SelfPlayWorker.buffer :return: """ state_list = [] policy_list = [] value_list = [] env = ChessEnv().reset() for state_fen, policy, value in data: move_number = int(state_fen.split(' ')[5]) # f2 = maybe_flip_fen(maybe_flip_fen(state_fen,True),True) # assert state_fen == f2 next_move = env.deltamove(state_fen) if next_move == None: # new game! assert state_fen == chess.STARTING_FEN env.reset() else: env.step(next_move, False) state_planes = env.canonical_input_planes() # assert env.check_current_planes(state_planes) side_to_move = state_fen.split(" ")[1] if side_to_move == 'b': #assert np.sum(policy) == 0 policy = Config.flip_policy(policy) else: #assert abs(np.sum(policy) - 1) < 1e-8 pass # if np.sum(policy) != 0: # policy /= np.sum(policy) #assert abs(np.sum(policy) - 1) < 1e-8 assert len(policy) == 1968 assert state_planes.dtype == np.float32 value_certainty = min( 15, move_number ) / 15 # reduces the noise of the opening... plz train faster SL_value = value * value_certainty + env.testeval() * (1 - value_certainty) state_list.append(state_planes) policy_list.append(policy) value_list.append(SL_value) return np.array(state_list, dtype=np.float32), np.array( policy_list, dtype=np.float32), np.array(value_list, dtype=np.float32)
def start(config: Config): PlayWithHumanConfig().update_play_config(config.play) me_player = 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 not me_player: me_player = get_player(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: if words[0] == "fen": # skip extraneous word words = words[1].split(' ',1) 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": if not me_player: me_player = get_player(config) action = me_player.action(env, False) print(f"bestmove {action}") elif words[0] == "stop": pass elif words[0] == "quit": break
def start(config: Config): PlayWithHumanConfig().update_play_config(config.play) me_player = 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 not me_player: me_player = get_player(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: if words[0] == "fen": # skip extraneous word words = words[1].split(' ', 1) 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": if not me_player: me_player = get_player(config) action = me_player.action(env, False) print(f"bestmove {action}") elif words[0] == "stop": pass elif words[0] == "quit": break
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