def sp_strategies():
    """The list of strategies used in Stewart and Plotkin's 2012 tournament."""

    strategies = [
        axelrod.Cooperator(),  # ALLC
        axelrod.Defector(),  # ALLD
        axelrod.GTFT(),
        axelrod.GoByMajority(soft=False),  # HARD_MAJO
        #axelrod.GoByMajority(soft=True), # SOFT_MAJO
        axelrod.TitFor2Tats(),  # TFT2
        axelrod.HardTitFor2Tats(),  # HARD_TFT2
        axelrod.Random(),  # RANDOM
        axelrod.WinStayLoseShift(),  # WSLS
        axelrod.TitForTat(),
        axelrod.HardTitForTat(),  # HARD_TFT
        axelrod.Grudger(),  # GRIM
        axelrod.Joss(),  # HARD_JOSS
        axelrod.ZDGTFT2(),
        axelrod.ZDExtort2(),
        axelrod.Prober(),
        axelrod.Prober2(),
        axelrod.Prober3(),
        axelrod.HardProber(),
        axelrod.Calculator(),
    ]
    return strategies
Esempio n. 2
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)
Esempio n. 3
0
    def test_specific_set_of_results(self):
        """
        This tests specific reported results as discussed in
        https://github.com/Axelrod-Python/Axelrod/issues/1294

        The results there used a version of mistrust with a bug that corresponds
        to a memory one player that start by defecting and only cooperates if
        both players cooperated in the previous round.
        """
        mistrust_with_bug = axl.MemoryOnePlayer(
            initial=D,
            four_vector=(1, 0, 0, 0),
        )
        players = [
            self.player(),
            axl.TitForTat(),
            axl.GoByMajority(),
            axl.Grudger(),
            axl.WinStayLoseShift(),
            axl.Prober(),
            axl.Defector(),
            mistrust_with_bug,
            axl.Cooperator(),
            axl.CyclerCCD(),
            axl.CyclerDDC(),
        ]
        axl.seed(1)
        tournament = axl.Tournament(players, turns=1000, repetitions=1)
        results = tournament.play(progress_bar=False)
        scores = [
            round(average_score_per_turn * 1000, 1)
            for average_score_per_turn in results.payoff_matrix[0]
        ]
        expected_scores = [
            3000.0,
            3000.0,
            3000.0,
            3000.0,
            3000.0,
            2999.0,
            983.0,
            983.0,
            3000.0,
            3596.0,
            2302.0,
        ]
        self.assertEqual(scores, expected_scores)
Esempio n. 4
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))
Esempio n. 5
0
    axl.Weiner(),
    axl.White(),
    axl.WmAdams(),
    axl.Yamachi()
]

# The list of agents playing in the Stewart-Plotkin's tournament.
steward_plotkin_players = [
    axl.ZDExtort2(),
    axl.HardGoByMajority(),
    axl.HardTitForTat(),
    axl.HardTitFor2Tats(),
    axl.GTFT(),
    axl.ZDGTFT2(),
    axl.Calculator(),
    axl.Prober(),
    axl.Prober2(),
    axl.Prober3(),
    axl.HardProber(),
    axl.NaiveProber()
]

# The list of agents playing in the Case's simulation
case_players = [
    axl.Cooperator(),
    axl.Defector(),
    axl.TitForTat(),
    axl.Grudger(),
    axl.Detective(),
    axl.TitFor2Tats(),
    axl.WinStayLoseShift(),
Esempio n. 6
0
def getdata(n=1000,
            ld=10,
            players=[axl.Cooperator(), axl.Defector(), axl.TitForTat(), axl.WinStayLoseShift(), axl.Prober(), axl.Grudger()]):
    ds = ClassificationDataSet(ld*2, nb_classes=len(players))
    j = 2
    k = 2
    while j<n:
        for a in (0, 0.01, 0.02):
            tournament = axl.Tournament(players, turns=ld, repetitions=1, noise=a)
            results = tournament.play(keep_interactions=True)
            print()
            for index_pair, interaction in results.interactions.items():
                player1 = tournament.players[index_pair[0]]
                player2 = tournament.players[index_pair[1]]
                r1 = []
                r2 = []
                for i in interaction[0]:
                    if i == (Action.C, Action.C): r2.append(1), r2.append(1), r1.append('R') # CC R 1
                    if i == (Action.D, Action.D): r2.append(-1), r2.append(-1), r1.append('P') # DD P 4
                    if i == (Action.D, Action.C): r2.append(-1), r2.append(1), r1.append('T') # DC T 2
                    if i == (Action.C, Action.D): r2.append(1), r2.append(-1), r1.append('S') # CD S 3
                if r1 != (ld*['P']) and r1 != ld*['R'] and r1 != ld*['S'] and r1 != ld*['T']:
                    print('%i %i %s (%s) vs %s (%s): %s' % (k, j, player1, index_pair[0], player2, index_pair[1], r1))
                    ds.addSample(r2, (index_pair[0]))
                    j+=1
                k+=1
    print(len(ds))
    return ds