1
1
"""Tests for the Gradual Killer strategy."""
2
2
3
- import axelrod
3
+ import axelrod as axl
4
4
from .test_player import TestPlayer
5
5
6
- C , D = axelrod .Actions .C , axelrod .Actions .D
6
+ C , D = axl .Actions .C , axl .Actions .D
7
7
8
8
9
9
class TestGradualKiller (TestPlayer ):
10
10
11
11
name = "Gradual Killer: ('D', 'D', 'D', 'D', 'D', 'C', 'C')"
12
- player = axelrod .GradualKiller
12
+ player = axl .GradualKiller
13
13
expected_classifier = {
14
14
'memory_depth' : float ('Inf' ),
15
15
'stochastic' : False ,
@@ -19,78 +19,57 @@ class TestGradualKiller(TestPlayer):
19
19
'manipulates_state' : False
20
20
}
21
21
22
- def test_strategy (self ):
23
- # Starts by defecting.
24
- self .first_play_test (D )
25
- self .second_play_test (D , D , D , D )
26
- # First seven moves.
27
- self .responses_test ([D , D , D , D , D , C , C ])
22
+ first_seven = [D , D , D , D , D , C , C ]
23
+
24
+ def test_first_seven_moves_always_the_same (self ):
25
+ opponent = axl .Cooperator ()
26
+ actions = list (zip (self .first_seven , [C ] * 7 ))
27
+ self .versus_test (opponent , expected_actions = actions )
28
+
29
+ opponent = axl .Defector ()
30
+ actions = list (zip (self .first_seven , [D ] * 7 ))
31
+ self .versus_test (opponent , expected_actions = actions )
32
+
33
+ opponent = axl .Alternator ()
34
+ actions = list (zip (self .first_seven , [C , D ] * 4 ))
35
+ self .versus_test (opponent , expected_actions = actions )
28
36
29
37
def test_effect_of_strategy_with_history_CC (self ):
30
38
"""Continues with C if opponent played CC on 6 and 7."""
31
- P1 = axelrod .GradualKiller ()
32
- P2 = axelrod .Player ()
33
- P1 .history = [D , D , D , D , D , C , C ]
34
- P2 .history = [C , C , C , C , C , C , C ]
35
- self .assertEqual (P1 .strategy (P2 ), 'C' )
36
- P1 .history = [D , D , D , D , D , C , C , C ]
37
- P2 .history = [C , C , C , C , C , C , C , C ]
38
- self .assertEqual (P1 .strategy (P2 ), 'C' )
39
- P1 .history = [D , D , D , D , D , C , C , C , C ]
40
- P2 .history = [C , C , C , C , C , C , C , C , C ]
41
- self .assertEqual (P1 .strategy (P2 ), 'C' )
42
- P1 .history = [D , D , D , D , D , C , C , C , C , C ]
43
- P2 .history = [C , C , C , C , C , C , C , C , C , C ]
44
- self .assertEqual (P1 .strategy (P2 ), 'C' )
39
+ opponent_actions = [D ] * 5 + [C , C ] + [D , C ] * 20
40
+ opponent = axl .MockPlayer (actions = opponent_actions )
41
+
42
+ start = list (zip (self .first_seven , opponent_actions [:7 ]))
43
+ actions = start + [(C , D ), (C , C )] * 20
44
+
45
+ self .versus_test (opponent , expected_actions = actions )
45
46
46
47
def test_effect_of_strategy_with_history_CD (self ):
47
48
"""Continues with C if opponent played CD on 6 and 7."""
48
- P1 = axelrod .GradualKiller ()
49
- P2 = axelrod .Player ()
50
- P1 .history = [D , D , D , D , D , C , C ]
51
- P2 .history = [C , C , C , C , C , C , D ]
52
- self .assertEqual (P1 .strategy (P2 ), 'C' )
53
- P1 .history = [D , D , D , D , D , C , C , C ]
54
- P2 .history = [C , C , C , C , C , C , D , D ]
55
- self .assertEqual (P1 .strategy (P2 ), 'C' )
56
- P1 .history = [D , D , D , D , D , C , C , C , C ]
57
- P2 .history = [C , C , C , C , C , C , D , D , C ]
58
- self .assertEqual (P1 .strategy (P2 ), 'C' )
59
- P1 .history = [D , D , D , D , D , C , C , C , C , C ]
60
- P2 .history = [C , C , C , C , C , C , D , D , C , C ]
61
- self .assertEqual (P1 .strategy (P2 ), 'C' )
49
+ opponent_actions = [D ] * 5 + [C , D ] + [D , C ] * 20
50
+ opponent = axl .MockPlayer (actions = opponent_actions )
51
+
52
+ start = list (zip (self .first_seven , opponent_actions [:7 ]))
53
+ actions = start + [(C , D ), (C , C )] * 20
54
+
55
+ self .versus_test (opponent , expected_actions = actions )
62
56
63
57
def test_effect_of_strategy_with_history_DC (self ):
64
58
"""Continues with C if opponent played DC on 6 and 7."""
65
- P1 = axelrod .GradualKiller ()
66
- P2 = axelrod .Player ()
67
- P1 .history = [D , D , D , D , D , C , C ]
68
- P2 .history = [C , C , C , C , C , D , C ]
69
- self .assertEqual (P1 .strategy (P2 ), 'C' )
70
- P1 .history = [D , D , D , D , D , C , C , C ]
71
- P2 .history = [C , C , C , C , C , D , C , C ]
72
- self .assertEqual (P1 .strategy (P2 ), 'C' )
73
- P1 .history = [D , D , D , D , D , C , C , C , C ]
74
- P2 .history = [C , C , C , C , C , D , C , C , D ]
75
- self .assertEqual (P1 .strategy (P2 ), 'C' )
76
- P1 .history = [D , D , D , D , D , C , C , C , C , C ]
77
- P2 .history = [C , C , C , C , C , D , C , C , D , C ]
78
- self .assertEqual (P1 .strategy (P2 ), 'C' )
59
+ opponent_actions = [D ] * 5 + [D , C ] + [D , C ] * 20
60
+ opponent = axl .MockPlayer (actions = opponent_actions )
61
+
62
+ start = list (zip (self .first_seven , opponent_actions [:7 ]))
63
+ actions = start + [(C , D ), (C , C )] * 20
64
+
65
+ self .versus_test (opponent , expected_actions = actions )
79
66
80
67
def test_effect_of_strategy_with_history_DD (self ):
81
68
"""Continues with D if opponent played DD on 6 and 7."""
82
- P1 = axelrod .GradualKiller ()
83
- P2 = axelrod .Player ()
84
- P1 .history = [D , D , D , D , D , C , C ]
85
- P2 .history = [C , C , C , C , C , D , D ]
86
- self .assertEqual (P1 .strategy (P2 ), 'D' )
87
- P1 .history = [D , D , D , D , D , C , C , D ]
88
- P2 .history = [C , C , C , C , C , D , D , C ]
89
- self .assertEqual (P1 .strategy (P2 ), 'D' )
90
- P1 .history = [D , D , D , D , D , C , C , D , D ]
91
- P2 .history = [C , C , C , C , C , D , D , C , C ]
92
- self .assertEqual (P1 .strategy (P2 ), 'D' )
93
- P1 .history = [D , D , D , D , D , C , C , D , D , D ]
94
- P2 .history = [C , C , C , C , C , D , D , C , C , D ]
95
- self .assertEqual (P1 .strategy (P2 ), 'D' )
69
+ opponent_actions = [C ] * 5 + [D , D ] + [D , C ] * 20
70
+ opponent = axl .MockPlayer (actions = opponent_actions )
71
+
72
+ start = list (zip (self .first_seven , opponent_actions [:7 ]))
73
+ actions = start + [(D , D ), (D , C )] * 20
96
74
75
+ self .versus_test (opponent , expected_actions = actions )
0 commit comments