def test_strategy(self):
        # Starts by cooperating.
        self.first_play_test(C)

        opponent = axelrod.MockPlayer(actions=[C, C, C, D, C, C])
        actions = [(C, C), (C, C), (D, C), (D, D), (C, C), (C, C)]
        self.versus_test(opponent, expected_actions=actions)

        # Repents if punished for a defection
        actions = [(C, C), (C, D), (D, C), (C, D), (C, C)]
        self.versus_test(axelrod.Alternator(), expected_actions=actions)
    def test_strategy(self):
        # Cooperates for the first ten rounds
        actions = [(C, C)] * 10
        self.versus_test(axelrod.Cooperator(), expected_actions=actions)

        actions = [(C, D)] * 10
        self.versus_test(axelrod.Defector(), expected_actions=actions)

        actions = [(C, C), (C, D)] * 5
        self.versus_test(axelrod.Alternator(), expected_actions=actions)

        # If opponent defects at any point then the player will defect forever
        # (after 10 rounds)
        opponent = axelrod.MockPlayer(actions=[C] * 10 + [D])
        actions = [(C, C)] * 10 + [(C, D), (D, C)]
        self.versus_test(opponent, expected_actions=actions)

        opponent = axelrod.MockPlayer(actions=[C] * 15 + [D])
        actions = [(C, C)] * 15 + [(C, D), (D, C)]
        self.versus_test(opponent, expected_actions=actions)
Exemple #3
0
    def test_strategy(self):
        # Repeats last action of opponent history until 2 consecutive
        # defections, then always defects
        opponent = axelrod.MockPlayer(actions=[C, C, C, C])
        actions = [(C, C)] * 5
        self.versus_test(opponent,
                         expected_actions=actions,
                         attrs={"retaliating": False})

        opponent = axelrod.MockPlayer(actions=[C, C, C, C, D, C])
        actions = [(C, C)] * 4 + [(C, D), (D, C), (C, C)]
        self.versus_test(opponent,
                         expected_actions=actions,
                         attrs={"retaliating": False})

        opponent = axelrod.MockPlayer(actions=[C, C, D, D, C])
        actions = [(C, C), (C, C), (C, D), (D, D), (D, C)]
        self.versus_test(opponent,
                         expected_actions=actions,
                         attrs={"retaliating": True})
Exemple #4
0
    def test_strategy(self):
        # Start with TFT
        actions = [(C, C), (C, C)]
        self.versus_test(
            opponent=axl.Cooperator(),
            expected_actions=actions,
            attrs={"play_as": "TFT", "shift_counter": 1, "alld_counter": 0},
        )
        actions = [(C, D), (D, D)]
        self.versus_test(
            opponent=axl.Defector(),
            expected_actions=actions,
            attrs={"play_as": "TFT", "shift_counter": 1, "alld_counter": 0},
        )
        # TFTT if C, D and D, C
        opponent = axl.MockPlayer([D, C, D, D])
        actions = [(C, D), (D, C), (C, D), (C, D)]
        self.versus_test(
            opponent=opponent,
            expected_actions=actions,
            attrs={"play_as": "TFTT", "shift_counter": 1, "alld_counter": 0},
        )

        opponent = axl.MockPlayer([D, C, D, D])
        actions = [
            (C, D),
            (D, C),
            (C, D),
            (C, D),
            (D, D),
            (D, C),
            (D, D),
            (D, D),
            (D, D),
            (D, C),
        ]
        self.versus_test(
            opponent=opponent,
            expected_actions=actions,
            attrs={"play_as": "ALLD", "shift_counter": -1, "alld_counter": 2},
        )
Exemple #5
0
    def test_starting_defect_keeps_alt_strategy_from_triggering(self):
        opponent_actions_suffix = [C, D, C, D, D] + 3 * [C]
        expected_actions_suffix = [(C, C), (C, D), (C, C), (C, D), (C, D)] + 3 * [(D, C)]

        defects_on_first = [D] + [C] * 6
        defects_on_first_actions = [(C, D)] + [(C, C)] * 6
        self.versus_test(axelrod.MockPlayer(actions=defects_on_first + opponent_actions_suffix),
                         expected_actions=defects_on_first_actions + expected_actions_suffix,
                         match_attributes={"length": 200})

        defects_in_middle = [C, C, C, D, C, C, C]
        defects_in_middle_actions = [(C, C), (C, C), (C, C), (C, D), (C, C), (C, C), (C, C)]
        self.versus_test(axelrod.MockPlayer(actions=defects_in_middle + opponent_actions_suffix),
                         expected_actions=defects_in_middle_actions + expected_actions_suffix,
                         match_attributes={"length": 200})

        defects_on_last = [C] * 6 + [D]
        defects_on_last_actions = [(C, C)] * 6 + [(C, D)]
        self.versus_test(axelrod.MockPlayer(actions=defects_on_last + opponent_actions_suffix),
                         expected_actions=defects_on_last_actions + expected_actions_suffix,
                         match_attributes={"length": 200})
