Skip to content

Commit 3adf311

Browse files
authored
Merge pull request #39 from Axelrod-Python/second
Add code snippet to rerun Axelrod's second tournament to readme
2 parents a0d6853 + 3b60e9f commit 3adf311

File tree

4 files changed

+34
-11
lines changed

4 files changed

+34
-11
lines changed

README.rst

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,33 @@ Installation
1818
Usage
1919
=====
2020

21-
::
21+
Running a match:
22+
23+
.. code-block:: python
24+
25+
>>> import axelrod_fortran as axlf
26+
>>> import axelrod as axl
27+
>>> p1 = axlf.Player('k31r')
28+
>>> p2 = axlf.Player('k33r')
29+
>>> match = axl.Match((p1, p2), turns=5)
30+
>>> match.play()
31+
[(C, C), (C, C), (C, D), (C, D), (C, C)]
32+
33+
Running an instance of Axelrod's second tournament:
34+
35+
.. code-block:: python
36+
37+
>>> import axelrod_fortran as axlf
38+
>>> import axelrod as axl
39+
>>> players = [axlf.Player(name) for name in axlf.second_tournament_strategies]
40+
>>> print(len(players), "players")
41+
62 players
42+
>>> tournament = axl.Tournament(players, repetitions=1, turns=200)
43+
>>> results = tournament.play()
44+
>>> results.write_summary('summary.csv')
45+
>>> plot = axl.Plot(results)
46+
>>> plot.save_all_plots("second_tournament")
2247
23-
>>> import axelrod_fortran as axlf
24-
>>> import axelrod as axl
25-
>>> p1 = axlf.Player('k31r')
26-
>>> p2 = axlf.Player('k33r')
27-
>>> match = axl.Match((p1, p2), turns=5)
28-
>>> match.play()
29-
[(C, C), (C, C), (C, D), (C, D), (C, C)]
3048
3149
Contributing
3250
============

src/axelrod_fortran/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
__version__ = "0.1.0"
22

33
from .player import Player
4-
from .strategies import characteristics, all_strategies
4+
from .strategies import (all_strategies, characteristics,
5+
second_tournament_strategies)

src/axelrod_fortran/player.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import axelrod as axl
44
from axelrod.interaction_utils import compute_final_score
55
from axelrod.action import Action
6-
from axelrod import Game
76
from ctypes import cdll, c_int, c_float, byref, POINTER
87
from .strategies import characteristics
98

@@ -49,7 +48,7 @@ def original_name(self, value):
4948
if value in characteristics:
5049
self.__original_name = value
5150
else:
52-
raise ValueError(f'{value} is not a valid Fortran function')
51+
raise ValueError('{} is not a valid Fortran function'.format(value))
5352

5453
@property
5554
def original_function(self):

src/axelrod_fortran/strategies.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,3 +349,8 @@
349349
}
350350

351351
all_strategies = characteristics.keys()
352+
353+
# Players from Axelrod's second tournament.
354+
second_tournament_strategies = [
355+
name for name in characteristics.keys()
356+
if characteristics[name]["original_rank"] is not None]

0 commit comments

Comments
 (0)