Exemplo n.º 1
0
 def test_rounds(self):
     self.versus_test(
         axl.Grudger(),
         axl.SuspiciousTitForTat(),
         [C] + [D] * 9,
         [D, C] + [D] * 8,
     )
Exemplo n.º 2
0
 def test_rounds(self):
     self.versus_test(
         axl.TitForTat(),
         axl.SuspiciousTitForTat(),
         [C, D, C, D, C, D],
         [D, C, D, C, D, C],
     )
def tscizzle_strategies():
    """The list of strategies used in @tscizzle's Morality Metrics paper."""

    strategies = [
        axelrod.Cooperator(),
        axelrod.Defector(),
        axelrod.Eatherley(),
        axelrod.Champion(),
        axelrod.GTFT(p=0.1),
        axelrod.GTFT(p=0.3),
        axelrod.GoByMajority(soft=True),
        axelrod.GoByMajority(soft=False),
        axelrod.TitFor2Tats(),
        axelrod.Random(0.8),
        axelrod.Random(0.5),
        axelrod.Random(0.2),
        axelrod.WinStayLoseShift(),  # Pavlov
        axelrod.TitForTat(),
        axelrod.TwoTitsForTat(),
        axelrod.Grudger(),  # Friedman
        axelrod.Tester(),
        axelrod.SuspiciousTitForTat(),
        axelrod.Joss(0.9),
        axelrod.Joss(0.7),
    ]
    return strategies
Exemplo n.º 4
0
    def test_strategy(self):
        # tests states 2, 7, 14 and 15
        actions = [(C, C), (C, D), (D, C), (D, D), (D, C), (D, D)]
        self.versus_test(opponent=axelrod.Alternator(),
                         expected_actions=actions)

        # tests states 4, 16 and 11
        actions = [(C, D), (C, D), (D, C), (D, D), (D, D), (C, C), (C, D)]
        self.versus_test(opponent=axelrod.CyclerDDC(),
                         expected_actions=actions)

        # tests states 3, 5 and 12
        actions = [(C, D), (C, C), (D, C), (D, D), (D, D), (C, D)]
        self.versus_test(opponent=axelrod.SuspiciousTitForTat(),
                         expected_actions=actions)

        # tests state 1
        actions = [(C, C), (C, C), (C, C), (C, C)]
        self.versus_test(opponent=axelrod.Cooperator(),
                         expected_actions=actions)

        # tests state 6
        actions = [(C, D), (C, C), (D, D), (C, C)]
        self.versus_test(opponent=axelrod.CyclerDC(),
                         expected_actions=actions)
Exemplo n.º 5
0
    def test_strategy(self):
        player_history = [C, D, C, D, C, C, C, C, C]
        opp_history = [D, C, D, C, D, C, C, C, C]
        actions = list(zip(player_history, opp_history))
        self.versus_test(axl.SuspiciousTitForTat(), expected_actions=actions)

        player_history = [C, C, D, C, D, C, C, C, D, D, D, D, D, D]
        opp_history = [C, D] * 7
        actions = list(zip(player_history, opp_history))
        self.versus_test(axl.Alternator(), expected_actions=actions)
Exemplo n.º 6
0
    def test_output_from_literature(self):
        """
        This strategy is not fully described in the literature, however the
        scores for the strategy against a set of opponents is reported

        Bruno Beaufils, Jean-Paul Delahaye, Philippe Mathie
        "Our Meeting With Gradual: A Good Strategy For The Iterated Prisoner's
        Dilemma" Proc. Artif. Life 1996

        This test just ensures that the strategy is as was originally defined.

        See https://github.com/Axelrod-Python/Axelrod/issues/1294 for another
        discussion of this.
        """
        players = [
            axl.Cooperator(),
            axl.Defector(),
            axl.Random(),
            axl.TitForTat(),
            axl.Grudger(),
            axl.CyclerDDC(),
            axl.CyclerCCD(),
            axl.GoByMajority(),
            axl.SuspiciousTitForTat(),
            axl.Prober(),
            self.player(),
            axl.WinStayLoseShift(),
        ]

        turns = 1000
        tournament = axl.Tournament(players,
                                    turns=turns,
                                    repetitions=1,
                                    seed=75)
        results = tournament.play(progress_bar=False)
        scores = [
            round(average_score_per_turn * 1000, 1)
            for average_score_per_turn in results.payoff_matrix[-2]
        ]
        expected_scores = [
            3000.0,
            915.0,
            2763.0,
            3000.0,
            3000.0,
            2219.0,
            3472.0,
            3000.0,
            2996.0,
            2999.0,
            3000.0,
            3000.0,
        ]
        self.assertEqual(scores, expected_scores)
