Exemplo n.º 1
0
    def test_update_history_action_asexual_reproduction(self):
        """
        Test update_history method for action 10 (i.e. asexual reproduction)
        """

        player = Player(i=10, log_dir=".", tob=10, energy=200, x=0, y=0)
        player.states.append([-1, -1])
        player.update_history(action=10,
                              time=10,
                              reward=-2,
                              num_offspring=2,
                              offspring_ids=[11, 12])

        check_vals = [10, 10, -2, 200, 2, [11, 12], 0, 0, [-1, -1]]

        for i in range(len(check_vals)):
            if i != 5:
                with self.subTest("Check action history for failed action",
                                  i=i):
                    self.assertEqual(player.action_history[-1][i],
                                     check_vals[i])
            else:
                with self.subTest("Check action history for failed action",
                                  i=i):
                    self.assertEqual(player.action_history[-1][i][0],
                                     check_vals[i][0])
                    self.assertEqual(player.action_history[-1][i][1],
                                     check_vals[i][1])
Exemplo n.º 2
0
    def test_update_history_action_fight(self):
        """
        Test update_history method for action 12 (i.e. fight)
        """

        player = Player(i=10, log_dir=".", tob=10, energy=200, x=0, y=0)
        player.states.append([-1, -1])
        player.update_history(action=12, time=10, reward=-2, fight_with=6)

        check_vals = [12, 10, -2, 200, 6, 0, 0, [-1, -1]]

        for i in range(len(check_vals)):
            with self.subTest("Check action history for failed action", i=i):
                self.assertEqual(player.action_history[-1][i], check_vals[i])
Exemplo n.º 3
0
    def test_update_history_action_less_equal_9(self):
        """
        Test update_history method for an action <= 9 (i.e. movement in 8 directions, stay, and ingestion),
        tested with action 7 here (moving south-east)
        """

        player = Player(i=10, log_dir=".", tob=10, energy=200, x=0, y=0)
        player.states.append([-1, -1])
        player.update_history(action=7, time=10, reward=-2)

        check_vals = [7, 10, -2, 200, 0, 0, [-1, -1]]

        for i in range(len(check_vals)):
            with self.subTest("Check action history for an action <= 9", i=i):
                self.assertEqual(player.action_history[-1][i], check_vals[i])