assignment1_coding/vi_and_pi.py
def render_single(env, policy, max_steps=100):
  """
    This function does not need to be modified
    Renders policy once on environment. Watch your agent play!

    Parameters
    ----------
    env: gym.core.Environment
      Environment to play on. Must have nS, nA, and P as
      attributes.
    Policy: np.array of shape [env.nS]
      The action to take at a given state
  """

  episode_reward = 0
  ob = env.reset()
  for t in range(max_steps):
    env.render()
    time.sleep(0.25)
    a = policy[ob]
    ob, rew, done, _ = env.step(a)
    episode_reward += rew
    if done:
      break
  env.render();
  if not done:
    print("The agent didn't reach a terminal state in {} steps.".format(max_steps))
  else:
      print("Episode reward: %f" % episode_reward)

    This function does not need to be modified
    Renders policy once on environment. Watch your agent play!

    Parameters
    ----------
    env: gym.core.Environment
      Environment to play on. Must have nS, nA, and P as
      attributes.
    Policy: np.array of shape [env.nS]
      The action to take at a given state
  
This function does not need to be modified
Renders policy once on environment. Watch your agent play!

Parameters

gym.core.Environment
Environment to play on. Must have nS, nA, and P as
attributes.
Policy: np.array of shape [env.nS]
The action to take at a given state
This function does not need to be modified Renders policy once on environment . Watch your agent play! Parameters gym . core . Environment Environment to play on . Must have nS nA and P as attributes . Policy : np . array of shape [ env . nS ] The action to take at a given state
def render_single(env, policy, max_steps=100):
  episode_reward = 0
  ob = env.reset()
  for t in range(max_steps):
    env.render()
    time.sleep(0.25)
    a = policy[ob]
    ob, rew, done, _ = env.step(a)
    episode_reward += rew
    if done:
      break
  env.render();
  if not done:
    print("The agent didn't reach a terminal state in {} steps.".format(max_steps))
  else:
      print("Episode reward: %f" % episode_reward)
def render_single ( env , policy , max_steps = 100 ) : episode_reward = 0 ob = env . reset ( ) for t in range ( max_steps ) : env . render ( ) time . sleep ( 0.25 ) a = policy [ ob ] ob , rew , done , _ = env . step ( a ) episode_reward += rew if done : break env . render ( ) ; if not done : print ( "The agent didn't reach a terminal state in {} steps." . format ( max_steps ) ) else : print ( "Episode reward: %f" % episode_reward )
This function does not need to be modified
Renders policy once on environment.
This function does not need to be modified Renders policy once on environment .
"""
    This function does not need to be modified
    Renders policy once on environment. Watch your agent play!

    Parameters
    ----------
    env: gym.core.Environment
      Environment to play on. Must have nS, nA, and P as
      attributes.
    Policy: np.array of shape [env.nS]
      The action to take at a given state
  """
env
policy
max_steps