Skip to content

Commit 67d73dd

Browse files
committed
Adding more details to the docs.
1 parent ad8de7d commit 67d73dd

File tree

1 file changed

+23
-29
lines changed

1 file changed

+23
-29
lines changed

docs/contributing.rst

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -95,18 +95,24 @@ For example there is strategy with :math:`\pi` as a name::
9595

9696
name = '$\pi$'
9797

98-
After that the only thing required is to write the :code:`strategy` method which takes an opponent as an argument.
99-
In the case of :code:`TitForTat` the strategy attempts to play the same thing as the last strategy played by the opponent (:code:`opponent.history[-1]`) and if this is not possible (in other words the opponent has not played yet) will cooperate::
98+
After that the only thing required is to write the :code:`strategy` method which
99+
takes an opponent as an argument. In the case of :code:`TitForTat` the strategy
100+
attempts to play the same thing as the last strategy played by the opponent
101+
(:code:`opponent.history[-1]`) and if this is not possible (in other words the
102+
opponent has not played yet) will cooperate::
100103

101104
def strategy(self, opponent):
102105
try:
103106
return opponent.history[-1]
104107
except IndexError:
105108
return 'C'
106109

107-
If your strategy creates any particular attribute along the way you need to make sure that there is a :code:`reset` method that takes account of it.
108-
An example of this is the :code:`ForgetfulGrudger` strategy which creates a boolean variable :code:`grudged` and a counter :code:`grudge_memory` which keeps track of things during a duel.
109-
Here is the :code:`reset` method which takes care of resetting this in between rounds::
110+
If your strategy creates any particular attribute along the way you need to make
111+
sure that there is a :code:`reset` method that takes account of it. An example
112+
of this is the :code:`ForgetfulGrudger` strategy which creates a boolean
113+
variable :code:`grudged` and a counter :code:`grudge_memory` which keeps track
114+
of things during a duel. Here is the :code:`reset` method which takes care of
115+
resetting this in between rounds::
110116

111117
def reset(self):
112118
"""Resets scores and history."""
@@ -115,10 +121,10 @@ Here is the :code:`reset` method which takes care of resetting this in between r
115121
self.grudge_memory = 0
116122

117123

118-
You can also modify the name of the strategy with the `__repr__` method, which is invoked
119-
when `str` is applied to a player instance. For example, the player `Random` takes a
120-
parameter `p` for how often it cooperates, and the `__repr__` method adds the value
121-
of this parameter to the name::
124+
You can also modify the name of the strategy with the `__repr__` method, which
125+
is invoked when `str` is applied to a player instance. For example, the player
126+
`Random` takes a parameter `p` for how often it cooperates, and the `__repr__`
127+
method adds the value of this parameter to the name::
122128

123129
def __repr__(self):
124130
return "%s: %s" % (self.name, round(self.p, 2))
@@ -140,6 +146,10 @@ This helps distinguish players in tournaments that have multiple instances of th
140146
same strategy. If you modify the `__repr__` method of player, be sure to add an
141147
appropriate test.
142148

149+
There is also a behaviour dictionary that allows for easy classification of
150+
strategies: take a look at the `Strategy Behaviour`_ section for more
151+
information.
152+
143153

144154
Adding the strategy to the library
145155
''''''''''''''''''''''''''''''''''
@@ -156,27 +166,10 @@ So for the :code:`TitForTat` strategy which is written in the :code:`titfortat.p
156166

157167
from titfortat import *
158168

159-
Once you have done that (**and you need to do this even if you have added a strategy to an already existing file**), you need to add the class itself to one of the following lists::
160-
161-
basic_strategies
162-
ordinary_strategies
163-
cheating_strategies
164-
165-
You will most probably be adding the strategy to one of :code:`ordinary_strategies` or :code:`cheating_strategies`.
166-
If you are unsure take a look at the section: `Strategy behaviour`_.
167-
168-
For :code:`TitForTat` this looks like::
169-
170-
basic_strategies = [
171-
Alternator,
172-
Cooperator,
173-
Defector,
174-
Random,
175-
TitForTat,
176-
]
169+
Once you have done that (**and you need to do this even if you have added a
170+
strategy to an already existing file**), you need to add the class itself to one
171+
of the :code:`strategies` list.
177172

178-
Note that :code:`TitForTat` is here added to the :code:`basic_strategies` list.
179-
If you would like to check if your strategy is honest, read the next section, if you would like to take a look at how to write tests please skip to `How to write tests`_ (again though if you need a hand with testing please let us know!).
180173

181174
Strategy behaviour
182175
''''''''''''''''''
@@ -205,6 +198,7 @@ the initialisation depending on input parameters. A good example of this is the
205198
>>> joss.behaviour['stochastic'], boring_joss.behaviour['stochastic']
206199
(True, False)
207200

201+
Dimensions that are not classified have value `None` in the dictionary.
208202

209203
There are currently three important dimensions that help identify if a strategy
210204
is 'honest' or not:

0 commit comments

Comments
 (0)