File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed
Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -114,6 +114,33 @@ Here is the :code:`reset` method which takes care of resetting this in between r
114114 self.grudged = False
115115 self.grudge_memory = 0
116116
117+
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::
122+
123+ def __repr__(self):
124+ return "%s: %s" % (self.name, round(self.p, 2))
125+
126+ Now we have separate names for different instantiations::
127+
128+ import axelrod
129+ player1 = axelrod.Random(p=0.5)
130+ player2 = axelrod.Random(p=0.1)
131+ print(str(player1))
132+ print(str(player2))
133+
134+ This produces the following output::
135+
136+ 'Random: 0.5'
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 `__repr__ ` method of player, be sure to add an
141+ appropriate test.
142+
143+
117144Adding the strategy to the library
118145''''''''''''''''''''''''''''''''''
119146
You can’t perform that action at this time.
0 commit comments