Skip to content

Commit 57d4034

Browse files
committed
Updates following Nik's initial review
1 parent 7163497 commit 57d4034

File tree

4 files changed

+14
-12
lines changed

4 files changed

+14
-12
lines changed

axelrod/player.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,8 @@ def set_seed(self, seed):
190190
"""Set a random seed for the player's random number generator."""
191191
if seed is None:
192192
warnings.warn(
193-
"Initializing player with seed from Axelrod module random number generator."
194-
" Results may not be seed reproducible.")
193+
"Initializing player with seed from Axelrod module random number generator. "
194+
"Results may not be seed reproducible.")
195195
self._seed = _module_random.random_seed_int()
196196
else:
197197
self._seed = seed

axelrod/random_.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
1+
from typing import Optional
12
import numpy as np
23
from axelrod.action import Action
34
from numpy.random import RandomState
45

6+
57
C, D = Action.C, Action.D
68

79

810
class RandomGenerator(object):
911
"""Container around a random number generator.
1012
Enables reproducibility of player behavior, matches,
1113
and tournaments."""
12-
def __init__(self, seed=None):
14+
def __init__(self, seed: Optional[int] = None):
1315
# _random is the internal object that generators random values
1416
self._random = RandomState()
1517
self.original_seed = seed
1618
self.seed(seed)
1719

18-
def seed(self, seed_):
20+
def seed(self, seed_: Optional[int] = None):
1921
"""Sets a seed"""
2022
self._random.seed(seed_)
2123

@@ -25,7 +27,7 @@ def random(self, *args, **kwargs):
2527
def randint(self, *args, **kwargs):
2628
return self._random.randint(*args, **kwargs)
2729

28-
def random_seed_int(self):
30+
def random_seed_int(self) -> int:
2931
return self.randint(low=0, high=2**32-1, dtype="uint64")
3032

3133
def choice(self, *args, **kwargs):
@@ -117,7 +119,7 @@ class BulkRandomGenerator(object):
117119
"""Bulk generator of random integers for tournament seeding and
118120
reproducibility. Bulk generation of random values is more efficient.
119121
Use this class like a generator."""
120-
def __init__(self, seed=None, batch_size=1000):
122+
def __init__(self, seed=None, batch_size:int = 1000):
121123
self._random_generator = RandomState()
122124
self._random_generator.seed(seed)
123125
self._ints = None

axelrod/tests/strategies/test_worse_and_worse.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,12 @@ class TestWorseAndWorse(TestPlayer):
2222
}
2323

2424
def test_strategy(self):
25-
"""Test that the strategy gives expected behaviour."""
26-
# 6 Rounds Cooperate given seed
25+
# For given seed cooperates for 6 rounds and then defects for a round
2726
actions = [(C, C)] * 6 + [(D, C)] + [(C, C)] * 3
2827
self.versus_test(axl.Cooperator(), expected_actions=actions, seed=144)
2928

3029
def test_strategy2(self):
31-
# 6 Rounds Cooperate and Defect no matter opponent
30+
# Test that behaviour does not depend on opponent
3231
actions = [(C, D)] * 6 + [(D, D)] + [(C, D)] * 3
3332
self.versus_test(axl.Defector(), expected_actions=actions, seed=144)
3433

docs/tutorials/getting_started/running_axelrods_first_tournament.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,10 @@ The results object contains the ranked names::
7171
First by Anonymous
7272
Random: 0.5
7373

74-
We see that `TitForTat` does not in fact win this tournament. `TitForTat` typically does not
75-
win, possibly because our implementations differ from the original strategies as their code
76-
is not available.
74+
75+
We see that `TitForTat` does not win. In fact `TitForTat` typically does not
76+
win this tournament, possibly because our implementations differ from the original
77+
strategies as their code is not available.
7778

7879
We can plot the reported rank (from [Axelrod1980]_) versus the reproduced one::
7980

0 commit comments

Comments
 (0)