Exemplo n.º 1
0
    def test_meta_inclusion(self):
        self.assertTrue(str(axl.MetaMajority()) in str_reps(axl.strategies))

        self.assertTrue(str(axl.MetaHunter()) in str_reps(axl.strategies))
        self.assertFalse(
            str(axl.MetaHunter()) in str_reps(axl.long_run_time_strategies)
        )
Exemplo n.º 2
0
    def test_score_with_particular_players(self):
        """
        These are players that are known to be difficult to pickle
        """
        name = "score"
        turns = 10
        noise = 0
        repetitions = 5
        num_states = 2
        opponents = [axl.ThueMorse(),
                     axl.MetaHunter(),
                     axl.BackStabber(),
                     axl.Alexei()]
        size = 10

        objective = dojo.prepare_objective(name=name,
                                           turns=turns,
                                           noise=noise,
                                           repetitions=repetitions)

        population = dojo.Population(player_class=player_class,
                                     params_kwargs={"num_states": num_states},
                                     size=size,
                                     objective=objective,
                                     output_filename=self.temporary_file.name,
                                     opponents=opponents,
                                     bottleneck=2,
                                     mutation_probability = .01,
                                     processes=0)

        generations = 4
        axl.seed(0)
        population.run(generations, print_output=False)
        self.assertEqual(population.generation, 4)
Exemplo n.º 3
0
    def test_strategy(self):

        P1 = axelrod.MetaHunter()
        P2 = axelrod.Player()

        self.assertEqual(P1.strategy(P2), 'C')

        # We are not using the Cooperator Hunter here, so this should lead to cooperation.
        P1.history = ['C'] * 4
        P2.history = ['C'] * 4
        self.assertEqual(P1.strategy(P2), 'C')

        # All these others, however, should trigger a defection for the hunter.
        histories = [
            ['D'] * 4,
            ['C', 'D'] * 2,
            ['C', 'C', 'C', 'D', 'C', 'C', 'C', 'D'],
            [random.choice(['C', 'D']) for i in range(8)],
        ]
        for h in histories:
            P1.history = ['C'] * len(h)
            P2.history = h
            self.assertEqual(P1.strategy(P2), 'D')
Exemplo n.º 4
0
 def test_update_histories(self):
     """Artificial test to ensure that an exception is thrown."""
     p = axl.MetaHunter()
     with self.assertRaises(TypeError):
         p.update_histories(C)