def export_game()

in pyhanabi/tools/game_exporter.py [0:0]


def export_game(env: hanalearn.HanabiEnv, moves: List[int]) -> Dict:
    num_players = 2
    game_json = {}

    game_json["players"] = [f"p{i}" for i in range(num_players)]

    game_json["deck"] = []
    for rank, color in env.deck_history():
        game_json["deck"].append(dict(rank=int(rank), suitIndex=COLORS.index(color)))

    max_cards = len(game_json["deck"])
    # The index of the next card to pick.
    deck_cursor = 10
    # Player hands as indices in the deck.
    hands = {0: list(range(5)), 1: list(range(5, 10))}

    # Valid actions types are:
    # - 0 for a play
    # - 1 for a discard
    # - 2 for a color clue
    # - 3 for a number clue
    # - 4 for an end game
    # Hanabi env codes:
    # 0-4 is discard, 5-9 is play
    # 10-14 is color hint, 15-19 is rank hint
    assert num_players == 2
    game_json["actions"] = []
    for i, action in enumerate(moves):
        assert 0 <= action < 20, action
        player = i % 2
        if action < 10:
            action_type = 1 if action < 5 else 0
            game_json["actions"].append(
                dict(type=action_type, target=hands[player][action % 5])
            )
            del hands[player][action % 5]
            if deck_cursor < max_cards:
                hands[player].append(deck_cursor)
                deck_cursor += 1
        elif action < 15:
            game_json["actions"].append(
                dict(type=2, target=1 - player, value=action % 5)
            )
        elif action < 20:
            # Ranks start with 1, therefore + 1.
            game_json["actions"].append(
                dict(type=3, target=1 - player, value=action % 5 + 1)
            )
        else:
            assert False, f"Bad action: {action}"

    game_json["options"] = dict(variant="No Variant")

    return game_json