1
1
import random
2
+ import warnings
2
3
3
4
import axelrod as axl
4
5
from axelrod .interaction_utils import compute_final_score
7
8
from .strategies import characteristics
8
9
9
10
C , D = Action .C , Action .D
10
- strategies = cdll .LoadLibrary ('libstrategies.so' )
11
11
actions = {0 : C , 1 : D }
12
12
original_actions = {C : 0 , D : 1 }
13
13
@@ -16,7 +16,8 @@ class Player(axl.Player):
16
16
17
17
classifier = {"stochastic" : True }
18
18
19
- def __init__ (self , original_name ):
19
+ def __init__ (self , original_name ,
20
+ shared_library_name = 'libstrategies.so' ):
20
21
"""
21
22
Parameters
22
23
----------
@@ -27,6 +28,8 @@ def __init__(self, original_name):
27
28
A instance of an axelrod Game
28
29
"""
29
30
super ().__init__ ()
31
+ self .shared_library_name = shared_library_name
32
+ self .shared_library = cdll .LoadLibrary (shared_library_name )
30
33
self .original_name = original_name
31
34
self .original_function = self .original_name
32
35
is_stochastic = characteristics [self .original_name ]['stochastic' ]
@@ -56,7 +59,7 @@ def original_function(self):
56
59
57
60
@original_function .setter
58
61
def original_function (self , value ):
59
- self .__original_function = strategies [(value + '_' ).lower ()]
62
+ self .__original_function = self . shared_library [(value + '_' ).lower ()]
60
63
self .__original_function .argtypes = (
61
64
POINTER (c_int ), POINTER (c_int ), POINTER (c_int ), POINTER (c_int ),
62
65
POINTER (c_float ))
@@ -72,6 +75,17 @@ def original_strategy(
72
75
return self .original_function (* [byref (arg ) for arg in args ])
73
76
74
77
def strategy (self , opponent ):
78
+ if type (opponent ) is Player \
79
+ and (opponent .original_name == self .original_name ) \
80
+ and (opponent .shared_library_name == self .shared_library_name ):
81
+
82
+ message = """
83
+ You are playing a match with two copies of the same player.
84
+ However the axelrod fortran players share memory.
85
+ You can initialise an instance of an Axelrod_fortran player with a `strategies`
86
+ variable that points to a copy of the shared library."""
87
+ warnings .warn (message = message )
88
+
75
89
if not self .history :
76
90
their_last_move = 0
77
91
scores = (0 , 0 )
0 commit comments