@@ -149,36 +149,86 @@ class TestGraaskamp(TestPlayer):
149
149
name = "Graaskamp: 0.05"
150
150
player = axelrod .Graaskamp
151
151
expected_classifier = {
152
- ' memory_depth' : float ("inf" ),
153
- ' stochastic' : True ,
154
- ' makes_use_of' : set (),
155
- ' inspects_source' : False ,
156
- ' manipulates_source' : False ,
157
- ' manipulates_state' : False
152
+ " memory_depth" : float ("inf" ),
153
+ " stochastic" : True ,
154
+ " makes_use_of" : set (),
155
+ " inspects_source" : False ,
156
+ " manipulates_source" : False ,
157
+ " manipulates_state" : False ,
158
158
}
159
159
160
160
def test_strategy (self ):
161
- # Play against opponents
162
- actions = [(C , D ), (D , C ), (C , C ), (C , C ), (C , D ), (D , D )]
163
- self .versus_test (axelrod .Random (), expected_actions = actions , seed = 0 )
161
+ # Test TfT in first 50 rounds followed by defection followed by 5 rounds
162
+ # of TfT
163
+ expected_attrs = {
164
+ "opponent_is_random" : False ,
165
+ "next_random_defection_turn" : None ,
166
+ }
167
+
168
+ # Against alternator
169
+ actions = [(C , C )] + [(C , D ), (D , C )] * 24 + [(C , D )] # 50 turns
170
+ actions += [(D , C )] # 51 turns
171
+ actions += [(C , D ), (D , C )] * 2 + [(C , D )] # 56 turns
172
+ self .versus_test (
173
+ axelrod .Alternator (), expected_actions = actions , attrs = expected_attrs
174
+ )
164
175
165
- actions = [(C , C ), (C , C ), (C , D ), (D , C ), (C , D ), (D , D )]
166
- self .versus_test (axelrod .Random (), expected_actions = actions , seed = 1 )
176
+ # Against defector
177
+ actions = [(C , D )] + [(D , D )] * 55 # 56 turns
178
+ self .versus_test (
179
+ axelrod .Defector (), expected_actions = actions , attrs = expected_attrs
180
+ )
167
181
168
- actions = [(C , C ), (C , D ), (D , C ), (C , D ), (D , C )]
169
- self .versus_test (axelrod .Alternator (), expected_actions = actions )
182
+ # Against cooperator
183
+ actions = [(C , C )] * 50 + [(D , C )] + [(C , C )] * 5
184
+ self .versus_test (
185
+ axelrod .Cooperator (), expected_actions = actions , attrs = expected_attrs
186
+ )
170
187
171
- actions = [(C , C ) * 50 , (D , C ), (C , C ) * 5 ]
172
- self .versus_test (axelrod .Cooperator (), expected_actions = actions )
188
+ # Test recognition of random player
173
189
174
- actions = [(C , D ), (D , D ) * 49 , (D , D ) * 6 ]
175
- self .versus_test (axelrod .Defector (), expected_actions = actions )
190
+ expected_attrs = {
191
+ "opponent_is_random" : False ,
192
+ "next_random_defection_turn" : None ,
193
+ }
194
+ actions = [(C , C )] * 50 + [(D , C )] + [(C , C )] * 5 # 56 turns
195
+ self .versus_test (
196
+ axelrod .Cooperator (), expected_actions = actions , attrs = expected_attrs
197
+ )
198
+ expected_attrs = {"opponent_is_random" : False , "next_random_defection_turn" : 68 }
199
+ actions += [(C , C )] # 57 turns
200
+ self .versus_test (
201
+ axelrod .Cooperator (), expected_actions = actions , attrs = expected_attrs
202
+ )
203
+
204
+ expected_attrs = {
205
+ "opponent_is_random" : True ,
206
+ "next_random_defection_turn" : None ,
207
+ }
208
+ actions = [(C , C )] + [(C , D ), (D , C )] * 24 + [(C , D )] # 50 turns
209
+ actions += [(D , C )] # 51 turns
210
+ actions += [(C , D ), (D , C )] * 3 # 57 turns
211
+ actions += [(D , D )]
212
+ self .versus_test (
213
+ axelrod .Alternator (), expected_actions = actions , attrs = expected_attrs
214
+ )
215
+ actions += [(D , C ), (D , D )] * 5
216
+ self .versus_test (
217
+ axelrod .Alternator (), expected_actions = actions , attrs = expected_attrs
218
+ )
176
219
177
- actions = [(C , C ) * 50 , (D , C ), (C , C ) * 5 ]
178
- self .versus_test (axelrod .Grumpy (), expected_actions = actions )
220
+ # Test random defections
221
+ expected_attrs = {"opponent_is_random" : False , "next_random_defection_turn" : 78 }
222
+ actions = [(C , C )] * 50 + [(D , C )] + [(C , C )] * 16 + [(D , C )] + [(C , C )]
223
+ self .versus_test (
224
+ axelrod .Cooperator (), expected_actions = actions , seed = 0 , attrs = expected_attrs
225
+ )
179
226
180
- actions = [(C , C ) * 50 , (D , C ), (C , D ) * 5 ]
181
- self .versus_test (axelrod .Grudger (), expected_actions = actions )
227
+ expected_attrs = {"opponent_is_random" : False , "next_random_defection_turn" : 77 }
228
+ actions = [(C , C )] * 50 + [(D , C )] + [(C , C )] * 12 + [(D , C )] + [(C , C )]
229
+ self .versus_test (
230
+ axelrod .Cooperator (), expected_actions = actions , seed = 1 , attrs = expected_attrs
231
+ )
182
232
183
233
184
234
class TestGrofman (TestPlayer ):
0 commit comments