Skip to content

Commit b5aa7de

Browse files
zewaywongdrvinceknight
authored andcommitted
Fixed spelling, added reference, feedback edits
1 parent 0f30f65 commit b5aa7de

File tree

2 files changed

+20
-24
lines changed

2 files changed

+20
-24
lines changed

docs/how-to/heterogeneous_matches.rst

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.. _heterogeneous-matches:
22

3-
Heterogeneous Matches
4-
=====================
3+
Use custom matches
4+
===================
55

66
Axelrod Matches are homogeneous by nature but can be extended to utilize additional attributes of heterogeneous players.
77
This tutorial indicates how the Axelrod :code:`Match` class can be manipulated in order to play heterogeneous tournaments and Moran processes using country mass as a score modifier.
@@ -17,20 +17,20 @@ The following lines of code creates a list of players from the available demo st
1717
Using the :code:`setattr()` method, additional attributes can be passed to players to enable access during matches and tournaments without manual modification of individual strategies::
1818

1919
>>> def set_player_mass(players, masses):
20-
>>> """Add mass attribute to player strategy classes to be accessable via self.mass"""
21-
>>> for player, mass in zip(players, masses):
22-
>>> setattr(player, "mass", mass)
23-
>>>
20+
... """Add mass attribute to player strategy classes to be accessable via self.mass"""
21+
... for player, mass in zip(players, masses):
22+
... setattr(player, "mass", mass)
23+
...
2424
>>> set_player_mass(players, masses)
2525

2626
The :code:`Match` class can be partially altered to enable different behaviour. Here we extend :code:`axl.Match` and overwrite its :code:`final_score_per_turn()`
27-
function to utilize the player mass attribute als a multiplier for the final score::
27+
function to utilize the player mass attribute as a multiplier for the final score::
2828

2929
>>> class MassBaseMatch(axl.Match):
30-
>>> """Axelrod Match object with a modified final score function to enable mass to influence the final score as a multiplier"""
31-
>>> def final_score_per_turn(self):
32-
>>> base_scores = axl.Match.final_score_per_turn(self)
33-
>>> return [player.mass * score for player, score in zip(self.players, base_scores)]
30+
... """Axelrod Match object with a modified final score function to enable mass to influence the final score as a multiplier"""
31+
... def final_score_per_turn(self):
32+
... base_scores = axl.Match.final_score_per_turn(self)
33+
... return [player.mass * score for player, score in zip(self.players, base_scores)]
3434

3535
We can now create a tournament like we normally would and pass our custom :code:`MassBaseMatch` to the tournament with the :code:`match_class` keyword argument::
3636

@@ -39,22 +39,17 @@ We can now create a tournament like we normally would and pass our custom :code:
3939
>>> print(results.ranked_names)
4040
['Defector', 'Grudger', 'Tit For Tat', 'Cooperator', 'Random: 0.5']
4141

42-
Additionally, Moran Processes can also be altered to incorporate heterogeneous matches. In order to
43-
use our previously defined :code:`MassBaseMatch`, we require one additional change to the :code:`MoranProcess` class::
42+
Similarly to [Krapohl2020] we are going to assign a mass to each individual for a Moran process.
43+
This requires us to build a specific match class:
4444

4545
>>> class MassBasedMoranProcess(axl.MoranProcess):
46-
>>> """Axelrod MoranProcess class """
47-
>>> def __next__(self):
48-
>>> set_player_mass(self.players, masses)
49-
>>> super().__next__()
50-
>>> return self
46+
... """Axelrod MoranProcess class """
47+
... def __next__(self):
48+
... set_player_mass(self.players, masses)
49+
... super().__next__()
50+
... return self
5151

52-
With this code snippet we can override the :code:`__next__()` call within the MoranProcess to include :code:`set_player_mass()`
53-
every round. This ensures that every player has mass attributes after the Moran process is triggered.
54-
Subsequently, with :code:`super().__next__()` the base MoranProcess :code:`__next__()` call is triggered. This method enables quick
55-
modifications to tournaments and moran processes with minimal repetitive code.
56-
57-
We can now create a Moran process as we normally would, with the inclusion of the match class as a keyword argument::
52+
In [Krapohl2020] a non standard Moran process is used where the mass of individuals is not reproduced so we will use inheritance to create a new Moran process that keeps the mass of the individuals constant.
5853

5954
>>> mp = MassBasedMoranProcess(players, match_class=MassBaseMatch)
6055
>>> mp.play()

docs/reference/bibliography.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ documentation.
3535
.. [Hilbe2017] Hilbe, C., Martinez-Vaquero, L. A., Chatterjee K., Nowak M. A. (2017). Memory-n strategies of direct reciprocity, Proceedings of the National Academy of Sciences May 2017, 114 (18) 4715-4720; doi: 10.1073/pnas.1621239114.
3636
.. [Kuhn2017] Kuhn, Steven, "Prisoner's Dilemma", The Stanford Encyclopedia of Philosophy (Spring 2017 Edition), Edward N. Zalta (ed.), https://plato.stanford.edu/archives/spr2017/entries/prisoner-dilemma/
3737
.. [Kraines1989] Kraines, David, and Vivian Kraines. "Pavlov and the prisoner's dilemma." Theory and decision 26.1 (1989): 47-79. doi:10.1007/BF00134056
38+
.. [Krapohl2020] Krapohl, S., Ocelík, V. & Walentek, D.M. The instability of globalization: applying evolutionary game theory to global trade cooperation. Public Choice 188, 31–51 (2021). https://doi.org/10.1007/s11127-020-00799-1
3839
.. [LessWrong2011] Zoo of Strategies (2011) LessWrong. Available at: http://lesswrong.com/lw/7f2/prisoners_dilemma_tournament_results/
3940
.. [Li2007] Li, J, How to Design a Strategy to Win an IPD Tournament, in Kendall G., Yao X. and Chong S. (eds.) The iterated prisoner’s dilemma: 20 years on. World Scientific, chapter 4, pp. 29-40, 2007.
4041
.. [Li2009] Li, J. & Kendall, G. (2009). A Strategy with Novel Evolutionary Features for the Iterated Prisoner’s Dilemma. Evolutionary Computation 17(2): 257–274.

0 commit comments

Comments
 (0)