11import random
2+ import warnings
23
34import axelrod as axl
45from axelrod .interaction_utils import compute_final_score
78from .strategies import characteristics
89
910C , D = Action .C , Action .D
10- strategies = cdll .LoadLibrary ('libstrategies.so' )
1111actions = {0 : C , 1 : D }
1212original_actions = {C : 0 , D : 1 }
1313
@@ -16,7 +16,8 @@ class Player(axl.Player):
1616
1717 classifier = {"stochastic" : True }
1818
19- def __init__ (self , original_name ):
19+ def __init__ (self , original_name ,
20+ shared_library_name = 'libstrategies.so' ):
2021 """
2122 Parameters
2223 ----------
@@ -27,6 +28,8 @@ def __init__(self, original_name):
2728 A instance of an axelrod Game
2829 """
2930 super ().__init__ ()
31+ self .shared_library_name = shared_library_name
32+ self .shared_library = cdll .LoadLibrary (shared_library_name )
3033 self .original_name = original_name
3134 self .original_function = self .original_name
3235 is_stochastic = characteristics [self .original_name ]['stochastic' ]
@@ -56,7 +59,7 @@ def original_function(self):
5659
5760 @original_function .setter
5861 def original_function (self , value ):
59- self .__original_function = strategies [(value + '_' ).lower ()]
62+ self .__original_function = self . shared_library [(value + '_' ).lower ()]
6063 self .__original_function .argtypes = (
6164 POINTER (c_int ), POINTER (c_int ), POINTER (c_int ), POINTER (c_int ),
6265 POINTER (c_float ))
@@ -72,6 +75,18 @@ def original_strategy(
7275 return self .original_function (* [byref (arg ) for arg in args ])
7376
7477 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
86+ `shared_library_name`
87+ variable that points to a copy of the shared library."""
88+ warnings .warn (message = message )
89+
7590 if not self .history :
7691 their_last_move = 0
7792 scores = (0 , 0 )
0 commit comments