示例#1
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')
示例#2
0
 def test_move_west(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')
     observation, reward, done, _ = blobble_env.step(4)  # Step West
     self.assertEqual(0, observation[0], 'Should be northerly=0')
     self.assertEqual(0, observation[1], 'Should be easterly=0')
示例#3
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')
示例#4
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')
示例#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')
示例#6
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')
示例#7
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')
示例#8
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')
示例#9
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')
示例#10
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')
示例#11
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')
示例#12
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')
示例#13
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')
示例#14
0
def create_blobble_video(video_filename, num_episodes=1, fps=30):
    filename = video_filename + ".mp4"

    blobble_env = BlobbleEnv()

    print('Observation space: '+str(blobble_env.observation_space))
    print('Action space:      '+str(blobble_env.action_space))

    with imageio.get_writer(filename, fps=fps) as video:
        for i in range(num_episodes-1):
            print(i)
            blobble_env.reset()
            done = False
            while not done:
                action = np.random.randint(8)
                print('Next Action: ', action)
                observation, reward, done, _ = blobble_env.step(action)
                blobble_env.render_print()
                video.append_data(blobble_env.render(mode='rgb_array'))

    blobble_env.close()