def evaluate_policy(policy, simulator, T=200):
    """
    Evaluate the given policy by calculating the cumulative reward of
    of a T-step trajectory generated from this policy
    """
    simulator.reset()
    state = simulator.observe()
    cumulative_reward = 0
    for i in range(T):
        action = policy(state)
        reward, state = simulator.perform(action)
        cumulative_reward += reward

    return cumulative_reward