예제 #1
0
    def check_distance(self, world):
        """
            Checks the if there is an object is within the vision cone. Does not return coordinates! 

            Args:\n
                world - The 3d list of the world.
            
            Returns:\n 
                Normalized distance to the closest object (0-1). 1 if there is no object in range.
        """
        if isinstance(self.x, float) or isinstance(
                self.y, float) or isinstance(self.z, float):
            print(
                "Matt, you screwed up somewhere. Why is the sensor coordinates a float"
            )
        shortest_distance = 1
        #Right now is starting from coordnates 1
        for i in range(1, self.view_distance + 1):  #Forward-Back
            for j in range(-1 * math.floor(self.view_height / 2),
                           math.floor(self.view_height / 2) + 1):  #Up-Down
                for k in range(-1 * math.floor(self.view_width / 2),
                               math.floor(self.view_width / 2) +
                               1):  #Left-Right
                    coords = Direction.calculate_coords(
                        self.direction, i, self.x, self.y, self.z)
                    d = Direction.calculate_distance(self.direction, self.x,
                                                     self.y, self.z, coords[0],
                                                     coords[1], coords[2])
                    if (not (coords[0] >= len(world.tunnel_world))
                            and not world.check_space(coords)):
                        temp = d / self.view_distance
                        if (temp < shortest_distance):
                            shortest_distance = temp
        return shortest_distance
예제 #2
0
 def check_touch(self, world):
     """
         Returns:
             True if the sensor is touching something,
             False if the sensor is not.
     """
     return (Direction.calculate_coords(self.direction, 1, self.x, self.y,
                                        self.z) == 1)
예제 #3
0
    def generate_moves(self, world):
        """
            Generates all the possible moves of the agent.
            
            Args:\n
                world - A 3d list representing the world
        """
        self.moves = []

        #init_coords = tuple((self.x, self.y, self.z))

        # Goes through each direction
        for direction in Direction:

            # We can add everything to the list because we are just checking to see if that move is possible
            if direction == Direction.NORTH:
                current = math.ceil(self.x)
            elif direction == Direction.SOUTH:
                current = math.floor(self.x)
            elif direction == Direction.UP:
                current = math.ceil(self.y)
            elif direction == Direction.DOWN:
                current = math.floor(self.y)
            elif direction == Direction.WEST:
                current = math.ceil(self.z)
            elif direction == Direction.EAST:
                current = math.floor(self.z)

            # Future at the end of this block will contain the furtherest possible move
            future = tuple((self.x, self.y, self.z))

            # Facing determines if we are going in a positive or negative direction
            facing = numpy.sign(direction.value)
            if facing == 0:
                facing = 1

            # Dim hold the (length, height, width) relative to the direction that it is facing
            dim = Direction.calculate_dimensions_by_direction(
                direction, self.agent_length, self.agent_height,
                self.agent_width)

            # This for loop checks v (velocity-value) spaces ahead. Checks the path forward by one unit in each iteration. Accounts for morphology
            for dis in range(current, current + facing * self.velocity,
                             facing):
                # Coords holds the range of coords, that represents the path of the block. Vital for accounting for its morphology
                #BUG: Problem is here. The calculation doesn't account for "left/right/up/down" "length" when looking that direction
                if direction == Direction.NORTH:  #Positive X
                    temp = math.floor(future[0] + dim[0] / 2)
                    temp_coords = tuple((temp, future[1], future[2]))
                elif direction == Direction.SOUTH:  #Negative X
                    temp = math.ceil(future[0] - dim[0] / 2)
                    temp_coords = tuple((temp, future[1], future[2]))
                elif direction == Direction.UP:  #Positive Y
                    temp = math.floor(future[1] + dim[0] / 2)
                    temp_coords = tuple((future[0], temp, future[2]))
                elif direction == Direction.DOWN:  #Negative Y
                    temp = math.ceil(future[1] - dim[0] / 2)
                    temp_coords = tuple((future[0], temp, future[2]))
                elif direction == Direction.WEST:  #Positive Z
                    temp = math.floor(future[2] + dim[0] / 2)
                    temp_coords = tuple((future[0], future[1], temp))
                elif direction == Direction.EAST:  #Negative XZ
                    temp = math.ceil(future[2] - dim[0] / 2)
                    temp_coords = tuple((future[0], future[1], temp))

                coords = Direction.calculate_range(direction, 1,
                                                   temp_coords[0],
                                                   temp_coords[1],
                                                   temp_coords[2], dim[1],
                                                   dim[2])

                # Checks to see if the path is possible. Re-sets the future coords if possible
                if (world.check_spaces(coords[0], coords[1])):
                    future = Direction.calculate_coords(
                        direction, 1, future[0], future[1], future[2])
                else:
                    break
            # Append the latest possible move of the direciton
            self.moves.append(future)