Exemplo n.º 7
0
    def test_strategy(self):
        # Starts by cooperating.
        self.first_play_test(C)

        player_history = [C, C, D, C, D, C, C, C, D, C, C, C, D, D, D, D, D, D]
        opp_history = [C, D] * 9
        actions = list(zip(player_history, opp_history))
        self.versus_test(axelrod.Alternator(), expected_actions=actions)

        player_history =  [C, D, C, D, C, C, C, C, C]
        opp_history = [D, C, D, C, D, C, C, C, C]
        actions = list(zip(player_history, opp_history))
        self.versus_test(axelrod.SuspiciousTitForTat(),
                         expected_actions=actions)
Exemplo n.º 8
0
    def test_strategy_mutually_cooperative(self):
        # tests states 2, 7, 14 and 11
        actions = [(C, C), (C, D), (D, C), (D, D), (C, C), (C, D)]
        self.versus_test(opponent=axl.Alternator(), expected_actions=actions)

        # tests states 1, 4 and 8
        actions = [(C, D), (C, D), (D, D), (C, C), (C, C), (C, D)]
        self.versus_test(opponent=axl.Cycler(["D", "D", "D", "C", "C"]),
                         expected_actions=actions)

        # tests states 3, 5
        actions = [(C, D), (C, C), (D, C), (D, D), (C, D)]
        self.versus_test(opponent=axl.SuspiciousTitForTat(),
                         expected_actions=actions)
Exemplo n.º 9
0
    def test_strategy(self):
        actions = [(C, C)] * 100
        self.versus_test(axelrod.Cooperator(), expected_actions=actions)

        actions = [(C, D), (C, D), (D, D), (D, D)]
        self.versus_test(axelrod.Defector(), expected_actions=actions, seed=1)
        actions = [(C, D), (D, D), (D, D), (C, D)]
        self.versus_test(axelrod.Defector(), expected_actions=actions, seed=2)

        actions = [(C, D), (C, C), (D, C), (C, D), (D, C), (D, D), (C, D), (D, C), (C, D)]
        self.versus_test(axelrod.SuspiciousTitForTat(), expected_actions=actions, seed=1)

        actions = [(C, C), (C, D), (D, C)] + [(D, D), (C, C)] * 3
        self.versus_test(axelrod.Alternator(), expected_actions=actions, seed=2)
        actions = [(C, C), (C, D), (C, C)] + [(D, D), (C, C)] * 3
        self.versus_test(axelrod.Alternator(), expected_actions=actions, seed=3)
Exemplo n.º 10
0
 def test_affect_of_strategy(self):
     """Will do opposite of what opponent does."""
     P1 = axelrod.SuspiciousTitForTat()
     P2 = axelrod.Player()
     P1.history = ['D']
     P2.history = ['C']
     self.assertEqual(P1.strategy(P2), 'D')
     P1.history.append('D')
     P2.history.append('D')
     self.assertEqual(P1.strategy(P2), 'C')
     P1.history.append('C')
     P2.history.append('D')
     self.assertEqual(P1.strategy(P2), 'C')
     P1.history.append('C')
     P2.history.append('C')
     self.assertEqual(P1.strategy(P2), 'D')
Exemplo n.º 11
0
 def test_rounds(self):
     self.versus_test(axelrod.FoolMeOnce(), axelrod.SuspiciousTitForTat(),
                      [C] * 9, [D] + [C] * 8)
Exemplo n.º 12
0
 def test_rounds(self):
     outcomes = zip()
     self.versus_test(axelrod.OmegaTFT(), axelrod.SuspiciousTitForTat(),
                      [C, D, C, D, C, C, C, C, C],
                      [D, C, D, C, D, C, C, C, C])
Exemplo n.º 13
0
oppScore = []
selfAvgList = []
oppAvgList = []
avgScore = []
oppAvgScore = []

evolveCode = [0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0,\
 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 1, 0, 0]     # For final experiments

singEvolveCode = [0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 1,\
 0, 1, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 0]

# strategies = [axelrod.Cooperator(), axelrod.Defector()]
# strategies = [axelrod.TitFor2Tats(), axelrod.SuspiciousTitForTat(), axelrod.TitForTat(), axelrod.Prober()]
strategies = [axelrod.Cooperator(), axelrod.Defector(), axelrod.CyclerCCD(),axelrod.HardTitForTat(),\
axelrod.TitFor2Tats(), axelrod.SuspiciousTitForTat(), axelrod.Random(), axelrod.TitForTat(), axelrod.Prober()]

learner = axelrod.LearnerAxel(memory_depth=2, exploreProb=0.1, learnerType=2)
multAxel = axelrod.EvolveAxel(3, evolveCode, 'MULT')
singAxel = axelrod.EvolveAxel(3, evolveCode, 'SING')

ply = learner

# print ply

for p in strategies:
    print "Currently playing against strategy:", p
    for turn in range(numTurns):
        ply.play(p)
    selfList = map(ScoreMatrix, zip(ply.history, p.history))
    oppList = map(ScoreMatrix, zip(p.history, ply.history))
Exemplo n.º 14
0
 def test_strategy(self):
     """Starts by defecting"""
     P1 = axelrod.SuspiciousTitForTat()
     P2 = axelrod.Player()
     self.assertEqual(P1.strategy(P2), 'D')