示例#1
0
    def test_sexual_reproduction_gen_offspring(self):
        """
        Test sexual_reproduction for mother (i.e. gen_offspring = True)
        """

        player = Player(i=2, log_dir=".", tob=10, energy=200, x=0, y=0)
        len_players = 10
        offspring_players, offspring_ids = player.sexual_reproduction(
            mating_begin_time=30,
            len_players=len_players,
            initial_energy=200,
            gen_offspring=True,
            mate_id=3,
            mate_tob=12,
        )

        self.assertEqual(len(offspring_players), len(offspring_ids))

        self.assertEqual(player.energy, 170)
        self.assertEqual(player.cannot_move, True)
        self.assertEqual(player.mating_begin_time, 30)

        for i in range(len(offspring_ids)):
            with self.subTest("Testing offspring ids in asexual reproduction",
                              i=i):
                self.assertEqual(offspring_ids[i], len_players + i)
                self.assertEqual(offspring_players[i].action_history[-1][0][0],
                                 2)
                self.assertEqual(offspring_players[i].action_history[-1][0][1],
                                 10)
                self.assertEqual(offspring_players[i].action_history[-1][1][0],
                                 3)
                self.assertEqual(offspring_players[i].action_history[-1][1][1],
                                 12)
示例#2
0
    def test_sexual_reproduction_no_gen_offspring(self):
        """
        Test sexual_reproduction for father (i.e. gen_offspring = False)
        """

        player = Player(i=2, log_dir=".", tob=10, energy=200, x=0, y=0)
        len_players = 10
        player.sexual_reproduction(
            mating_begin_time=30,
            len_players=len_players,
            initial_energy=200,
            gen_offspring=False,
            mate_id=3,
            mate_tob=12,
        )

        self.assertEqual(player.energy, 170)
        self.assertEqual(player.cannot_move, True)
        self.assertEqual(player.mating_begin_time, 30)