Exemple #6
0
    def test_strategy(self):
        # Will defect twice when last turn of opponent was defection.
        opponent = axelrod.MockPlayer(actions=[D, C, C, D, C])
        actions = [(C, D), (D, C), (D, C), (C, D), (D, C)]
        self.versus_test(opponent, expected_actions=actions)

        actions = [(C, C), (C, C)]
        self.versus_test(opponent=axelrod.Cooperator(),
                         expected_actions=actions)

        actions = [(C, D), (D, D), (D, D)]
        self.versus_test(opponent=axelrod.Defector(), expected_actions=actions)
    def test_strategy(self):
        """Test that the strategy gives expected behaviour."""

        # Test next move matches opponent
        actions = [(C, C)] * 19
        self.versus_test(axelrod.Cooperator(), expected_actions = actions)

        actions = [(C, C), (C, C), (C, D),(D, C)]
        self.versus_test(opponent=axelrod.MockPlayer(actions=[C,C,D,C]), expected_actions = actions)

        actions = [(C, C)] * 18 + [(C, D), (D, C)]
        self.versus_test(opponent=axelrod.MockPlayer(actions=[C] * 18 + [D, C]), expected_actions = actions)

        # After round 20, strategy follows stochastic behavior given a seed
        actions = [(C, C)] * 20 + [(C, D), (D, C), (C, C), (C, D)]
        self.versus_test(opponent=axelrod.MockPlayer(actions=[C] * 20 + [D, C, C, D]), expected_actions = actions,
                         seed=8)

        actions = [(C, C)] * 20 + [(D, D), (D, C)] + [(C, C)] * 2 + [(D, C)]
        self.versus_test(opponent=axelrod.MockPlayer(actions=[C] * 20 + [D, C, C, C]), expected_actions = actions,
                         seed=2)
Exemple #8
0
 def test_strategy(self):
     # Will punish sequence of 2 defections but will forgive one
     opponent = axelrod.MockPlayer(actions=[D, D, D, C, C])
     actions = [(C, D), (C, D), (D, D), (D, C), (C, C), (C, D)]
     self.versus_test(opponent, expected_actions=actions)
     opponent = axelrod.MockPlayer(
         actions=[C, C, D, D, C, D, D, C, C, D, D])
     actions = [
         (C, C),
         (C, C),
         (C, D),
         (C, D),
         (D, C),
         (C, D),
         (C, D),
         (D, C),
         (C, C),
         (C, D),
         (C, D),
     ]
     self.versus_test(opponent, expected_actions=actions)
Exemple #9
0
    def test_thresholds(self):
        init_kwargs = {'grumpy_threshold': 3, 'nice_threshold': -2}
        opponent_actions = [D] * 4 + [C] * 7 + [D] * 3
        opponent = axl.MockPlayer(actions=opponent_actions)
        actions = ([(C, D)] * 4 + [(D, C)] * 7 + [(C, D)] * 3) * 3
        self.versus_test(opponent, expected_actions=actions,
                         init_kwargs=init_kwargs)

        init_kwargs = {'grumpy_threshold': 0, 'nice_threshold': -2}
        opponent_actions = [D] * 1 + [C] * 4 + [D] * 3
        opponent = axl.MockPlayer(actions=opponent_actions)
        actions = ([(C, D)] * 1 + [(D, C)] * 4 + [(C, D)] * 3) * 3
        self.versus_test(opponent, expected_actions=actions,
                         init_kwargs=init_kwargs)

        init_kwargs = {'grumpy_threshold': 3, 'nice_threshold': 0}
        opponent_actions = [D] * 4 + [C] * 5 + [D] * 1
        opponent = axl.MockPlayer(actions=opponent_actions)
        actions = ([(C, D)] * 4 + [(D, C)] * 5 + [(C, D)] * 1) * 3
        self.versus_test(opponent, expected_actions=actions,
                         init_kwargs=init_kwargs)
