@@ -33,7 +33,7 @@ class Champion(Player):
33
33
classifier = {
34
34
'memory_depth' : float ('inf' ),
35
35
'stochastic' : True ,
36
- 'makes_use_of' : set ([ "length" ] ),
36
+ 'makes_use_of' : set (),
37
37
'long_run_time' : False ,
38
38
'inspects_source' : False ,
39
39
'manipulates_source' : False ,
@@ -42,14 +42,13 @@ class Champion(Player):
42
42
43
43
def strategy (self , opponent : Player ) -> Action :
44
44
current_round = len (self .history )
45
- expected_length = self .match_attributes ['length' ]
46
- # Cooperate for the first 1/20-th of the game
45
+ # Cooperate for the first 10 turns
47
46
if current_round == 0 :
48
47
return C
49
- if current_round < expected_length / 20 :
48
+ if current_round < 10 :
50
49
return C
51
50
# Mirror partner for the next phase
52
- if current_round < expected_length * 5 / 40 :
51
+ if current_round < 25 :
53
52
return opponent .history [- 1 ]
54
53
# Now cooperate unless all of the necessary conditions are true
55
54
defection_prop = opponent .defections / len (opponent .history )
@@ -204,22 +203,22 @@ def strategy(self, opponent: Player) -> Action:
204
203
return opponent .history [- 1 ]
205
204
206
205
class Tranquilizer (Player ):
207
-
206
+
208
207
"""
209
208
Submitted to Axelrod's second tournament by Craig Feathers
210
209
211
- Description given in Axelrod's "More Effective Choice in the
212
- Prisoner's Dilemma" paper: The rule normally cooperates but
213
- is ready to defect if the other player defects too often.
210
+ Description given in Axelrod's "More Effective Choice in the
211
+ Prisoner's Dilemma" paper: The rule normally cooperates but
212
+ is ready to defect if the other player defects too often.
214
213
Thus the rule tends to cooperate for the first dozen or two moves
215
- if the other player is cooperating, but then it throws in a
216
- defection. If the other player continues to cooperate, then defections
217
- become more frequent. But as long as Tranquilizer is maintaining an
218
- average payoff of at least 2.25 points per move, it will never defect
219
- twice in succession and it will not defect more than
214
+ if the other player is cooperating, but then it throws in a
215
+ defection. If the other player continues to cooperate, then defections
216
+ become more frequent. But as long as Tranquilizer is maintaining an
217
+ average payoff of at least 2.25 points per move, it will never defect
218
+ twice in succession and it will not defect more than
220
219
one-quarter of the time.
221
220
222
- This implementation is based on the reverse engineering of the
221
+ This implementation is based on the reverse engineering of the
223
222
Fortran strategy K67R from Axelrod's second tournament.
224
223
Reversed engineered by: Owen Campbell, Will Guo and Mansour Hakem.
225
224
@@ -228,87 +227,87 @@ class Tranquilizer(Player):
228
227
At the start of the strategy it updates its states:
229
228
230
229
- It counts the number of consecutive defections by the opponent.
231
- - If it was in state 2 it moves to state 0 and calculates the
230
+ - If it was in state 2 it moves to state 0 and calculates the
232
231
following quantities two_turns_after_good_defection_ratio and
233
232
two_turns_after_good_defection_ratio_count.
234
-
233
+
235
234
Formula for:
236
-
235
+
237
236
two_turns_after_good_defection_ratio:
238
237
239
238
self.two_turns_after_good_defection_ratio = (
240
- ((self.two_turns_after_good_defection_ratio
241
- * self.two_turns_after_good_defection_ratio_count)
242
- + (3 - (3 * self.dict[opponent.history[-1]]))
243
- + (2 * self.dict[self.history[-1]])
244
- - ((self.dict[opponent.history[-1]]
245
- * self.dict[self.history[-1]])))
239
+ ((self.two_turns_after_good_defection_ratio
240
+ * self.two_turns_after_good_defection_ratio_count)
241
+ + (3 - (3 * self.dict[opponent.history[-1]]))
242
+ + (2 * self.dict[self.history[-1]])
243
+ - ((self.dict[opponent.history[-1]]
244
+ * self.dict[self.history[-1]])))
246
245
/ (self.two_turns_after_good_defection_ratio_count + 1)
247
246
)
248
247
249
248
two_turns_after_good_defection_ratio_count =
250
249
two_turns_after_good_defection_ratio + 1
251
250
252
- - If it was in state 1 it moves to state 2 and calculates the
253
- following quantities one_turn_after_good_defection_ratio and
251
+ - If it was in state 1 it moves to state 2 and calculates the
252
+ following quantities one_turn_after_good_defection_ratio and
254
253
one_turn_after_good_defection_ratio_count.
255
254
256
255
Formula for:
257
-
256
+
258
257
one_turn_after_good_defection_ratio:
259
258
260
259
self.one_turn_after_good_defection_ratio = (
261
- ((self.one_turn_after_good_defection_ratio
260
+ ((self.one_turn_after_good_defection_ratio
262
261
* self.one_turn_after_good_defection_ratio_count)
263
- + (3 - (3 * self.dict[opponent.history[-1]]))
264
- + (2 * self.dict[self.history[-1]])
265
- - (self.dict[opponent.history[-1]]
266
- * self.dict[self.history[-1]]))
262
+ + (3 - (3 * self.dict[opponent.history[-1]]))
263
+ + (2 * self.dict[self.history[-1]])
264
+ - (self.dict[opponent.history[-1]]
265
+ * self.dict[self.history[-1]]))
267
266
/ (self.one_turn_after_good_defection_ratio_count + 1)
268
267
)
269
268
270
269
one_turn_after_good_defection_ratio_count:
271
270
272
271
one_turn_after_good_defection_ratio_count =
273
272
one_turn_after_good_defection_ratio + 1
274
-
273
+
275
274
If after this it is in state 1 or 2 then it cooperates.
276
275
277
- If it is in state 0 it will potentially perform 1 of the 2
276
+ If it is in state 0 it will potentially perform 1 of the 2
278
277
following stochastic tests:
279
278
280
- 1. If average score per turn is greater than 2.25 then it calculates a
279
+ 1. If average score per turn is greater than 2.25 then it calculates a
281
280
value of probability:
282
-
281
+
283
282
probability = (
284
283
(.95 - (((self.one_turn_after_good_defection_ratio)
285
- + (self.two_turns_after_good_defection_ratio) - 5) / 15))
284
+ + (self.two_turns_after_good_defection_ratio) - 5) / 15))
286
285
+ (1 / (((len(self.history))+1) ** 2))
287
286
- (self.dict[opponent.history[-1]] / 4)
288
- )
287
+ )
289
288
290
- and will cooperate if a random sampled number is less than that value of
291
- probability. If it does not cooperate then the strategy moves to state 1
289
+ and will cooperate if a random sampled number is less than that value of
290
+ probability. If it does not cooperate then the strategy moves to state 1
292
291
and defects.
293
-
294
- 2. If average score per turn is greater than 1.75 but less than 2.25
292
+
293
+ 2. If average score per turn is greater than 1.75 but less than 2.25
295
294
then it calculates a value of probability:
296
295
297
296
probability = (
298
297
(.25 + ((opponent.cooperations + 1) / ((len(self.history)) + 1)))
299
- - (self.opponent_consecutive_defections * .25)
300
- + ((current_score[0]
301
- - current_score[1]) / 100)
298
+ - (self.opponent_consecutive_defections * .25)
299
+ + ((current_score[0]
300
+ - current_score[1]) / 100)
302
301
+ (4 / ((len(self.history)) + 1))
303
302
)
304
303
305
- and will cooperate if a random sampled number is less than that value of
304
+ and will cooperate if a random sampled number is less than that value of
306
305
probability. If not, it defects.
307
306
308
307
If none of the above holds the player simply plays tit for tat.
309
308
310
- Tranquilizer came in 27th place in Axelrod's second torunament.
311
-
309
+ Tranquilizer came in 27th place in Axelrod's second torunament.
310
+
312
311
313
312
Names:
314
313
@@ -335,75 +334,75 @@ def __init__(self):
335
334
self .one_turn_after_good_defection_ratio_count = 1 # equal to AK variable
336
335
self .two_turns_after_good_defection_ratio_count = 1 # equal to NK variable
337
336
# All above variables correspond to those in original Fotran Code
338
- self .dict = {C : 0 , D : 1 }
337
+ self .dict = {C : 0 , D : 1 }
339
338
340
339
341
- def update_state (self , opponent ):
342
-
340
+ def update_state (self , opponent ):
341
+
343
342
"""
344
343
Calculates the ratio values for the one_turn_after_good_defection_ratio,
345
- two_turns_after_good_defection_ratio and the probability values,
344
+ two_turns_after_good_defection_ratio and the probability values,
346
345
and sets the value of num_turns_after_good_defection.
347
346
"""
348
- if opponent .history [- 1 ] == D :
347
+ if opponent .history [- 1 ] == D :
349
348
self .opponent_consecutive_defections += 1
350
349
else :
351
350
self .opponent_consecutive_defections = 0
352
351
353
352
if self .num_turns_after_good_defection == 2 :
354
353
self .num_turns_after_good_defection = 0
355
354
self .two_turns_after_good_defection_ratio = (
356
- ((self .two_turns_after_good_defection_ratio
357
- * self .two_turns_after_good_defection_ratio_count )
358
- + (3 - (3 * self .dict [opponent .history [- 1 ]]))
359
- + (2 * self .dict [self .history [- 1 ]])
360
- - ((self .dict [opponent .history [- 1 ]]
361
- * self .dict [self .history [- 1 ]])))
355
+ ((self .two_turns_after_good_defection_ratio
356
+ * self .two_turns_after_good_defection_ratio_count )
357
+ + (3 - (3 * self .dict [opponent .history [- 1 ]]))
358
+ + (2 * self .dict [self .history [- 1 ]])
359
+ - ((self .dict [opponent .history [- 1 ]]
360
+ * self .dict [self .history [- 1 ]])))
362
361
/ (self .two_turns_after_good_defection_ratio_count + 1 )
363
362
)
364
363
self .two_turns_after_good_defection_ratio_count += 1
365
364
elif self .num_turns_after_good_defection == 1 :
366
365
self .num_turns_after_good_defection = 2
367
366
self .one_turn_after_good_defection_ratio = (
368
- ((self .one_turn_after_good_defection_ratio
367
+ ((self .one_turn_after_good_defection_ratio
369
368
* self .one_turn_after_good_defection_ratio_count )
370
- + (3 - (3 * self .dict [opponent .history [- 1 ]]))
371
- + (2 * self .dict [self .history [- 1 ]])
372
- - (self .dict [opponent .history [- 1 ]]
373
- * self .dict [self .history [- 1 ]]))
369
+ + (3 - (3 * self .dict [opponent .history [- 1 ]]))
370
+ + (2 * self .dict [self .history [- 1 ]])
371
+ - (self .dict [opponent .history [- 1 ]]
372
+ * self .dict [self .history [- 1 ]]))
374
373
/ (self .one_turn_after_good_defection_ratio_count + 1 )
375
374
)
376
375
self .one_turn_after_good_defection_ratio_count += 1
377
-
376
+
378
377
def strategy (self , opponent : Player ) -> Action :
379
378
380
379
if not self .history :
381
380
return C
382
381
383
-
382
+
384
383
self .update_state (opponent )
385
384
if self .num_turns_after_good_defection in [1 , 2 ]:
386
- return C
385
+ return C
387
386
388
387
current_score = compute_final_score (zip (self .history , opponent .history ))
389
388
390
389
if (current_score [0 ] / ((len (self .history )) + 1 )) >= 2.25 :
391
390
probability = (
392
391
(.95 - (((self .one_turn_after_good_defection_ratio )
393
- + (self .two_turns_after_good_defection_ratio ) - 5 ) / 15 ))
392
+ + (self .two_turns_after_good_defection_ratio ) - 5 ) / 15 ))
394
393
+ (1 / (((len (self .history ))+ 1 ) ** 2 ))
395
394
- (self .dict [opponent .history [- 1 ]] / 4 )
396
395
)
397
- if random .random () <= probability :
396
+ if random .random () <= probability :
398
397
return C
399
398
self .num_turns_after_good_defection = 1
400
399
return D
401
400
if (current_score [0 ] / ((len (self .history )) + 1 )) >= 1.75 :
402
401
probability = (
403
402
(.25 + ((opponent .cooperations + 1 ) / ((len (self .history )) + 1 )))
404
- - (self .opponent_consecutive_defections * .25 )
405
- + ((current_score [0 ]
406
- - current_score [1 ]) / 100 )
403
+ - (self .opponent_consecutive_defections * .25 )
404
+ + ((current_score [0 ]
405
+ - current_score [1 ]) / 100 )
407
406
+ (4 / ((len (self .history )) + 1 ))
408
407
)
409
408
if random .random () <= probability :
0 commit comments