original_docstring: 
          Runs one episode of the gym environment.
          When in training mode, updates the Q-table,
          while when in running mode, computes and return the cumulative
          discounted reward.
  
  
          Parameters
          ----------
          train_mode : bool 
              Flag defining if we are in training mode or testing mode
          env : GymEnv 
              An object that is a gym environment, gotten from gym.make.
              It can be a non gym environment, as long as it is similar
              to one.
              This means it needs
              - a reset method, that starts the episode (and returns starting state) 
              - a state attribute, that gives the state at anytime
              - a step method, that receives an action and returns a tuple with
              4 elements, "observation" (object), object representing the state 
                          "reward" (float), reward of the previous action
                          "done" (boolean), flag defining if the episode ended
                          "info" (dict), dict with diagnostic information
  
          Returns:
              None
          
docstring: Runs one episode of the gym environment.
  When in training mode, updates the Q-table,
  while when in running mode, computes and return the cumulative
  discounted reward.
  
  Parameters
  
  train_mode : bool
  Flag defining if we are in training mode or testing mode
  env : GymEnv
  An object that is a gym environment, gotten from gym.make.
  It can be a non gym environment, as long as it is similar
  to one.
docstring_tokens: Runs one episode of the gym environment . When in training mode updates the Q - table while when in running mode computes and return the cumulative discounted reward . Parameters train_mode : bool Flag defining if we are in training mode or testing mode env : GymEnv An object that is a gym environment gotten from gym . make . It can be a non gym environment as long as it is similar to one .
code: def run_episode(
          self,
          train_mode:bool,
          env:GymEnv):
          """
          Runs one episode of the gym environment.
          When in training mode, updates the Q-table,
          while when in running mode, computes and return the cumulative
          discounted reward.
  
  
          Parameters
          ----------
          train_mode : bool 
              Flag defining if we are in training mode or testing mode
          env : GymEnv 
              An object that is a gym environment, gotten from gym.make.
              It can be a non gym environment, as long as it is similar
              to one.
              This means it needs
              - a reset method, that starts the episode (and returns starting state) 
              - a state attribute, that gives the state at anytime
              - a step method, that receives an action and returns a tuple with
              4 elements, "observation" (object), object representing the state 
                          "reward" (float), reward of the previous action
                          "done" (boolean), flag defining if the episode ended
                          "info" (dict), dict with diagnostic information
  
          Returns:
              None
          """
          epi_reward = 0
  
          # initialize for each episode
          state = env.reset()
          state_idx = self.boilerplate.get_idx_from_state(state)
          terminal = False
  
          step_count = 0
          while not terminal:
              
              # Choose next action and execute
              act_idx = self.select_action(state_idx, train_mode)
              action = act_idx
              
              new_state, reward, terminal, info = env.step(action)
              new_state_idx = self.boilerplate.get_idx_from_state(new_state)
  
              if train_mode:
                  # update Q table
  
                  self.q_func = self.q_table_update(
                                      self.q_func,
                                      state_idx,
                                      act_idx,
                                      reward,
                                      new_state_idx,
                                      terminal)
  
              else:
                  # update reward
  
                  epi_reward += ( self.gamma ** step_count ) * reward
                  
              # prepare next step
              state_idx = new_state_idx
              step_count += 1
  
              if step_count == 1000:
                  # Wether the environment ends or not after a long time,
                  # we will end it.
                  terminal = True
  
          if not train_mode:
              print(f"Final reward : {epi_reward}")
              return epi_reward
code_tokens: def run_episode ( self , train_mode : bool , env : GymEnv ) : epi_reward = 0 state = env . reset ( ) state_idx = self . boilerplate . get_idx_from_state ( state ) terminal = False step_count = 0 while not terminal : act_idx = self . select_action ( state_idx , train_mode ) action = act_idx new_state , reward , terminal , info = env . step ( action ) new_state_idx = self . boilerplate . get_idx_from_state ( new_state ) if train_mode : self . q_func = self . q_table_update ( self . q_func , state_idx , act_idx , reward , new_state_idx , terminal ) else : epi_reward += ( self . gamma ** step_count ) * reward state_idx = new_state_idx step_count += 1 if step_count == 1000 : terminal = True if not train_mode : print ( f"Final reward : {epi_reward}" ) return epi_reward
short_docstring: Runs one episode of the gym environment.
short_docstring_tokens: Runs one episode of the gym environment .
comment: """
          Runs one episode of the gym environment.
          When in training mode, updates the Q-table,
          while when in running mode, computes and return the cumulative
          discounted reward.
  
  
          Parameters
          ----------
          train_mode : bool 
              Flag defining if we are in training mode or testing mode
          env : GymEnv 
              An object that is a gym environment, gotten from gym.make.
              It can be a non gym environment, as long as it is similar
              to one.
              This means it needs
              - a reset method, that starts the episode (and returns starting state) 
              - a state attribute, that gives the state at anytime
              - a step method, that receives an action and returns a tuple with
              4 elements, "observation" (object), object representing the state 
                          "reward" (float), reward of the previous action
                          "done" (boolean), flag defining if the episode ended
                          "info" (dict), dict with diagnostic information
  
          Returns:
              None
          """$SEP$# initialize for each episode$SEP$# Choose next action and execute$SEP$# update Q table$SEP$# update reward$SEP$# prepare next step$SEP$# Wether the environment ends or not after a long time,$SEP$# we will end it.