Esempio n. 1
0
 def move(self, target=None):
     visible_tiles = vision.vision(4, self.world_map, self.tile)
     flight_tile = vision.find_target(visible_tiles, self.predators)
     target_tile = vision.find_target(visible_tiles, self.prey)
     if flight_tile:
         move_to_tile = vision.flee(self.tile, flight_tile, self.world_map)
         if Sprite.is_movable_terrain(
                 self,
                 move_to_tile) and self.not_contains_sprite(move_to_tile):
             Sprite.move(self, move_to_tile)
         else:
             Sprite.move(self)
     elif target_tile:
         move_to_tile = vision.approach(self.tile, target_tile,
                                        self.world_map)
         if Sprite.is_movable_terrain(
                 self, move_to_tile) and Sprite.not_contains_sprite(
                     self, move_to_tile, self.prey):
             if move_to_tile == target_tile:
                 move_to_tile.contains_sprite.die()
             Sprite.move(self, move_to_tile)
         else:
             Sprite.move(self)
     else:
         Sprite.move(self)
Esempio n. 2
0
 def move(self):
     """
     :return:
     """
     visible_tiles = vision.vision(4, self.world_map, self.tile)
     target_tile = vision.find_target(visible_tiles, self.prey)
     if target_tile:
         move_to_tile = vision.approach(self.tile, target_tile, self.world_map)
         if self.is_movable_terrain(move_to_tile) and self.not_contains_sprite(move_to_tile, self.prey):
             AnimalSprite.move(self, move_to_tile)
         else:
             AnimalSprite.move(self)
     else:
         AnimalSprite.move(self)
Esempio n. 3
0
 def move(self, target=None):
     visible_tiles = vision.vision(15, self.world_map, self.tile)
     visible_tiles = filter(BeesSprite.pollinated_filter, visible_tiles)
     target_tile = vision.find_target(visible_tiles, self.prey)
     if target_tile:
         move_to_tile = vision.approach(self.tile, target_tile,
                                        self.world_map)
         if Sprite.is_movable_terrain(self, move_to_tile) and \
                 Sprite.not_contains_sprite(self, move_to_tile, self.prey):
             if move_to_tile == target_tile:
                 move_to_tile.contains_sprite.pollinate()
             Sprite.move(self, move_to_tile)
         else:
             Sprite.move(self)
     else:
         Sprite.move(self)
Esempio n. 4
0
    def move(self, target=None):
        """

        :return:
        """
        visible_tiles = vision.vision(10, self.world_map, self.tile)
        target_tile = vision.find_target(visible_tiles, self.prey)
        if target_tile:
            move_to_tile = vision.approach(self.tile, target_tile,
                                           self.world_map)
            if self.is_movable_terrain(
                    move_to_tile) and self.not_contains_sprite(
                        move_to_tile, self.prey):
                if move_to_tile == target_tile:
                    move_to_tile.contains_sprite.die()
                AnimalSprite.move(self, move_to_tile)
            elif not self.is_leader:
                leader_tile = self.find_leader()
                if leader_tile:
                    move_to_tile = vision.approach(self.tile, leader_tile,
                                                   self.world_map)
                    if self.is_movable_terrain(
                            move_to_tile) and self.not_contains_sprite(
                                move_to_tile, self.prey):
                        AnimalSprite.move(self, move_to_tile)
                else:
                    AnimalSprite.move(self)
            else:
                AnimalSprite.move(self)
        elif not self.is_leader:
            leader_tile = self.find_leader()
            if leader_tile:
                chance = random.randint(0, 10)
                if chance == 0:
                    AnimalSprite.move(self)
                else:
                    move_to_tile = vision.approach(self.tile, leader_tile,
                                                   self.world_map)
                    if self.is_movable_terrain(
                            move_to_tile) and self.not_contains_sprite(
                                move_to_tile, self.prey):
                        AnimalSprite.move(self, move_to_tile)
            else:
                AnimalSprite.move(self)
        else:
            AnimalSprite.move(self)
Esempio n. 5
0
def test_sample_images():
    variables = ['x', 'nt']
    with open('sample_img/tests.csv', 'r') as csvfile:
        # filename, x, y, w, h
        testreader = csv.reader(csvfile, delimiter=',')
        for sample in testreader:
            image = cv2.imread('sample_img/' + sample[0])
            # Rescale if necessary
            height, width, channels = image.shape
            x, img, num_targets, target_sep = find_target(image)
            assert num_targets == int(sample[2])
            if num_targets == 0:
                x = None
                continue
            if x != None and sample[1] != None:
                sample[1] = 2 * float(sample[1]) / width - 1
                assert math.isclose(x, sample[1], abs_tol=0.1)
Esempio n. 6
0
 def move(self, target=None):
     """
     @Override
         Move sprite to a specified target tile (target).
         Otherwise, moves sprite to a random adjacent tile.
     :param target: Target tile to move sprite.
     """
     visible_tiles = vision.vision(self.vision, self.world_map, self.tile)
     target_tile = vision.find_target(visible_tiles, self.prey)
     if target_tile:
         move_to_tile = vision.approach(self.tile, target_tile,
                                        self.world_map)
         if self.is_movable_terrain(
                 move_to_tile) and self.not_contains_sprite(
                     move_to_tile, self.prey):
             if move_to_tile == target_tile:
                 move_to_tile.contains_sprite.die()
             AnimalSprite.move(self, move_to_tile)
         else:
             AnimalSprite.move(self)
     else:
         AnimalSprite.move(self)
Esempio n. 7
0
def test_black():
    res = vision.find_target(np.zeros(shape=(320, 240, 3), dtype=np.uint8))
    assert res[2] is 0