parameters: (coord1, action, coord2)
return_statement: return 1.0 / 4.0
docstring: Given two coordinates and an action, return the transition probability.
  
      Parameters
      ----------
      coord1: tuple of int
          Four element tuple containing the current coordinates of the tiger and
          antelope.
      action: str
          String representing the tiger action, options are i
          'stand', 'up', 'down', 'left', 'right'.
      coord2: tuple of int
          Four element tuple containing the next coordinates of the tiger and
          antelope.
docstring_summary: Given two coordinates and an action, return the transition probability.
docstring_tokens: Given two coordinates and an action return the transition probability .
function: def getTransitionProbability(coord1, action, coord2):
      """
      Given two coordinates and an action, return the transition probability.
  
      Parameters
      ----------
      coord1: tuple of int
          Four element tuple containing the current coordinates of the tiger and
          antelope.
      action: str
          String representing the tiger action, options are i
          'stand', 'up', 'down', 'left', 'right'.
      coord2: tuple of int
          Four element tuple containing the next coordinates of the tiger and
          antelope.
      """
      # We compute the distances traveled by both the antelope and the tiger.
      tiger_x1, tiger_y1, antelope_x1, antelope_y1 = coord1
      tiger_x2, tiger_y2, antelope_x2, antelope_y2 = coord2
  
      # We compute the distances traveled by both the antelope and the tiger.
      tigerMovementX = wrapDiff(tiger_x1, tiger_x2)
      tigerMovementY = wrapDiff(tiger_y1, tiger_y2)
      antelMovementX = wrapDiff(antelope_x1, antelope_x2)
      antelMovementY = wrapDiff(antelope_y1, antelope_y2)
  
      # Both the tiger and the antelope can only move by 1 cell max at each
      # timestep. Thus, if this is not the case, the transition is
      # impossible.
      if abs(tigerMovementX) + abs(tigerMovementY) > 1:
          return 0.0
      if abs(antelMovementX) + abs(antelMovementY) > 1:
          return 0.0
  
      # Now we check whether the tiger was next to the antelope or not
      diffX = wrapDiff(tiger_x1, antelope_x1)
      diffY = wrapDiff(tiger_y1, antelope_y1)
  
      # We check whether they were both in the same cell before.
      # In that case the game would have ended, and nothing would happen anymore.
      # We model this as a self-absorbing state, or a state that always
      # transitions to itself. This is valid no matter the action taken.
      if diffX == 0 and diffY == 0:
          if coord1 == coord2:
              return 1.0
          return 0.0
  
      # The tiger can move only in the direction specified by its action. If
      # it is not the case, the transition is impossible.
      if action == 'stand' and (tigerMovementX or tigerMovementY):
          return 0.0
      if action == 'up' and tigerMovementY != 1:
          return 0.0
      if action == 'down' and tigerMovementY != -1:
          return 0.0
      if action == 'left' and tigerMovementX != -1:
          return 0.0
      if action == 'right' and tigerMovementX != 1:
          return 0.0
  
      # If tiger and antelope are not adjacent, then the probability for any
      # move of the antelope is simply 1/5: it behaves randomly.
      if abs(diffX) + abs(diffY) > 1:
          return 1.0 / 5.0
  
      # Otherwise, first we check that the move was allowed, as
      # the antelope cannot move where the tiger was before.
      if tiger_x1 == antelope_x2 and tiger_y1 == antelope_y2:
          return 0.0
  
      # Else the probability of this transition is 1 / 4, still random but
      # without a possible antelope action.
      return 1.0 / 4.0
function_tokens: def getTransitionProbability ( coord1 , action , coord2 ) : # We compute the distances traveled by both the antelope and the tiger. tiger_x1 , tiger_y1 , antelope_x1 , antelope_y1 = coord1 tiger_x2 , tiger_y2 , antelope_x2 , antelope_y2 = coord2 # We compute the distances traveled by both the antelope and the tiger. tigerMovementX = wrapDiff ( tiger_x1 , tiger_x2 ) tigerMovementY = wrapDiff ( tiger_y1 , tiger_y2 ) antelMovementX = wrapDiff ( antelope_x1 , antelope_x2 ) antelMovementY = wrapDiff ( antelope_y1 , antelope_y2 ) # Both the tiger and the antelope can only move by 1 cell max at each # timestep. Thus, if this is not the case, the transition is # impossible. if abs ( tigerMovementX ) + abs ( tigerMovementY ) > 1 : return 0.0 if abs ( antelMovementX ) + abs ( antelMovementY ) > 1 : return 0.0 # Now we check whether the tiger was next to the antelope or not diffX = wrapDiff ( tiger_x1 , antelope_x1 ) diffY = wrapDiff ( tiger_y1 , antelope_y1 ) # We check whether they were both in the same cell before. # In that case the game would have ended, and nothing would happen anymore. # We model this as a self-absorbing state, or a state that always # transitions to itself. This is valid no matter the action taken. if diffX == 0 and diffY == 0 : if coord1 == coord2 : return 1.0 return 0.0 # The tiger can move only in the direction specified by its action. If # it is not the case, the transition is impossible. if action == 'stand' and ( tigerMovementX or tigerMovementY ) : return 0.0 if action == 'up' and tigerMovementY != 1 : return 0.0 if action == 'down' and tigerMovementY != - 1 : return 0.0 if action == 'left' and tigerMovementX != - 1 : return 0.0 if action == 'right' and tigerMovementX != 1 : return 0.0 # If tiger and antelope are not adjacent, then the probability for any # move of the antelope is simply 1/5: it behaves randomly. if abs ( diffX ) + abs ( diffY ) > 1 : return 1.0 / 5.0 # Otherwise, first we check that the move was allowed, as # the antelope cannot move where the tiger was before. if tiger_x1 == antelope_x2 and tiger_y1 == antelope_y2 : return 0.0 # Else the probability of this transition is 1 / 4, still random but # without a possible antelope action. return 1.0 / 4.0