Skip to content

Commit

Permalink
Merge pull request #39 from Axelrod-Python/second
Browse files Browse the repository at this point in the history
Add code snippet to rerun Axelrod's second tournament to readme
  • Loading branch information
meatballs authored Jul 29, 2017
2 parents a0d6853 + 3b60e9f commit 3adf311
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 11 deletions.
34 changes: 26 additions & 8 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,33 @@ Installation
Usage
=====

::
Running a match:

.. code-block:: python
>>> import axelrod_fortran as axlf
>>> import axelrod as axl
>>> p1 = axlf.Player('k31r')
>>> p2 = axlf.Player('k33r')
>>> match = axl.Match((p1, p2), turns=5)
>>> match.play()
[(C, C), (C, C), (C, D), (C, D), (C, C)]
Running an instance of Axelrod's second tournament:

.. code-block:: python
>>> import axelrod_fortran as axlf
>>> import axelrod as axl
>>> players = [axlf.Player(name) for name in axlf.second_tournament_strategies]
>>> print(len(players), "players")
62 players
>>> tournament = axl.Tournament(players, repetitions=1, turns=200)
>>> results = tournament.play()
>>> results.write_summary('summary.csv')
>>> plot = axl.Plot(results)
>>> plot.save_all_plots("second_tournament")
>>> import axelrod_fortran as axlf
>>> import axelrod as axl
>>> p1 = axlf.Player('k31r')
>>> p2 = axlf.Player('k33r')
>>> match = axl.Match((p1, p2), turns=5)
>>> match.play()
[(C, C), (C, C), (C, D), (C, D), (C, C)]
Contributing
============
Expand Down
3 changes: 2 additions & 1 deletion src/axelrod_fortran/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
__version__ = "0.1.0"

from .player import Player
from .strategies import characteristics, all_strategies
from .strategies import (all_strategies, characteristics,
second_tournament_strategies)
3 changes: 1 addition & 2 deletions src/axelrod_fortran/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import axelrod as axl
from axelrod.interaction_utils import compute_final_score
from axelrod.action import Action
from axelrod import Game
from ctypes import cdll, c_int, c_float, byref, POINTER
from .strategies import characteristics

Expand Down Expand Up @@ -49,7 +48,7 @@ def original_name(self, value):
if value in characteristics:
self.__original_name = value
else:
raise ValueError(f'{value} is not a valid Fortran function')
raise ValueError('{} is not a valid Fortran function'.format(value))

@property
def original_function(self):
Expand Down
5 changes: 5 additions & 0 deletions src/axelrod_fortran/strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,3 +349,8 @@
}

all_strategies = characteristics.keys()

# Players from Axelrod's second tournament.
second_tournament_strategies = [
name for name in characteristics.keys()
if characteristics[name]["original_rank"] is not None]

0 comments on commit 3adf311

Please sign in to comment.