Exemple #10
0
    def test_strategy(self):
        """Test that strategy is randomly picked (not affected by history)."""
        opponent = axelrod.MockPlayer()
        actions = [(C, C), (D, C), (D, C), (C, C)]
        self.versus_test(opponent, expected_actions=actions, seed=1)

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

        opponent = axelrod.MockPlayer()
        actions = [(D, C), (D, C), (D, C)]
        self.versus_test(opponent,
                         expected_actions=actions,
                         init_kwargs={"p": 0})

        opponent = axelrod.MockPlayer()
        actions = [(C, C), (C, C), (C, C)]
        self.versus_test(opponent,
                         expected_actions=actions,
                         init_kwargs={"p": 1})
Exemple #11
0
    def test_strategy(self):
        actions = [(C, C)] * 3 + [(D, C)]
        self.versus_test(opponent=axl.Cooperator(), expected_actions=actions)

        # wish_score < current_average_score < very_good_score
        actions = [(C, C)] * 7 + [(C, D), (C, D), (C, C), (C, C), (D, C)]
        self.versus_test(opponent=axl.MockPlayer(actions=[C] * 7 + [D] * 2),
                         expected_actions=actions)

        actions = [(C, C)] * 7 + [(C, D), (C, C), (D, C)]
        self.versus_test(opponent=axl.MockPlayer(actions=[C] * 7 + [D]),
                         expected_actions=actions)

        # current_average_score > 2
        actions = [(C, C)] * 9 + [(D, C)]
        self.versus_test(axl.Cooperator(), expected_actions=actions)

        # 1 < current_average_score < 2
        actions = [(C, C)] * 7 + [(C, D)] * 4 + [(D, D)]
        self.versus_test(opponent=axl.MockPlayer(actions=[C] * 7 + [D] * 5),
                         expected_actions=actions)
Exemple #12
0
    def test_strategy(self):
        # If opponent has never defected, co-operate
        opponent = axl.Cooperator()
        actions = [(C, C)] * 5
        self.versus_test(opponent=opponent,
                         expected_actions=actions,
                         attrs={"retaliating": False})

        # Retaliate after a (C, D) round.
        opponent = axl.MockPlayer([C, C, C, D, C])
        actions = [(C, C), (C, C), (C, C), (C, D), (D, C), (D, C)]
        self.versus_test(opponent=opponent,
                         expected_actions=actions,
                         attrs={"retaliating": True})

        opponent = axl.Alternator()

        # Count retaliations
        actions = [(C, C), (C, D), (D, C), (D, D), (D, C)]
        self.versus_test(opponent=opponent,
                         expected_actions=actions,
                         attrs={"retaliation_count": 3})
        opponent = axl.Alternator()

        # Cooperate if we hit the retaliation limit
        actions = [(C, C), (C, D), (D, C), (D, D), (C, C)]
        self.versus_test(
            opponent=opponent,
            expected_actions=actions,
            attrs={"retaliation_count": 0},
            init_kwargs={"retaliation_limit": 2},
        )

        # Defect again after cooperating
        actions = [(C, C), (C, D), (D, C), (D, D), (C, C), (D, D), (D, C)]
        self.versus_test(
            opponent=opponent,
            expected_actions=actions,
            attrs={"retaliation_count": 2},
            init_kwargs={"retaliation_limit": 2},
        )

        # Different behaviour with different retaliation threshold
        actions = [(C, C), (C, D), (D, C), (C, D), (C, C), (C, D), (C, C)]
        self.versus_test(
            opponent=opponent,
            expected_actions=actions,
            attrs={"retaliation_count": 0},
            init_kwargs={
                "retaliation_limit": 2,
                "retaliation_threshold": 9
            },
        )
Exemple #13
0
    def test_memory_depth_infinite_soft_is_false(self):
        init_kwargs = {}
        if self.default_soft:
            init_kwargs["soft"] = False

        opponent_actions = [C] * 50 + [D] * 100 + [C] * 52
        actions = ([(D, C)] + [(C, C)] * 49 + [(C, D)] * 50 + [(D, D)] * 50 +
                   [(D, C)] * 51 + [(C, C)])
        opponent = axl.MockPlayer(actions=opponent_actions)
        self.versus_test(opponent,
                         expected_actions=actions,
                         init_kwargs=init_kwargs)
