コード例 #1
0
def json_to_examples(line, examples, proba=None):
    try:
        game_json = json.loads(line)
    except json.decoder.JSONDecodeError:
        print("Problem with", line)
        return

    board = Board.from_fen(game_json["initial_fen"])
    is_blue = True
    round = 0
    if game_json["winner"] == "BLUE":
        winner = 1
    else:
        winner = -1
    for move in game_json["moves"]:
        played = Action.from_uci_usi(move["played"])
        node = MCTSNode()
        node.total_N = move["total_N"]
        for action_uci_usi, value in move["N"].items():
            node.N[Action.from_uci_usi(action_uci_usi)] = value
        update_examples(board,
                        examples,
                        node.get_policy,
                        is_blue,
                        proba,
                        round,
                        winner=winner)
        board.apply_action(played)
        round += 1
        is_blue = not is_blue
コード例 #2
0
 def play_action(self):
     while True:
         read_data = input("Enter your action:")
         try:
             action = Action.from_uci_usi(read_data.strip())
             break
         except IndexError:
             print("Invalid Action")
     return action
コード例 #3
0
 def from_uci_usi(cls, player_blue, player_red, uci_usi):
     uci_usi = uci_usi.replace("--", "- -")
     uci_usi_split = uci_usi.split(" ")
     fen = " ".join(uci_usi_split[2:8])
     moves = uci_usi_split[9:]
     game = Game.from_fen(player_blue, player_red, fen)
     for move in moves:
         action = Action.from_uci_usi(move)
         game.apply_action(action)
     return game
コード例 #4
0
 def get_actions(self, color):
     moves = pyffish.legal_moves("janggi", self.initial_fen,
                                 self.previous_moves)
     return [Action.from_uci_usi(move) for move in moves]