Ejemplo n.º 1
0
 def test_move_east(self):
     blobble_env = BlobbleEnv()
     blobble_env.reset()
     blobble_env.reset_test([0, 0, 5], TEST_FOOD)
     observation, reward, done, _ = blobble_env.step(3)  # Step East
     self.assertEqual(0, observation[0], 'Should be northerly=0')
     self.assertEqual(1, observation[1], 'Should be easterly=1')
Ejemplo n.º 2
0
 def test_move_too_far_north(self):
     blobble_env = BlobbleEnv()
     blobble_env.reset()
     blobble_env.reset_test([10, 0, 5], TEST_FOOD)
     observation, reward, done, _ = blobble_env.step(1)  # Step North
     self.assertEqual(10, observation[0], 'Should be northerly=10')
     self.assertEqual(0, observation[1], 'Should be easterly=0')
Ejemplo n.º 3
0
 def test_move_too_far_west(self):
     blobble_env = BlobbleEnv()
     blobble_env.reset()
     blobble_env.reset_test([0, -10, 5], TEST_FOOD)
     observation, reward, done, _ = blobble_env.step(4)  # Step West
     self.assertEqual(0, observation[0], 'Should be northerly=0')
     self.assertEqual(-10, observation[1], 'Should be easterly=-10')
Ejemplo n.º 4
0
 def test_reward_eat_no_nutritional_value(self):
     blobble_env = BlobbleEnv()
     blobble_env.reset()
     blobble_env.reset_test([0, 0, 5], TEST_FOOD)
     observation, reward, done, _ = blobble_env.step(0)  # Eat food=0
     self.assertEqual(5, observation[2], 'Should be health=5')
     self.assertEqual(0.5, reward, 'Should be reward=0.5')
Ejemplo n.º 5
0
 def test_eat_no_step(self):
     blobble_env = BlobbleEnv()
     blobble_env.reset()
     blobble_env.reset_test([0, 0, 5], TEST_FOOD)
     observation, reward, done, _ = blobble_env.step(0)  # No step
     self.assertEqual(0, observation[0], 'Should be northerly=0')
     self.assertEqual(0, observation[1], 'Should be easterly=0')
Ejemplo n.º 6
0
 def test_move_south(self):
     blobble_env = BlobbleEnv()
     blobble_env.reset()
     blobble_env.reset_test([0, 0, 5], TEST_FOOD)
     observation, reward, done, _ = blobble_env.step(0)  # No step
     observation, reward, done, _ = blobble_env.step(1)  # Step North
     observation, reward, done, _ = blobble_env.step(2)  # Step South
     self.assertEqual(0, observation[0], 'Should be northerly=0')
     self.assertEqual(0, observation[1], 'Should be easterly=0')
Ejemplo n.º 7
0
    def test_reward_eat_nutritional_value(self):
        blobble_env = BlobbleEnv()
        blobble_env.reset()
        blobble_env.reset_test([0, 0, 5], TEST_FOOD)
        observation, reward, done, _ = blobble_env.step(3)  # Move East
        observation, reward, done, _ = blobble_env.step(1)  # Move North
        observation, reward, done, _ = blobble_env.step(0)  # Eat food=5

        self.assertEqual(10, observation[2], 'Should be health=10')
        self.assertEqual(1.0, reward, 'Should be reward=1.0')
Ejemplo n.º 8
0
 def test_smell_south(self):
     blobble_env = BlobbleEnv()
     blobble_env.reset()
     blobble_env.reset_test([0, 0, 5], TEST_FOOD)
     observation, reward, done, _ = blobble_env.step(0)  # Eat food at current location
     '''
     [ ., ., B, ., .]
     [ ., 2, 0, -5 .],
     [ ., ., 0, ., .],
     '''
     self.assertEqual(-2, observation[5], 'Should be sniff south=0.75')
Ejemplo n.º 9
0
 def test_smell_west(self):
     blobble_env = BlobbleEnv()
     blobble_env.reset()
     blobble_env.reset_test([0, 0, 5], TEST_FOOD)
     observation, reward, done, _ = blobble_env.step(0)  # Eat food at current location
     '''
     [ ., 4, ., ., .],
     [ 2, 4, B, ., .],
     [ ., 2, ., ., .],
     '''
     self.assertEqual(0, observation[7], 'Should be sniff west=3')
