Skip to content

Commit 8f339f4

Browse files
authored
Merge pull request #5 from Axelrod-Python/add-abilitity-to-play-with-different-game
Add abilitity to play with different game
2 parents ba99a8f + 5e37382 commit 8f339f4

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

src/axelrod_fortran/player.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import axelrod.player as axl
22
from axelrod.interaction_utils import compute_final_score
33
from axelrod.action import Action
4+
from axelrod import Game
45
from ctypes import cdll, c_int, c_float, byref, POINTER
56

67
C, D = Action.C, Action.D
@@ -11,17 +12,20 @@
1112

1213
class Player(axl.Player):
1314

14-
def __init__(self, original_name):
15+
def __init__(self, original_name, game=Game()):
1516
"""
1617
Parameters
1718
----------
1819
original_name: str
1920
The name of the fortran function from the original axelrod
2021
tournament
22+
game: axelrod.Game
23+
A instance of an axelrod Game
2124
"""
2225
super().__init__()
2326
self.original_name = original_name
2427
self.original_function = self.original_name
28+
self.game = game
2529

2630
def __enter__(self):
2731
return self
@@ -66,7 +70,8 @@ def strategy(self, opponent, noise=0):
6670
my_last_move = 0
6771
else:
6872
their_last_move = original_actions[opponent.history[-1]]
69-
scores = compute_final_score(zip(self.history, opponent.history))
73+
scores = compute_final_score(zip(self.history, opponent.history),
74+
game=self.game)
7075
my_last_move = original_actions[self.history[-1]]
7176
move_number = len(self.history) + 1
7277
original_action = self.original_strategy(

tests/test_player.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from axelrod_fortran.strategies import all_strategies
22
from axelrod_fortran.player import Player
3-
from axelrod import Alternator, Cooperator, Defector, Match
3+
from axelrod import Alternator, Cooperator, Defector, Match, Game
44
from axelrod.action import Action
55
from ctypes import c_int, c_float, POINTER
66

@@ -46,6 +46,17 @@ def test_probend_matches():
4646
action in (C, D) for interaction in match.play()
4747
for action in interaction)
4848

49+
def test_matches_with_different_game():
50+
for strategy in all_strategies:
51+
for opponent in (Alternator, Cooperator, Defector):
52+
game = Game(r=4,s=0,p=2,t=6)
53+
players = (Player(strategy, game=game), opponent())
54+
match = Match(players, turns=200, game=game)
55+
assert all(
56+
action in (C, D) for interaction in match.play()
57+
for action in interaction)
58+
59+
4960
def test_original_strategy():
5061
"""
5162
Test original strategy against all possible first 5 moves of a Match

0 commit comments

Comments
 (0)