コード例 #1
0
ファイル: test_memorytwo.py プロジェクト: vanden/Axelrod
    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)
コード例 #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)
コード例 #3
0
ファイル: test_titfortat.py プロジェクト: oneway3124/Axelrod
    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)