Beispiel #1
0
    def test_feature_collide_scale(self):
        vos = [VisibleObject(Rect((5, i * 20), (10, 10)), i + 1)
               for i in range(2, 10)]
        # colliding objects
        vos.append(VisibleObject(Rect((0, 9), (10, 10)), 10))
        vos.append(VisibleObject(Rect((30, 0), (10, 10)), 11))

        obs = Observation(max_id=11)
        obs.update_sensors(self.x_rect)

        '''
        Map is like following (. :actor, * :visible object)
0       |.| | |*|
9       |*| |
        | | |
        | | |
40      |*| |
        | | |
60      |*| |
        '''

        prepr_obs = obs.get_observation(self.x_rect, vos,
                                        preproc_mode=['collide', 'scale'])

        z = none_vis_id
        x = [0, 20/game_height, 0, 0,
             z, 11,            10, z,
             0, 0,              1, 0] == prepr_obs

        self.assertTrue(x.all())
Beispiel #2
0
 def __create_walls(self):
     self.walls.append(VisibleObject(Rect(0, 0, 1, game_height),
                                     wall_id))  # lewa
     self.walls.append(VisibleObject(Rect(0, 0, game_width, 1),
                                     wall_id))  # gorna
     self.walls.append(
         VisibleObject(Rect(0, game_height - 1, game_width, 1),
                       wall_id))  # dolna
     self.walls.append(
         VisibleObject(Rect(game_width - 1, 0, 1, game_height),
                       wall_id))  # prawa
Beispiel #3
0
    def test_sensor_with_multiple_objects(self):
        s = CommonSensors.down(self.x_rect.rect)

        vos = [VisibleObject(Rect((5, i), (10, 10)), 1) for i in range(120, 150)]
        s.add_objects_if_visible(vos)

        self.assertEqual(30, len(s.get_nearest(100)))
        self.assertEqual([[110, 1],
                          [111, 1],
                          [112, 1]],
                         s.get_nearest(3))
Beispiel #4
0
    def test_wall_stops_actors(self):
        gs = GameState()

        ac = VisibleActor('asd', pygame.Rect((100, 50, 10, 10)))
        ac.next_act = lambda _: Action(actions[down_id])

        ac2 = VisibleActor('asd', pygame.Rect((130, 60, 10, 10)))
        ac2.next_act = lambda _: Action(actions[down_id])

        gs.add_actor(ac)
        gs.add_actor(ac2)
        gs.add_action(
            Action(actions[food_id], rect=pygame.Rect((120, 150, 20, 10))))
        gs.add_wall(VisibleObject(pygame.Rect((100, 300, 50, 10)), wall_id))

        for i in range(300):
            gs.update()
            self.assertFalse(
                ac.rect.colliderect(pygame.Rect((100, 300, 50, 10))))

        self.assertEqual(ac.rect.y, 290)
Beispiel #5
0
    def test_get_observation_from_directional_sensors(self):
        vos = [VisibleObject(Rect((5, i*20), (10, 10)), i)
               for i in range(2, 10)]

        obs = Observation()
        obs.update_sensors(self.x_rect)

        '''
        Map is like following (. :actor, * :visible object)
0       |.|
10      | |
        | |
        | |
40      |*|
        | |
60      |*|
        '''

        prepr_obs = obs.get_observation(self.x_rect, vos,
                                        preproc_mode='')

        z = none_vis_id
        x = [0, 0, 30, 0, z, z, 2, z] == prepr_obs
        self.assertTrue(x.all())
Beispiel #6
0
 def setUp(self):
     self.x_rect = VisibleObject(Rect((0, 0), (10, 10)), 2)
     self.ac_rect = VisibleObject(Rect((10, 0), (10, 10)), 1)
Beispiel #7
0
    def test_sensor_down(self):
        s = CommonSensors.down(self.x_rect.rect)
        s.add_objects_if_visible(
            [VisibleObject(Rect((5, 100), (10, 10)), 1)])

        self.assertEqual([90, 1], s.get_nearest())