1
1
import random
2
2
3
+ import numpy as np
4
+ from numpy .random import choice
5
+
3
6
from axelrod .action import Action
7
+ from axelrod .classifier import Classifiers
4
8
from axelrod .player import Player , obey_axelrod
5
9
from axelrod .strategies import TitForTat
6
10
from axelrod .strategy_transformers import NiceTransformer
7
-
8
- import numpy as np
9
- from numpy .random import choice
10
-
11
11
from ._strategies import all_strategies
12
12
from .hunter import (
13
13
AlternatorHunter ,
@@ -69,10 +69,12 @@ def __init__(self, team=None):
69
69
"manipulates_source" ,
70
70
"manipulates_state" ,
71
71
]:
72
- self .classifier [key ] = any (t .classifier [key ] for t in self .team )
72
+ self .classifier [key ] = any (
73
+ Classifiers ().get (key , t ) for t in self .team )
73
74
74
75
for t in self .team :
75
- self .classifier ["makes_use_of" ].update (t .classifier ["makes_use_of" ])
76
+ self .classifier ["makes_use_of" ].update (
77
+ Classifiers ().get ("makes_use_of" , t ))
76
78
77
79
self ._last_results = None
78
80
@@ -332,7 +334,8 @@ class MetaMajorityMemoryOne(MetaMajority):
332
334
name = "Meta Majority Memory One"
333
335
334
336
def __init__ (self ):
335
- team = [s for s in ordinary_strategies if s ().classifier ["memory_depth" ] <= 1 ]
337
+ team = [s for s in ordinary_strategies if
338
+ Classifiers ().get ("memory_depth" , s ) <= 1 ]
336
339
super ().__init__ (team = team )
337
340
self .classifier ["long_run_time" ] = False
338
341
@@ -348,11 +351,8 @@ class MetaMajorityFiniteMemory(MetaMajority):
348
351
name = "Meta Majority Finite Memory"
349
352
350
353
def __init__ (self ):
351
- team = [
352
- s
353
- for s in ordinary_strategies
354
- if s ().classifier ["memory_depth" ] < float ("inf" )
355
- ]
354
+ team = [s for s in ordinary_strategies if
355
+ Classifiers ().get ("memory_depth" , s ) < float ("inf" )]
356
356
super ().__init__ (team = team )
357
357
358
358
@@ -367,11 +367,8 @@ class MetaMajorityLongMemory(MetaMajority):
367
367
name = "Meta Majority Long Memory"
368
368
369
369
def __init__ (self ):
370
- team = [
371
- s
372
- for s in ordinary_strategies
373
- if s ().classifier ["memory_depth" ] == float ("inf" )
374
- ]
370
+ team = [s for s in ordinary_strategies if
371
+ Classifiers ().get ("memory_depth" , s ) == float ("inf" )]
375
372
super ().__init__ (team = team )
376
373
377
374
@@ -386,7 +383,8 @@ class MetaWinnerMemoryOne(MetaWinner):
386
383
name = "Meta Winner Memory One"
387
384
388
385
def __init__ (self ):
389
- team = [s for s in ordinary_strategies if s ().classifier ["memory_depth" ] <= 1 ]
386
+ team = [s for s in ordinary_strategies if
387
+ Classifiers ().get ("memory_depth" , s ) <= 1 ]
390
388
super ().__init__ (team = team )
391
389
self .classifier ["long_run_time" ] = False
392
390
@@ -402,11 +400,8 @@ class MetaWinnerFiniteMemory(MetaWinner):
402
400
name = "Meta Winner Finite Memory"
403
401
404
402
def __init__ (self ):
405
- team = [
406
- s
407
- for s in ordinary_strategies
408
- if s ().classifier ["memory_depth" ] < float ("inf" )
409
- ]
403
+ team = [s for s in ordinary_strategies if
404
+ Classifiers ().get ("memory_depth" , s ) < float ("inf" )]
410
405
super ().__init__ (team = team )
411
406
412
407
@@ -421,11 +416,8 @@ class MetaWinnerLongMemory(MetaWinner):
421
416
name = "Meta Winner Long Memory"
422
417
423
418
def __init__ (self ):
424
- team = [
425
- s
426
- for s in ordinary_strategies
427
- if s ().classifier ["memory_depth" ] == float ("inf" )
428
- ]
419
+ team = [s for s in ordinary_strategies if
420
+ Classifiers ().get ("memory_depth" , s ) == float ("inf" )]
429
421
super ().__init__ (team = team )
430
422
431
423
@@ -440,7 +432,8 @@ class MetaWinnerDeterministic(MetaWinner):
440
432
name = "Meta Winner Deterministic"
441
433
442
434
def __init__ (self ):
443
- team = [s for s in ordinary_strategies if not s ().classifier ["stochastic" ]]
435
+ team = [s for s in ordinary_strategies if
436
+ not Classifiers ().get ("stochastic" , s )]
444
437
super ().__init__ (team = team )
445
438
self .classifier ["stochastic" ] = False
446
439
@@ -456,7 +449,8 @@ class MetaWinnerStochastic(MetaWinner):
456
449
name = "Meta Winner Stochastic"
457
450
458
451
def __init__ (self ):
459
- team = [s for s in ordinary_strategies if s ().classifier ["stochastic" ]]
452
+ team = [s for s in ordinary_strategies if
453
+ Classifiers ().get ("stochastic" , s )]
460
454
super ().__init__ (team = team )
461
455
462
456
@@ -512,7 +506,8 @@ class NMWEDeterministic(NiceMetaWinnerEnsemble):
512
506
name = "NMWE Deterministic"
513
507
514
508
def __init__ (self ):
515
- team = [s for s in ordinary_strategies if not s ().classifier ["stochastic" ]]
509
+ team = [s for s in ordinary_strategies if
510
+ not Classifiers ().get ("stochastic" , s )]
516
511
super ().__init__ (team = team )
517
512
self .classifier ["stochastic" ] = True
518
513
@@ -528,7 +523,8 @@ class NMWEStochastic(NiceMetaWinnerEnsemble):
528
523
name = "NMWE Stochastic"
529
524
530
525
def __init__ (self ):
531
- team = [s for s in ordinary_strategies if s ().classifier ["stochastic" ]]
526
+ team = [s for s in ordinary_strategies if
527
+ Classifiers ().get ("stochastic" , s )]
532
528
super ().__init__ (team = team )
533
529
534
530
@@ -543,11 +539,8 @@ class NMWEFiniteMemory(NiceMetaWinnerEnsemble):
543
539
name = "NMWE Finite Memory"
544
540
545
541
def __init__ (self ):
546
- team = [
547
- s
548
- for s in ordinary_strategies
549
- if s ().classifier ["memory_depth" ] < float ("inf" )
550
- ]
542
+ team = [s for s in ordinary_strategies if
543
+ Classifiers ().get ("memory_depth" , s ) < float ("inf" )]
551
544
super ().__init__ (team = team )
552
545
553
546
@@ -562,11 +555,8 @@ class NMWELongMemory(NiceMetaWinnerEnsemble):
562
555
name = "NMWE Long Memory"
563
556
564
557
def __init__ (self ):
565
- team = [
566
- s
567
- for s in ordinary_strategies
568
- if s ().classifier ["memory_depth" ] == float ("inf" )
569
- ]
558
+ team = [s for s in ordinary_strategies if
559
+ Classifiers ().get ("memory_depth" , s ) == float ("inf" )]
570
560
super ().__init__ (team = team )
571
561
572
562
@@ -581,7 +571,8 @@ class NMWEMemoryOne(NiceMetaWinnerEnsemble):
581
571
name = "NMWE Memory One"
582
572
583
573
def __init__ (self ):
584
- team = [s for s in ordinary_strategies if s ().classifier ["memory_depth" ] <= 1 ]
574
+ team = [s for s in ordinary_strategies if
575
+ Classifiers ().get ("memory_depth" , s ) <= 1 ]
585
576
super ().__init__ (team = team )
586
577
self .classifier ["long_run_time" ] = False
587
578
@@ -627,7 +618,6 @@ def __init__(
627
618
start_strategy_duration : int = 15 ,
628
619
):
629
620
super ().__init__ (team = [start_strategy ])
630
- self .classifier ["stochastic" ] = True
631
621
self .p_memory_delete = p_memory_delete
632
622
self .p_memory_alter = p_memory_alter
633
623
self .loss_value = loss_value
0 commit comments