Exemple #14
0
    def test_reverts_to_cooperator_if_defections_become_le_ten_percent(self):
        four_defections = [D, D, D, D]
        first_four = [(C, D)] + [(D, D)] * 3
        defections_at_ten_pct = four_defections + [C] * 36
        tft = first_four + [(D, C)] + [(C, C)] * 35

        maintain_ten_pct = defections_at_ten_pct + ([C] * 9 + [D]) * 3
        now_cooperates = tft + ([(C, C)] * 9 + [(C, D)]) * 3
        self.versus_test(
            axelrod.MockPlayer(actions=maintain_ten_pct),
            expected_actions=now_cooperates,
        )
Exemple #15
0
    def test_vs_DCDDC(self):
        opponent_actions = [D, C, D, D, C]

        seed = 1
        expected = [(C, D), (C, C), (D, D), (D, D), (C, C), (D, D), (D, C),
                    (C, D), (C, D)]
        self.versus_test(axelrod.MockPlayer(opponent_actions),
                         expected_actions=expected,
                         seed=seed)

        new_seed = 3
        expected[8] = (D, D)
        self.versus_test(axelrod.MockPlayer(opponent_actions),
                         expected_actions=expected,
                         seed=new_seed)

        new_seed = 2
        new_expected = expected[:6] + [(C, C), (D, D), (D, D)]
        self.versus_test(axelrod.MockPlayer(opponent_actions),
                         expected_actions=new_expected,
                         seed=new_seed)
Exemple #16
0
    def test_strategy(self):
        """If opponent defects at any point then the player will defect
        forever."""
        # Become grudged if the opponent defects twice in a row
        opponent = axelrod.MockPlayer([C, C, C, D])
        actions = [(C, C), (C, C), (C, C), (C, D), (C, C)]
        self.versus_test(
            opponent=opponent,
            expected_actions=actions,
            attrs={"grudged": False, "grudge_memory": 0},
        )

        opponent = axelrod.MockPlayer([C, C, C, D, D, D])
        actions = [
            (C, C),
            (C, C),
            (C, C),
            (C, D),
            (C, D),
            (D, D),
            (D, C),
            (D, C),
            (D, C),
            (D, D),
            (D, D),
        ]
        self.versus_test(
            opponent=opponent,
            expected_actions=actions,
            attrs={"grudged": True, "grudge_memory": 5},
        )

        # After 10 rounds of being grudged: forgives
        opponent = axelrod.MockPlayer([C, D, D, C] + [C] * 10)
        actions = [(C, C), (C, D), (C, D), (D, C)] + [(D, C)] * 10 + [(C, C)]
        self.versus_test(
            opponent=opponent,
            expected_actions=actions,
            attrs={"grudged": False, "grudge_memory": 0},
        )
Exemple #17
0
    def test_strategy(self):
        opponent = axelrod.Alternator()
        actions = [(C, C), (C, D), (D, C)]
        self.versus_test(opponent=opponent,
                         expected_actions=actions,
                         attrs={
                             "grudged": True,
                             "grudge_memory": 0
                         })

        opponent = axelrod.MockPlayer([C, D] + [C] * 10)
        actions = [(C, C), (C, D)] + [(D, C)] * 11
        self.versus_test(opponent=opponent,
                         expected_actions=actions,
                         attrs={
                             "grudged": True,
                             "grudge_memory": 10
                         })

        # Eventually the grudge is dropped
        opponent = axelrod.MockPlayer([C, D] + [C] * 10)
        actions = [(C, C), (C, D)] + [(D, C)] * 11 + [(C, D)]
        self.versus_test(opponent=opponent,
                         expected_actions=actions,
                         attrs={
                             "grudged": False,
                             "grudge_memory": 0,
                             "mem_length": 10
                         })

        # Grudged again on opponent's D
        opponent = axelrod.MockPlayer([C, D] + [C] * 11)
        actions = [(C, C), (C, D)] + [(D, C)] * 11 + [(C, C), (C, D), (D, C)]
        self.versus_test(opponent=opponent,
                         expected_actions=actions,
                         attrs={
                             "grudged": True,
                             "grudge_memory": 0,
                             "mem_length": 17
                         })
