Ejemplo n.º 1
0
 def test_reset(self):
     player = self.player()
     opponent = axl.Cooperator()
     match = Match((player, opponent), turns=100)
     match.play()
     self.assertFalse(player.countCC == 0)
     player.reset()
     self.assertTrue(player.countCC == 0)
Ejemplo n.º 2
0
def test_champion_v_alternator():
    """
    Specific regression test for a bug. See:
    https://github.com/Axelrod-Python/axelrod-fortran/issues/62
    """
    player = Player("k61r")
    opponent = Alternator()
    seed = 3
    match = Match((player, opponent), seed=seed)
    interactions = match.play()
    assert interactions[25:30] == [(C, D), (C, C), (C, D), (D, C), (C, D)]
    match = Match((player, opponent), seed=seed)
    assert interactions == match.play()
Ejemplo n.º 3
0
def test_deterministic_strategies():
    """
    Test that the strategies classified as deterministic indeed act
    deterministically.
    """
    for strategy in all_strategies:
        player = Player(strategy)
        if player.classifier["stochastic"] is False:
            for opponent in basic_strategies:
                match = Match((player, opponent()))
                interactions = match.play()
                for _ in range(2):  # Repeat 3 matches
                    assert interactions == match.play(), player
Ejemplo n.º 4
0
def test_match_reproducibility():
    for _ in range(100):
        rng = RandomGenerator()
        seed = rng.random_seed_int()
        strategies = rng.choice(all_strategies, size=2)
        players1 = [Player(strategy) for strategy in strategies]
        match1 = Match(players1, turns=200, noise=0.1, seed=seed)
        results1 = match1.play()

        players2 = [Player(strategy) for strategy in strategies]
        match2 = Match(players2, turns=200, noise=0.1, seed=seed)
        results2 = match2.play()

        assert (results1 == results2)
Ejemplo n.º 5
0
def test_probend_matches():
    for strategy in all_strategies:
        for opponent in (Alternator, Cooperator, Defector):
            players = (Player(strategy), opponent())
            match = Match(players, prob_end=0.5, noise=0.5)
            assert all(action in (C, D) for interaction in match.play()
                       for action in interaction)
Ejemplo n.º 6
0
def test_matches():
    for strategy in all_strategies:
        for opponent in (Alternator, Cooperator, Defector):
            players = (Player(strategy), opponent())
            match = Match(players, turns=200)
            assert all(action in (C, D) for interaction in match.play()
                       for action in interaction)
Ejemplo n.º 7
0
def test_matches_with_different_game():
    for strategy in all_strategies:
        for opponent in (Alternator, Cooperator, Defector):
            game = Game(r=4, s=0, p=2, t=6)
            players = (Player(strategy), opponent())
            match = Match(players, turns=200, game=game)
            assert all(action in (C, D) for interaction in match.play()
                       for action in interaction)
Ejemplo n.º 8
0
def test_warning_for_self_interaction(recwarn):
    """
    Test that a warning is given for a self interaction.
    """
    player = Player("k42r")
    opponent = player
    match = Match((player, opponent))
    interactions = match.play()
    assert len(recwarn) == 1
Ejemplo n.º 9
0
def test_no_warning_for_normal_interaction(recwarn):
    """
    Test that a warning is not given for a normal interaction
    """
    for players in [(Player("k42r"), Alternator()),
                    (Player("k42r"), Player("k41r"))]:

        match = Match(players)
        interactions = match.play()
        assert len(recwarn) == 0
Ejemplo n.º 10
0
def test_implemented_strategies():
    """
    Test that the deterministic strategies that are implemented in Axelrod
    give the same outcomes.
    """
    for strategy, dictionary in characteristics.items():
        axelrod_class = dictionary["axelrod-python_class"]
        stochastic = Player(strategy).classifier["stochastic"]
        if axelrod_class is not None and not stochastic:
            for opponent_strategy in basic_strategies:
                player = Player(strategy)
                opponent = opponent_strategy()
                match = Match((player, opponent))
                interactions = match.play()

                axl_player = axelrod_class()
                opponent = opponent_strategy()
                axl_match = Match((axl_player, opponent))
                axl_interactions = axl_match.play()
                assert interactions == axl_interactions
Ejemplo n.º 11
0
 def test_strategy(self):
     player = self.player()
     # Test against cyclers
     for opponent in [
             axl.CyclerCCD(),
             axl.CyclerCCCD(),
             axl.CyclerCCCCCD(),
             axl.Alternator(),
     ]:
         player.reset()
         match = Match((player, opponent), turns=50)
         match.play()
         self.assertEqual(player.history[-1], D)
     # Test against non-cyclers and cooperators
     for opponent in [
             axl.Random(),
             axl.AntiCycler(),
             axl.DoubleCrosser(),
             axl.Cooperator(),
     ]:
         player.reset()
         match = Match((player, opponent), turns=50, seed=43)
         match.play()
         self.assertEqual(player.history[-1], C)