def evaluate_training_result(env, agent):
    """
    Evaluates the performance of the current DQN agent by using it to play a
    few episodes of the game and then calculates the average reward it gets.
    The higher the average reward is the better the DQN agent performs.

    :param env: the game environment
    :param agent: the DQN agent
    :return: average reward across episodes
    """
    total_reward = 0.0
    episodes_to_play = 100
    for i in range(episodes_to_play):
        trajectories, _ = env.run(is_training=True)
        # calculate reward
        episode_reward = 0.0
        for ts in trajectories[0]:
            # print(
            #    'State: {}, Action: {}, Reward: {}, Next State: {}, Done: {}'.
            #    format(ts[0], ts[1], ts[2], ts[3], ts[4]))
            episode_reward += ts[2]
        total_reward += episode_reward

    average_reward = total_reward / episodes_to_play
    return average_reward