Exemple #18
0
    def test_strategy(self):
        # Tests that if opponent has played all C then player chooses C.
        actions = [(C, C)] * 10
        self.versus_test(axelrod.Cooperator(),
                         expected_actions=actions,
                         seed=1)
        actions = [(D, C)] + [(C, C)] * 9
        self.versus_test(axelrod.Cooperator(),
                         expected_actions=actions,
                         seed=2)

        # Tests that if opponent has played all D then player chooses D.
        actions = [(C, D)] + [(D, D)] * 9
        self.versus_test(axelrod.Defector(), expected_actions=actions, seed=1)
        actions = [(D, D)] + [(D, D)] * 9
        self.versus_test(axelrod.Defector(), expected_actions=actions, seed=2)

        # Variable behaviour based on the history and stochastic

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

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

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

        opponent = axelrod.MockPlayer(actions=[C, C, C, D, D, D])
        actions = [(D, C), (C, C), (C, C), (C, D), (D, D), (C, D), (C, C),
                   (D, C), (D, C), (D, D)]
        self.versus_test(opponent, expected_actions=actions, seed=2)
Exemple #19
0
    def test_strategy(self):
        actions = [(C, C)] * 100  # Cooperate forever
        self.versus_test(axelrod.Cooperator(), expected_actions=actions)

        # GK does not great against
        opponent_actions = [C, D, D] * 100
        GK_Foil = axelrod.MockPlayer(actions=opponent_actions)
        actions = [(C, C), (C, D), (D, D)]
        actions += [(D, C), (C, D), (D, D)] * 2
        actions += [(D, C)]
        actions += [(D, D), (D, D), (D, C)] * 20  # Defect here on
        self.versus_test(GK_Foil, expected_actions=actions)

        # Fail on second checkpoint
        opponent_actions = [C] * 10 + [C, D, D] * 100
        Delayed_GK_Foil = axelrod.MockPlayer(actions=opponent_actions)
        actions = [(C, C)] * 10
        actions += [(C, C), (C, D), (D, D)]
        actions += [(D, C), (C, D), (D, D)] * 2
        actions += [(D, C)]
        actions += [(D, D), (D, D), (D, C)] * 20  # Defect here on
        self.versus_test(Delayed_GK_Foil, expected_actions=actions)
Exemple #20
0
    def test_strategy(self):
        actions = [(C, C), (D, D)] + [(C, C), (C, D)] * 10
        self.versus_test(axelrod.Alternator(), expected_actions=actions)

        actions = [(C, C), (D, C)] + [(D, C)] * 20
        self.versus_test(axelrod.Cooperator(), expected_actions=actions)

        opponent = axelrod.MockPlayer([D, C])
        actions = [(C, D), (D, C)] + [(D, D), (D, C)] * 10
        self.versus_test(opponent, expected_actions=actions)

        actions = [(C, D), (D, D)] + [(D, D)] * 20
        self.versus_test(axelrod.Defector(), expected_actions=actions)
    def test_edge_case_calculator_sees_cycles_of_size_ten(self):
        seed = 3
        ten_length_cycle = [C, D, C, C, D, C, C, C, D, C]
        self.assertEqual(detect_cycle((ten_length_cycle * 2)),
                         tuple(ten_length_cycle))

        ten_cycle_twenty_rounds = get_joss_strategy_actions(
            ten_length_cycle * 2, indices_to_flip=[16])
        opponent_actions = ten_length_cycle * 2 + [C, D, C]
        expected = ten_cycle_twenty_rounds + [(D, C), (D, D), (D, C)]
        self.versus_test(axelrod.MockPlayer(opponent_actions),
                         expected,
                         seed=seed)
