Skip to content

Commit

Permalink
Merge pull request #685 from Axelrod-Python/684
Browse files Browse the repository at this point in the history
Add a better doctest for setting random seed.
  • Loading branch information
meatballs authored Aug 9, 2016
2 parents 792f402 + 354df19 commit 92e2c64
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 19 deletions.
14 changes: 6 additions & 8 deletions docs/tutorials/advanced/setting_a_seed.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@ set. To do this we can use the `seed` function::
>>> import axelrod as axl
>>> players = (axl.Random(), axl.MetaMixer()) # Two stochastic strategies
>>> axl.seed(0)
>>> axl.Match(players, turns=3).play()
[('D', 'C'), ('D', 'D'), ('C', 'C')]
>>> results = axl.Match(players, turns=3).play()

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

>>> axl.seed(0)
>>> axl.Match(players, turns=3).play()
[('D', 'C'), ('D', 'D'), ('C', 'C')]
>>> results == axl.Match(players, turns=3).play()
True

Note that this is equivalent to::

Expand All @@ -27,9 +26,8 @@ Note that this is equivalent to::
>>> players = (axl.Random(), axl.MetaMixer())
>>> random.seed(0)
>>> numpy.random.seed(0)
>>> axl.Match(players, turns=3).play()
[('D', 'C'), ('D', 'D'), ('C', 'C')]
>>> results = axl.Match(players, turns=3).play()
>>> numpy.random.seed(0)
>>> random.seed(0)
>>> axl.Match(players, turns=3).play()
[('D', 'C'), ('D', 'D'), ('C', 'C')]
>>> results == axl.Match(players, turns=3).play()
True
17 changes: 6 additions & 11 deletions docs/tutorials/further_topics/spatial_tournaments.rst
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,11 @@ It is also possible to create a probabilistic ending spatial tournament with the
>>> prob_end_spatial_tournament = axl.ProbEndSpatialTournament(players, edges=edges, prob_end=.1, repetitions=1)
>>> prob_end_results = prob_end_spatial_tournament.play(keep_interactions=True)

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

>>> axl.seed(0)
>>> for index_pair, interaction in prob_end_results.interactions.items():
... player1 = spatial_tournament.players[index_pair[0]]
... player2 = spatial_tournament.players[index_pair[1]]
... rep_length = [len(rep) for rep in interaction]
... print('%s vs %s: %s' % (player1, player2, rep_length))
Defector vs Tit For Tat: [43]
Cooperator vs Grudger: [7]
Defector vs Grudger: [5]
Cooperator vs Tit For Tat: [1]
>>> lengths = []
>>> for interaction in prob_end_results.interactions.values():
... lengths.append(len(interaction[0]))
>>> min(lengths) != max(lengths)
True

0 comments on commit 92e2c64

Please sign in to comment.