Skip to content

Commit 6ac8e8c

Browse files
authored
Merge pull request #12 from Axelrod-Python/marc
Fix stochastic behavior and refactor tests to use unittest
2 parents 96b9b96 + 2e2313f commit 6ac8e8c

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

src/axelrod_fortran/player.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import random
2+
13
import axelrod as axl
24
from axelrod.interaction_utils import compute_final_score
35
from axelrod.action import Action
@@ -57,15 +59,15 @@ def original_function(self, value):
5759
self.__original_function.restype = c_int
5860

5961
def original_strategy(
60-
self, their_last_move, move_number, my_score, their_score, noise,
62+
self, their_last_move, move_number, my_score, their_score, random_value,
6163
my_last_move
6264
):
6365
args = (
6466
c_int(their_last_move), c_int(move_number), c_int(my_score),
65-
c_int(their_score), c_float(noise), c_int(my_last_move))
67+
c_int(their_score), c_float(random_value), c_int(my_last_move))
6668
return self.original_function(*[byref(arg) for arg in args])
6769

68-
def strategy(self, opponent, noise=0):
70+
def strategy(self, opponent):
6971
if not self.history:
7072
their_last_move = 0
7173
scores = (0, 0)
@@ -76,8 +78,9 @@ def strategy(self, opponent, noise=0):
7678
game=self.game)
7779
my_last_move = original_actions[self.history[-1]]
7880
move_number = len(self.history) + 1
81+
random_value = random.random()
7982
original_action = self.original_strategy(
80-
their_last_move, move_number, scores[0], scores[1], noise,
83+
their_last_move, move_number, scores[0], scores[1], random_value,
8184
my_last_move)
8285
return actions[original_action]
8386

tests/test_player.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def test_matches():
2929
action in (C, D) for interaction in match.play()
3030
for action in interaction)
3131

32+
3233
def test_noisy_matches():
3334
for strategy in all_strategies:
3435
for opponent in (Alternator, Cooperator, Defector):
@@ -38,6 +39,7 @@ def test_noisy_matches():
3839
action in (C, D) for interaction in match.play()
3940
for action in interaction)
4041

42+
4143
def test_probend_matches():
4244
for strategy in all_strategies:
4345
for opponent in (Alternator, Cooperator, Defector):
@@ -47,10 +49,11 @@ def test_probend_matches():
4749
action in (C, D) for interaction in match.play()
4850
for action in interaction)
4951

52+
5053
def test_matches_with_different_game():
5154
for strategy in all_strategies:
5255
for opponent in (Alternator, Cooperator, Defector):
53-
game = Game(r=4,s=0,p=2,t=6)
56+
game = Game(r=4, s=0, p=2, t=6)
5457
players = (Player(strategy, game=game), opponent())
5558
match = Match(players, turns=200, game=game)
5659
assert all(
@@ -80,7 +83,7 @@ def test_original_strategy():
8083
move_number=move_number,
8184
my_score=my_score,
8285
their_score=their_score,
83-
noise=0,
86+
random_value=0,
8487
my_last_move=my_action)
8588

8689
assert my_action in [0, 1]

0 commit comments

Comments
 (0)