Exemple #22
0
    def test_strategy(self):

        # Starts by cooperating for the first ten moves.
        actions = [(C, C)] * 10
        self.versus_test(axl.Cooperator(), expected_actions=actions)

        actions = [(C, D)] * 10
        self.versus_test(axl.Defector(), expected_actions=actions)

        # Cooperate if in the last ten moves, Cooperations - Defections >= 3
        actions = [(C, C)] * 11 + [(C, D)] * 4
        self.versus_test(
            opponent=axl.MockPlayer(actions=[C] * 11 + [D] * 4),
            expected_actions=actions,
        )

        # Defect if in the last ten moves, Defections - Cooperations >= 3
        actions = [(C, D)] * 11 + [(D, C)] * 4
        self.versus_test(
            opponent=axl.MockPlayer(actions=[D] * 11 + [C] * 4),
            expected_actions=actions,
        )

        # If neither of the above conditions are met, apply TitForTat
        actions = [(C, D)] * 5 + [(C, C)] * 6 + [(C, D), (D, D), (D, D),
                                                 (D, C), (C, C)]
        self.versus_test(
            opponent=axl.MockPlayer(actions=[D] * 5 + [C] * 6 +
                                    [D, D, D, C, C]),
            expected_actions=actions,
        )

        actions = [(C, C)] * 5 + [(C, D)] * 6 + [(D, C), (C, C), (C, C),
                                                 (C, D), (D, D)]
        self.versus_test(
            opponent=axl.MockPlayer(actions=[C] * 5 + [D] * 6 +
                                    [C, C, C, D, D]),
            expected_actions=actions,
        )
Exemple #23
0
    def test_strategy(self):
        # If handshake (C, D) is used cooperate until a defection occurs and
        # then defect throughout
        opponent = axl.MockPlayer([C, D] + [C] * 10)
        actions = [(C, C), (D, D)] + [(C, C)] * 11 + [(C, D)] + [(D, C)] * 10
        self.versus_test(opponent=opponent, expected_actions=actions)

        # If handshake is not used: defect
        actions = [(C, C), (D, C)] + [(D, C)] * 15
        self.versus_test(opponent=axl.Cooperator(), expected_actions=actions)

        actions = [(C, D), (D, D)] + [(D, D)] * 15
        self.versus_test(opponent=axl.Defector(), expected_actions=actions)
Exemple #24
0
    def test_memory_depth_even_soft_is_false(self):
        memory_depth = 4
        init_kwargs = {"memory_depth": memory_depth}
        if self.default_soft:
            init_kwargs["soft"] = False

        opponent = axl.MockPlayer(actions=[C] * memory_depth +
                                  [D] * memory_depth)
        actions = ([(D, C)] + [(C, C)] * 3 + [(C, D)] * 2 + [(D, D)] * 2 +
                   [(D, C)] * 3 + [(C, C)])
        self.versus_test(opponent,
                         expected_actions=actions,
                         init_kwargs=init_kwargs)
Exemple #25
0
    def test_strategy(self):
        # Starts by playing DCC.
        # Cooperates forever if opponent played D, C in moves 2 and 3
        actions = [(D, C), (C, D), (C, C)] + [(C, D), (C, C), (C, D)]
        self.versus_test(opponent=axelrod.Alternator(),
                         expected_actions=actions)

        opponent = axelrod.MockPlayer([D, D, C])
        actions = [(D, D), (C, D), (C, C)] + [(C, D), (C, D), (C, C)]
        self.versus_test(opponent=opponent, expected_actions=actions)

        # Otherwise it plays like TFT
        actions = [(D, C), (C, C), (C, C), (C, C), (C, C)]
        self.versus_test(opponent=axelrod.Cooperator(),
                         expected_actions=actions)

        actions = [(D, D), (C, D), (C, D), (D, D), (D, D)]
        self.versus_test(opponent=axelrod.Defector(), expected_actions=actions)

        opponent = axelrod.MockPlayer([D, C])
        actions = [(D, D), (C, C), (C, D)] + [(D, C), (C, D), (D, C)]
        self.versus_test(opponent=opponent, expected_actions=actions)
Exemple #26
0
    def test_strategy(self):
        # Starts by cooperating.
        self.first_play_test(C)

        actions = [(C, C), (D, C)] * 5
        self.versus_test(axelrod.Cooperator(), expected_actions=actions)

        actions = [(C, D), (D, D)] * 5
        self.versus_test(axelrod.Defector(), expected_actions=actions)

        opponent = axelrod.MockPlayer([D, C])
        actions = [(C, D), (D, C)] * 5
        self.versus_test(opponent, expected_actions=actions)