Ejemplo n.º 10
0
 def test_taste(self):
     blobble_env = BlobbleEnv()
     blobble_env.reset()
     observation = blobble_env.reset_test([0, 0, 5], TEST_FOOD)
     self.assertEqual(0, observation[3], 'Should be taste=0')
     observation = blobble_env.reset_test([-1, -4, 5], TEST_FOOD)
     self.assertEqual(-2, observation[3], 'Should be taste=-2')
     observation = blobble_env.reset_test([3, 3, 5], TEST_FOOD)
     self.assertEqual(1, observation[3], 'Should be taste=1')
     observation = blobble_env.reset_test([3, 4, 5], TEST_FOOD)
     self.assertEqual(-2, observation[3], 'Should be taste=-2')
Ejemplo n.º 11
0
 def test_smell_north(self):
     blobble_env = BlobbleEnv()
     blobble_env.reset()
     blobble_env.reset_test([0, 0, 5], TEST_FOOD)
     observation, reward, done, _ = blobble_env.step(0)  # Eat food at current location
     '''
     [ ., ., ., ., .],
     [ ., 4, 2, 3, .],
     [ ., ., B, ., .]
     '''
     self.assertEqual(3, observation[4], 'Should be sniff north=4')
Ejemplo n.º 12
0
 def test_no_taste(self):
     blobble_env = BlobbleEnv()
     blobble_env.reset()
     observation = blobble_env.reset_test([3, 3, 5], TEST_FOOD, taste=False)
     self.assertEqual(0, observation[3], 'Should be no taste 0')
     observation, reward, done, _ = blobble_env.step(4)  # Step West
     self.assertEqual(0, observation[3], 'Should be no taste 0')
Ejemplo n.º 13
0
 def test_eat(self):
     blobble_env = BlobbleEnv()
     blobble_env.reset()
     observation = blobble_env.reset_test([3, 3, 5], TEST_FOOD)
     self.assertEqual(1, observation[3], 'Should be food of value 1')
     observation, reward, done, _ = blobble_env.step(0)  # Eat food
     self.assertEqual(0, observation[3], 'Should be no food')
Ejemplo n.º 14
0
    def test_reset_observation(self):
        blobble_env = BlobbleEnv()
        observation = blobble_env.reset()
        expected = np.array((0, 0, 5), dtype=np.float)
        np.testing.assert_array_equal(expected, observation[0:3], 'Observation not as expected after reset')

        observation = blobble_env.reset_test([1, 2, 3], TEST_FOOD)
        expected = np.array((1, 2, 3), dtype=np.float)
        np.testing.assert_array_equal(expected, observation[0:3], 'Observation not as expected after reset test')
Ejemplo n.º 15
0
 def test_eat_and_move_west(self):
     blobble_env = BlobbleEnv()
     blobble_env.reset()
     observation = blobble_env.reset_test([3, 3, 5], TEST_FOOD)
     print(observation)
     self.assertEqual(1, observation[3], 'Should be food of value 1')
     observation, reward, done, _ = blobble_env.step(8)  # Eat food, Go West
     print(observation)
     observation, reward, done, _ = blobble_env.step(3)  # Go East back to original (no food) spot
     print(observation)
     self.assertEqual(0, observation[3], 'Should be no food')
Ejemplo n.º 16
0
    def test_no_smell(self):
        blobble_env = BlobbleEnv()
        blobble_env.reset()
        observation = blobble_env.reset_test([3, 3, 5], TEST_FOOD, smell=False)
        self.assertEqual(0, observation[4], 'Should be no smell north')
        self.assertEqual(0, observation[5], 'Should be no smell south')
        self.assertEqual(0, observation[6], 'Should be no smell east')
        self.assertEqual(0, observation[7], 'Should be no smell west')

        observation, reward, done, _ = blobble_env.step(4)  # Step West
        self.assertEqual(0, observation[4], 'Should be no smell north after step')
        self.assertEqual(0, observation[5], 'Should be no smell south after step')
        self.assertEqual(0, observation[6], 'Should be no smell east after step')
        self.assertEqual(0, observation[7], 'Should be no smell west after step')
Ejemplo n.º 17
0
 def test_render_human(self):
     blobble_env = BlobbleEnv()
     blobble_env.reset()
     blobble_env.reset_test([-2, 5, 5], TEST_FOOD)
     blobble_env.render(mode='human')