Skip to content

Commit 92e2c64

Browse files
authored
Merge pull request #685 from Axelrod-Python/684
Add a better doctest for setting random seed.
2 parents 792f402 + 354df19 commit 92e2c64

File tree

2 files changed

+12
-19
lines changed

2 files changed

+12
-19
lines changed

docs/tutorials/advanced/setting_a_seed.rst

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,13 @@ set. To do this we can use the `seed` function::
1111
>>> import axelrod as axl
1212
>>> players = (axl.Random(), axl.MetaMixer()) # Two stochastic strategies
1313
>>> axl.seed(0)
14-
>>> axl.Match(players, turns=3).play()
15-
[('D', 'C'), ('D', 'D'), ('C', 'C')]
14+
>>> results = axl.Match(players, turns=3).play()
1615

1716
We obtain the same results is it is played with the same seed::
1817

1918
>>> axl.seed(0)
20-
>>> axl.Match(players, turns=3).play()
21-
[('D', 'C'), ('D', 'D'), ('C', 'C')]
19+
>>> results == axl.Match(players, turns=3).play()
20+
True
2221

2322
Note that this is equivalent to::
2423

@@ -27,9 +26,8 @@ Note that this is equivalent to::
2726
>>> players = (axl.Random(), axl.MetaMixer())
2827
>>> random.seed(0)
2928
>>> numpy.random.seed(0)
30-
>>> axl.Match(players, turns=3).play()
31-
[('D', 'C'), ('D', 'D'), ('C', 'C')]
29+
>>> results = axl.Match(players, turns=3).play()
3230
>>> numpy.random.seed(0)
3331
>>> random.seed(0)
34-
>>> axl.Match(players, turns=3).play()
35-
[('D', 'C'), ('D', 'D'), ('C', 'C')]
32+
>>> results == axl.Match(players, turns=3).play()
33+
True

docs/tutorials/further_topics/spatial_tournaments.rst

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,11 @@ It is also possible to create a probabilistic ending spatial tournament with the
7676
>>> prob_end_spatial_tournament = axl.ProbEndSpatialTournament(players, edges=edges, prob_end=.1, repetitions=1)
7777
>>> prob_end_results = prob_end_spatial_tournament.play(keep_interactions=True)
7878

79-
We see that the match lengths are no longer all equal (we are here printing the
80-
length of the interactions)::
79+
We see that the match lengths are no longer all equal::
8180

8281
>>> axl.seed(0)
83-
>>> for index_pair, interaction in prob_end_results.interactions.items():
84-
... player1 = spatial_tournament.players[index_pair[0]]
85-
... player2 = spatial_tournament.players[index_pair[1]]
86-
... rep_length = [len(rep) for rep in interaction]
87-
... print('%s vs %s: %s' % (player1, player2, rep_length))
88-
Defector vs Tit For Tat: [43]
89-
Cooperator vs Grudger: [7]
90-
Defector vs Grudger: [5]
91-
Cooperator vs Tit For Tat: [1]
82+
>>> lengths = []
83+
>>> for interaction in prob_end_results.interactions.values():
84+
... lengths.append(len(interaction[0]))
85+
>>> min(lengths) != max(lengths)
86+
True

0 commit comments

Comments
 (0)