Exemple #27
0
    def test_strategy(self):
        # Starts by playing CCDCDDDCCDCDCCDCDDCD.
        # After playing the initial sequence defects forever
        # if the absolute difference in the number of retaliating
        # and provocative defections of the opponent is smaller or equal to 2
        provocative_histories = [
            [C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C],
            [C, D, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C],
            [C, D, C, D, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C],
            [C, C, D, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C],
            [C, C, D, C, D, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C],
            [D, D, D, D, D, D, D, D, D, D, D, D, D, D, D, D, D, D, D, D],
        ]

        attrs = {'turned_defector': True}
        for history in provocative_histories:
            opponent = axelrod.MockPlayer(history + [C] * 5)
            actions = list(zip(self.initial_sequence, history)) + [(D, C)] * 5
            self.versus_test(opponent=opponent,
                             expected_actions=actions,
                             attrs=attrs)

        # Otherwise cooperates for 5 rounds and plays TfT afterwards
        unprovocative_histories = [
            [C, C, D, C, D, D, D, C, C, D, C, D, C, C, D, C, D, D, C, D],
            [D, D, C, D, C, C, C, D, D, C, D, C, D, D, C, D, C, C, D, C],
            [C, C, D, C, D, D, C, C, C, C, C, C, C, C, C, C, C, C, C, C],
            [C, C, D, C, D, D, C, C, D, C, C, C, C, C, C, D, D, D, C, C],
            [C, C, C, C, D, D, C, C, D, C, C, D, D, C, D, C, D, C, C, C],
        ]

        attrs = {'turned_defector': False}
        for history in unprovocative_histories:
            opponent = axelrod.MockPlayer(history + [D] * 5 + [C, C])
            actions = list(zip(self.initial_sequence, history)) + [(C, D)] * 5
            actions += [(D, C), (C, C)]
            self.versus_test(opponent=opponent,
                             expected_actions=actions,
                             attrs=attrs)
Exemple #28
0
    def test_strategy(self):
        """Test strategy with multiple initial parameters"""

        # Testing default parameters of n=1, d=4, c=2 (same as Soft Grudger)
        actions = [(C, D), (D, D), (D, C), (D, C), (D, D), (C, D),
                   (C, C), (C, C)]
        self.versus_test(axl.MockPlayer(actions=[D, D, C, C]),
                         expected_actions=actions)

        # Testing n=2, d=4, c=2
        actions = [(C, D), (C, D), (D, C), (D, C), (D, D), (D, D),
                   (C, C), (C, C)]
        self.versus_test(axl.MockPlayer(actions=[D, D, C, C]),
                         expected_actions=actions,
                         init_kwargs={"n": 2})

        # Testing n=1, d=1, c=1
        actions = [(C, D), (D, D), (C, C), (C, C), (C, D), (D, D),
                   (C, C), (C, C)]
        self.versus_test(axl.MockPlayer(actions=[D, D, C, C]),
                         expected_actions=actions,
                         init_kwargs={"n": 1, "d": 1, "c": 1})
    def test_strategy(self):
        actions = [(C, C), (C, C), (C, C)]
        self.versus_test(axelrod.Cooperator(), expected_actions=actions)

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

        opponent = axelrod.MockPlayer(actions=[D, C, C])
        actions = [(C, D), (C, C), (C, C), (C, D)]
        self.versus_test(opponent, expected_actions=actions)

        opponent = axelrod.MockPlayer(actions=[D, D, C])
        actions = [(C, D), (C, D), (D, C), (D, D)]
        self.versus_test(opponent, expected_actions=actions)

        opponent = axelrod.MockPlayer(actions=[C, C, D, D, C, C])
        actions = [(C, C), (C, C), (C, D), (C, D), (D, C), (D, C), (D, C)]
        self.versus_test(opponent, expected_actions=actions)

        opponent = axelrod.MockPlayer(actions=[C, C, C, C, D, D])
        actions = [(C, C), (C, C), (C, C), (C, C), (C, D), (C, D), (C, C)]
        self.versus_test(opponent, expected_actions=actions)
Exemple #30
0
 def test_strategy(self):
     """
     Regression test for init without specifying initial state or action
     """
     transitions = ((0, C, 0, C), (0, D, 3, C), (1, C, 5, D), (1, D, 0, C),
                    (2, C, 3, C), (2, D, 2, D), (3, C, 4, D), (3, D, 6, D),
                    (4, C, 3, C), (4, D, 1, D), (5, C, 6, C), (5, D, 3, D),
                    (6, C, 6, D), (6, D, 6, D), (7, C, 7, D), (7, D, 5, C))
     opponent = axelrod.MockPlayer([D, D, C, C, D])
     actions = [(C, D), (C, D), (C, C), (D, C), (C, D)]
     self.versus_test(opponent,
                      expected_actions=actions,
                      init_kwargs={"transitions": transitions})