def evaluate_policy(mdp, state, policy, rollouts=100, max_trajectory_length=200):
    """ Monte Carlo estimate of V^{pi}(state) """
    reward_func = mdp.get_reward_func()
    trans_func = mdp.get_transition_func()

    total_return = 0

    for _ in range(rollouts):
        step = 0
        cur_state = state
        discount = 1
        ret = 0

        while step < max_trajectory_length and not cur_state.is_terminal():
            action = policy(cur_state)
            next_state = trans_func(cur_state, action)
            reward = reward_func(cur_state, action, next_state)
            ret += discount * reward

            discount *= mdp.get_gamma()
            cur_state = next_state
            step += 1

        total_return += ret

    return float(total_return) / rollouts