#NEWLINE# def get_possible_next_states( self , state , action ) : #NEWLINE# #INDENT# "\n        Given the state and action, return a list of possible next states and their probabilities. Only next states\n        with nonzero probabilities will be returned\n        :param state: start state\n        :param action: action\n        :return: a list of pairs (s', p(s'|s,a))\n        " #NEWLINE# assert self . observation_space . contains ( state ) #NEWLINE# assert self . action_space . contains ( action ) #NEWLINE# x = ( state / self . n_col ) #NEWLINE# y = ( state % self . n_col ) #NEWLINE# coords = np . array ( [ x , y ] ) #NEWLINE# increments = np . array ( [ [ 0 , ( - 1 ) ] , [ 1 , 0 ] , [ 0 , 1 ] , [ ( - 1 ) , 0 ] ] ) #NEWLINE# next_coords = np . clip ( ( coords + increments [ action ] ) , [ 0 , 0 ] , [ ( self . n_row - 1 ) , ( self . n_col - 1 ) ] ) #NEWLINE# next_state = ( ( next_coords [ 0 ] * self . n_col ) + next_coords [ 1 ] ) #NEWLINE# state_type = self . desc [ ( x , y ) ] #NEWLINE# next_state_type = self . desc [ ( next_coords [ 0 ] , next_coords [ 1 ] ) ] #NEWLINE# if ( ( next_state_type == 'W' ) or ( state_type == 'H' ) or ( state_type == 'G' ) ) : #NEWLINE# #INDENT# return [ ( state , 1.0 ) ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return [ ( next_state , 1.0 ) ]