Skip to content

Commit 05f97e3

Browse files
committed
Write description/ex of receive_match_attributes
Note we only need to do this when the inputs from the match are used to change some other variable. Some other minor tweaks here: - Remove unneeded data file. This was checked in at some point but shouldn't have been. - Remove outdated documentation about repr. This is now done automatically by the parent class. - Make some minor stylistic changes. - PEP8 (column width) - Change to use class hyperlink instead of code syntax highlighting.
1 parent 3fd3250 commit 05f97e3

File tree

2 files changed

+15
-24
lines changed

2 files changed

+15
-24
lines changed

docs/tutorials/contributing/strategy/writing_the_new_strategy.rst

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ The code
2222
--------
2323

2424
There are a couple of things that need to be created in a strategy.py file. Let
25-
us take a look at the :code:`TitForTat` class (located in the
25+
us take a look at the :class:`TitForTat
26+
<axelrod.strategies.titfortat.TitForTat>` class (located in the
2627
:code:`axelrod/strategies/titfortat.py` file)::
2728

2829
class TitForTat(Player):
@@ -101,7 +102,8 @@ This helps classify the strategy as described in
101102
:ref:`classification-of-strategies`.
102103

103104
After that the only thing required is to write the :code:`strategy` method
104-
which takes an opponent as an argument. In the case of :code:`TitForTat` the
105+
which takes an opponent as an argument. In the case of
106+
:class:`TitForTat <axelrod.strategies.titfortat.TitForTat>` the
105107
strategy checks if it has any history (:code:`if len(self.history) == 0`). If
106108
it does not (ie this is the first play of the match) then it returns :code:`C`.
107109
If not, the strategy simply repeats the opponent's last move (:code:`return
@@ -115,30 +117,19 @@ opponent.history[-1]`)::
115117
# Repeat the opponent's last move
116118
return opponent.history[-1]
117119

118-
The variables :code:`C` and :code:`D` represent the cooperate and defect actions respectively.
120+
The variables :code:`C` and :code:`D` represent the cooperate and defect actions
121+
respectively.
119122

120-
You can also modify the name of the strategy with the :code:`__repr__` method,
121-
which is invoked when :code:`str` is applied to a player instance. For example,
122-
the :code:`Random` strategy takes a parameter :code:`p` for how often it
123-
cooperates, and the :code:`__repr__` method adds the value of this parameter to
124-
the name::
123+
Some strategies make specific use of the variables of a match to create their
124+
own attributes, in this case the :code:`receive_match_attributes` method must be
125+
defined. Here is how this is done for
126+
:class:`Stalker <axelrod.strategies.stalker.Stalker>`::
125127

126-
def __repr__(self):
127-
return "%s: %s" % (self.name, round(self.p, 2))
128-
129-
Now we have separate names for different instantiations::
130-
131-
>>> import axelrod
132-
>>> player1 = axelrod.Random(p=0.5)
133-
>>> player2 = axelrod.Random(p=0.1)
134-
>>> player1
135-
Random: 0.5
136-
>>> player2
137-
Random: 0.1
138-
139-
This helps distinguish players in tournaments that have multiple instances of the
140-
same strategy. If you modify the :code:`__repr__` method of player, be sure to
141-
add an appropriate test.
128+
def receive_match_attributes(self)
129+
R, P, S, T = self.match_attributes["game"].RPST()
130+
self.very_good_score = R
131+
self.very_bad_score = P
132+
self.wish_score = (R + P) / 2
142133

143134
There are various examples of helpful functions and properties that make
144135
writing strategies easier. Do not hesitate to get in touch with the

training_data.csv

Whitespace-only changes.

0 commit comments

Comments
 (0)