def run_game()

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


def run_game(game, max_len, f=None):
    """Iterate through a single human hanabi game from pickle format

    Parameters:
    game: extract_human_data.Game loaded from pickle file
    max_len: Bound on max len for hanabi env to simulate
    f: Optional function, if provided, call on every turn passing it the env and the action about to be made.

    Returns:
    A tuple of (final HanabiEnv object, hle_game object)
    """
    num_player = game["num_players"]
    hle_game = {"num_player": num_player}
    hle_game = {"game_id": game["game_id"]}
    game_params = {
        "players": str(num_player),
        "random_start_player": "0",
        "bomb": "0",
    }
    env = hanalearn.HanabiEnv(game_params, max_len, False)
    deck = []
    for card in game["deck"]:
        hle_card = hanalearn.HanabiCardValue(card.color - 1, card.value - 1)
        deck.append(hle_card)

    card_in_hands = []
    for hand in game["hands"]:
        for card in hand:
            hle_card = hanalearn.HanabiCardValue(card.color - 1, card.value - 1)
            card_in_hands.append(hle_card)
    deck = deck + list(reversed(card_in_hands))
    env.reset_with_deck(deck)
    hle_game["deck"] = deck

    moves = []
    cur_player = 0
    for move in game["moves"]:
        assert move.player_id == cur_player
        target_offset = -1
        if move.type == "hintValue":
            target_offset = (move.target_player - cur_player + num_player) % num_player
            move = hanalearn.HanabiMove(
                hanalearn.MoveType.RevealRank, -1, target_offset, -1, move.value - 1
            )
        elif move.type == "hintColor":
            target_offset = (move.target_player - cur_player + num_player) % num_player
            move = hanalearn.HanabiMove(
                hanalearn.MoveType.RevealColor, -1, target_offset, move.value - 1, -1
            )
        elif move.type == "playCard":
            move = hanalearn.HanabiMove(hanalearn.MoveType.Play, move.value, -1, -1, -1)
        elif move.type == "discardCard":
            move = hanalearn.HanabiMove(
                hanalearn.MoveType.Discard, move.value, -1, -1, -1
            )
        else:
            logging.error(f"Unknown or illegal move in {debug_label}: {move}")
            return False
        moves.append(move)
        cur_player = (cur_player + 1) % num_player

    hle_game["moves"] = moves
    for move in moves:
        if f is not None:
            f(env, move)
        env.step(move)

    return env, hle_game