def act( self ):
        '''Take an action from the action_set and set the expected outcome so we can wait for it.'''
        if self.action_set == 'discrete_absolute':
            actions = ['movenorth 1', 'movesouth 1', 'movewest 1', 'moveeast 1']
        elif self.action_set == 'discrete_relative':
            actions = ['move 1', 'move -1', 'turn 1', 'turn -1']
        elif self.action_set == 'teleport':
            while True:
                dx = random.randint(-10,10)
                dz = random.randint(-10,10)
                if not dx == 0 or not dz == 0:
                    break
            self.expected_x = self.prev_x + dx
            self.expected_y = self.prev_y
            self.expected_z = self.prev_z + dz
            self.expected_yaw = self.prev_yaw
            self.require_move = True
            self.require_yaw_change = False
            actions = ['tp '+str(self.expected_x)+' '+str(self.expected_y)+' '+str(self.expected_z)]
        else:
            print('ERROR: Unsupported action set:',self.action_set)
            exit(1)
        i_action = random.randint(0,len(actions)-1)
        action = actions[ i_action ]
        print('Sending',action)
        self.agent_host.sendCommand( action )
        if self.action_set == 'discrete_absolute':
            self.expected_x = self.prev_x + [0,0,-1,1][i_action]
            self.expected_y = self.prev_y
            self.expected_z = self.prev_z + [-1,1,0,0][i_action]
            self.expected_yaw = self.prev_yaw
            self.require_move = True
            self.require_yaw_change = False
        elif self.action_set == 'discrete_relative':
            if i_action == 0 or i_action == 1:
                i_yaw = indexOfClosest( [0,90,180,270], self.prev_yaw )
                forward = [ (0,1), (-1,0), (0,-1), (1,0) ][ i_yaw ]
                if i_action == 0:
                    self.expected_x = self.prev_x + forward[0]
                    self.expected_z = self.prev_z + forward[1]
                else:
                    self.expected_x = self.prev_x - forward[0]
                    self.expected_z = self.prev_z - forward[1]
                self.expected_y = self.prev_y
                self.expected_yaw = self.prev_yaw
                self.require_move = True
                self.require_yaw_change = False
            else:
                self.expected_x = self.prev_x
                self.expected_y = self.prev_y
                self.expected_z = self.prev_z
                self.expected_yaw = math.fmod( 360 + self.prev_yaw + [90,-90][i_action-2], 360 )
                self.require_move = False
                self.require_yaw_change = True
        elif self.action_set == 'teleport':
            pass
        else:
            print('ERROR: Unsupported action set:',self.action_set)
            exit(1)
def act ( self ) : if self . action_set == 'discrete_absolute' : actions = [ 'movenorth 1' , 'movesouth 1' , 'movewest 1' , 'moveeast 1' ] elif self . action_set == 'discrete_relative' : actions = [ 'move 1' , 'move -1' , 'turn 1' , 'turn -1' ] elif self . action_set == 'teleport' : while True : dx = random . randint ( - 10 , 10 ) dz = random . randint ( - 10 , 10 ) if not dx == 0 or not dz == 0 : break self . expected_x = self . prev_x + dx self . expected_y = self . prev_y self . expected_z = self . prev_z + dz self . expected_yaw = self . prev_yaw self . require_move = True self . require_yaw_change = False actions = [ 'tp ' + str ( self . expected_x ) + ' ' + str ( self . expected_y ) + ' ' + str ( self . expected_z ) ] else : print ( 'ERROR: Unsupported action set:' , self . action_set ) exit ( 1 ) i_action = random . randint ( 0 , len ( actions ) - 1 ) action = actions [ i_action ] print ( 'Sending' , action ) self . agent_host . sendCommand ( action ) if self . action_set == 'discrete_absolute' : self . expected_x = self . prev_x + [ 0 , 0 , - 1 , 1 ] [ i_action ] self . expected_y = self . prev_y self . expected_z = self . prev_z + [ - 1 , 1 , 0 , 0 ] [ i_action ] self . expected_yaw = self . prev_yaw self . require_move = True self . require_yaw_change = False elif self . action_set == 'discrete_relative' : if i_action == 0 or i_action == 1 : i_yaw = indexOfClosest ( [ 0 , 90 , 180 , 270 ] , self . prev_yaw ) forward = [ ( 0 , 1 ) , ( - 1 , 0 ) , ( 0 , - 1 ) , ( 1 , 0 ) ] [ i_yaw ] if i_action == 0 : self . expected_x = self . prev_x + forward [ 0 ] self . expected_z = self . prev_z + forward [ 1 ] else : self . expected_x = self . prev_x - forward [ 0 ] self . expected_z = self . prev_z - forward [ 1 ] self . expected_y = self . prev_y self . expected_yaw = self . prev_yaw self . require_move = True self . require_yaw_change = False else : self . expected_x = self . prev_x self . expected_y = self . prev_y self . expected_z = self . prev_z self . expected_yaw = math . fmod ( 360 + self . prev_yaw + [ 90 , - 90 ] [ i_action - 2 ] , 360 ) self . require_move = False self . require_yaw_change = True elif self . action_set == 'teleport' : pass else : print ( 'ERROR: Unsupported action set:' , self . action_set ) exit ( 1 )
Take an action from the action_set and set the expected outcome so we can wait for it.