



  

Axelrod 4.13.0 documentation

 [Axelrod](index.html#document-index) 

 stable

 

* [Tutorials](index.html#document-tutorials/index)

* [How to](index.html#document-how-to/index)

* [Discussion](index.html#document-discussion/index)

* [Reference](index.html#document-reference/index)

[Axelrod](index.html#document-index)

* [Docs](index.html#document-index) »

* Axelrod 4.13.0 documentation

* [Edit on GitHub](https://github.com/Axelrod-Python/Axelrod/blob/97db1f7c15d5a66807215278bde85a3cc89a2c01/docs/index.rst)

---

Welcome to the documentation for the Axelrod Python library[¶](#welcome-to-the-documentation-for-the-axelrod-python-library "Permalink to this headline")

=========================================================================================================================================================

Here is quick overview of the current capabilities of the library:

* Over 230 strategies including many from the literature and exciting

original contributions

> 

> 

> 	+ Classic strategies like TiT-For-Tat, WSLS, and variants

> 	+ Zero-Determinant and other Memory-One strategies

> 	+ Many generic strategies that can be used to define an array of popular

> 	strategies, including finite state machines, strategies that hunt for

> 	patterns in other strategies, and strategies that combine the effects of

> 	many others

> 	+ Strategy transformers that augment the abilities of any strategy

>

* Head-to-Head matches

* Round Robin tournaments with a variety of options, including:

> 

> 

> 	+ noisy environments

> 	+ spatial tournaments

> 	+ probabilistically chosen match lengths

>

* Population dynamics

> 

> 

> 	+ The Moran process

> 	+ An ecological model

>

* Multi-processor support (not currently supported on Windows), caching for

deterministic interactions, automatically generate figures and statistics

Every strategy is categorized on a number of dimensions, including:

> 

> * Deterministic or Stochastic

> * How many rounds of history used

> * Whether the strategy makes use of the game matrix, the length of the

> match, etc.

> 

> 

> 

Furthermore the library is extensively tested with 100% coverage, ensuring

validity and reproducibility of results!

Quick start[¶](#quick-start "Permalink to this headline")

---------------------------------------------------------

Count the number of available players:

```

>>> import axelrod as axl

>>> len(axl.strategies)

240

```

Create matches between two players:

```

>>> import axelrod as axl

>>> players = (axl.Alternator(), axl.TitForTat())

>>> match = axl.Match(players, 5)

>>> interactions = match.play()

>>> interactions

[(C, C), (D, C), (C, D), (D, C), (C, D)]

```

Build full tournaments between groups of players:

```

>>> import axelrod as axl

>>> players = (axl.Cooperator(), axl.Alternator(), axl.TitForTat())

>>> tournament = axl.Tournament(players)

>>> results = tournament.play()

>>> results.ranked\_names

['Alternator', 'Tit For Tat', 'Cooperator']

```

Study the evolutionary process using a Moran process:

```

>>> import axelrod as axl

>>> players = (axl.Cooperator(), axl.Alternator(), axl.TitForTat())

>>> mp = axl.MoranProcess(players)

>>> populations = mp.play()

>>> populations  

[Counter({'Alternator': 1, 'Cooperator': 1, 'Tit For Tat': 1}),

 Counter({'Alternator': 1, 'Cooperator': 1, 'Tit For Tat': 1}),

 Counter({'Cooperator': 1, 'Tit For Tat': 2}),

 Counter({'Cooperator': 1, 'Tit For Tat': 2}),

 Counter({'Tit For Tat': 3})]

```

As well as this, the library has a growing collection of strategies. The

[Strategy index](index.html#strategies-index) gives a description of them.

For further details there is a library of [Tutorials](index.html#tutorials) available and a

[Community](index.html#community) page with information about how to get support and/or make

contributions.

Table of Contents[¶](#table-of-contents "Permalink to this headline")

---------------------------------------------------------------------

### Tutorials[¶](#tutorials "Permalink to this headline")

This section contains a variety of tutorials related to the Axelrod library.

Contents:

#### New to Game Theory and/or Python[¶](#new-to-game-theory-and-or-python "Permalink to this headline")

This section contains a variety of tutorials that should help get you started

with the Axelrod library.

Contents:

##### Installation[¶](#installation "Permalink to this headline")

The library requires Python 3.5.

The simplest way to install the package is to obtain it from the PyPi

repository:

```

$ pip install axelrod

```

If you want to have access to the manual Human strategy for interactive play, use the following command to also install prompt\_toolkit:

```

$ pip install axelrod[Human]

```

You can also build it from source if you would like to:

```

$ git clone https://github.com/Axelrod-Python/Axelrod.git

$ cd Axelrod

$ python setup.py install

```

##### Creating Matches[¶](#creating-matches "Permalink to this headline")

You can create your own match between two players using the `Match` class.

This is often useful when designing new strategies in order to study how they

perform against specific opponents.

For example, to create a 5 turn match between `Cooperator` and

`Alternator`:

```

>>> import axelrod as axl

>>> players = (axl.Cooperator(), axl.Alternator())

>>> match = axl.Match(players, 5)

>>> match.play()

[(C, C), (C, D), (C, C), (C, D), (C, C)]

```

By default, a match will not be noisy, but you can introduce noise if you wish.

Noise is the probability with which any action dictated by a strategy will be

swapped:

```

>>> match = axl.Match(players=players, turns=5, noise=0.2)

>>> match.play()  

[(D, C), (C, D), (C, C), (C, D), (D, D)]

```

The result of the match is held as an attribute within the `Match` class.

Each time `play()` is called, it will overwrite the content of that

attribute:

```

>>> match.result  

[(D, C), (C, D), (C, C), (C, D), (D, D)]

>>> match.play()  

[(C, C), (C, C), (C, D), (C, C), (C, C)]

>>> match.result  

[(C, C), (C, C), (C, D), (C, C), (C, C)]

```

The result of the match can also be viewed as sparklines where cooperation is

shown as a solid block and defection as a space. Sparklines are a very concise

way to view the result and can be useful for spotting patterns:

```

>>> import axelrod as axl

>>> players = (axl.Cooperator(), axl.Alternator())

>>> match = axl.Match(players, 25)

>>> match.play()

[(C, C), (C, D), (C, C), (C, D), (C, C), (C, D), (C, C), (C, D), (C, C), (C, D), (C, C), (C, D), (C, C), (C, D), (C, C), (C, D), (C, C), (C, D), (C, C), (C, D), (C, C), (C, D), (C, C), (C, D), (C, C)]

>>> print(match.sparklines())  

█████████████████████████

█ █ █ █ █ █ █ █ █ █ █ █ █

```

The █ character for cooperation and a space for defection are default values

but you can use any characters you like:

```

>>> import axelrod as axl

>>> players = (axl.Cooperator(), axl.Alternator())

>>> match = axl.Match(players, 25)

>>> match.play()

[(C, C), (C, D), (C, C), (C, D), (C, C), (C, D), (C, C), (C, D), (C, C), (C, D), (C, C), (C, D), (C, C), (C, D), (C, C), (C, D), (C, C), (C, D), (C, C), (C, D), (C, C), (C, D), (C, C), (C, D), (C, C)]

>>> print(match.sparklines(c\_symbol='|', d\_symbol='-'))

|||||||||||||||||||||||||

|-|-|-|-|-|-|-|-|-|-|-|-|

```

A Match class can also score the individual turns of a match. Just call

match.scores() after play:

```

>>> import axelrod as axl

>>> players = (axl.Cooperator(), axl.Alternator())

>>> match = axl.Match(players, 25)

>>> match.play()

[(C, C), (C, D), (C, C), (C, D), (C, C), (C, D), (C, C), (C, D), (C, C), (C, D), (C, C), (C, D), (C, C), (C, D), (C, C), (C, D), (C, C), (C, D), (C, C), (C, D), (C, C), (C, D), (C, C), (C, D), (C, C)]

>>> match.scores()

[(3, 3), (0, 5), (3, 3), (0, 5), (3, 3), (0, 5), (3, 3), (0, 5), (3, 3), (0, 5), (3, 3), (0, 5), (3, 3), (0, 5), (3, 3), (0, 5), (3, 3), (0, 5), (3, 3), (0, 5), (3, 3), (0, 5), (3, 3), (0, 5), (3, 3)]

```

There are various further methods:

```

>>> match.final\_score()

(39, 99)

>>> match.final\_score\_per\_turn()

(1.56, 3.96)

>>> match.winner()

Alternator

>>> match.cooperation()  # The count of cooperations

(25, 13)

>>> match.normalised\_cooperation()  # The count of cooperations per turn

(1.0, 0.52)

```

##### Creating and running a simple tournament[¶](#creating-and-running-a-simple-tournament "Permalink to this headline")

The following lines of code creates a list players playing simple

strategies:

```

>>> import axelrod as axl

>>> players = [axl.Cooperator(), axl.Defector(),

...            axl.TitForTat(), axl.Grudger()]

>>> players

[Cooperator, Defector, Tit For Tat, Grudger]

```

We can now create a tournament, play it, save the results and view the rank of

each player:

```

>>> tournament = axl.Tournament(players)

>>> results = tournament.play()

>>> results.ranked\_names

['Defector', 'Tit For Tat', 'Grudger', 'Cooperator']

```

We can also plot these results:

```

>>> plot = axl.Plot(results)

>>> p = plot.boxplot()

>>> p.show()

```

[![_images/demo_deterministic_strategies_boxplot.svg](_images/demo_deterministic_strategies_boxplot.svg)](_images/demo_deterministic_strategies_boxplot.svg)

Note that in this case none of our strategies are stochastic so the boxplot

shows that there is no variation. Take a look at the [Visualising results](index.html#visualising-results)

section to see plots showing a stochastic effect.

##### Summarising tournament results[¶](#summarising-tournament-results "Permalink to this headline")

As shown in [Creating and running a simple tournament](index.html#creating-tournaments) let us create a tournament:

```

>>> import axelrod as axl

>>> players = [axl.Cooperator(), axl.Defector(),

...            axl.TitForTat(), axl.Grudger()]

>>> tournament = axl.Tournament(players, turns=10, repetitions=3)

>>> results = tournament.play()

```

The results set can return a list of named tuples, ordered by strategy rank

that summarises the results of the tournament:

```

>>> summary = results.summarise()

>>> import pprint

>>> pprint.pprint(summary)

[Player(Rank=0, Name='Defector', Median\_score=2.6..., Cooperation\_rating=0.0, Wins=3.0, Initial\_C\_rate=0.0, CC\_rate=...),

 Player(Rank=1, Name='Tit For Tat', Median\_score=2.3..., Cooperation\_rating=0..., Wins=0.0, Initial\_C\_rate=1.0, CC\_rate=...),

 Player(Rank=2, Name='Grudger', Median\_score=2.3..., Cooperation\_rating=0..., Wins=0.0, Initial\_C\_rate=1.0, CC\_rate=...),

 Player(Rank=3, Name='Cooperator', Median\_score=2.0..., Cooperation\_rating=1.0, Wins=0.0, Initial\_C\_rate=1.0, CC\_rate=...)]

```

It is also possible to write this data directly to a csv file using the

write\_summary method:

```

>>> results.write\_summary('summary.csv')

>>> import csv

>>> with open('summary.csv', 'r') as outfile:

...     csvreader = csv.reader(outfile)

...     for row in csvreader:

...         print(row)

['Rank', 'Name', 'Median\_score', 'Cooperation\_rating', 'Wins', 'Initial\_C\_rate', 'CC\_rate', 'CD\_rate', 'DC\_rate', 'DD\_rate', 'CC\_to\_C\_rate', 'CD\_to\_C\_rate', 'DC\_to\_C\_rate', 'DD\_to\_C\_rate']

['0', 'Defector', '2.6...', '0.0', '3.0', '0.0', '0.0', '0.0', '0.4...', '0.6...', '0', '0', '0', '0']

['1', 'Tit For Tat', '2.3...', '0.7', '0.0', '1.0', '0.66...', '0.03...', '0.0', '0.3...', '1.0', '0', '0', '0']

['2', 'Grudger', '2.3...', '0.7', '0.0', '1.0', '0.66...', '0.03...', '0.0', '0.3...', '1.0', '0', '0', '0']

['3', 'Cooperator', '2.0...', '1.0', '0.0', '1.0', '0.66...', '0.33...', '0.0', '0.0', '1.0', '1.0', '0', '0']

```

The result set class computes a large number of detailed outcomes read about

those in [Access tournament results](index.html#tournament-results).

##### Visualising results[¶](#visualising-results "Permalink to this headline")

This tutorial will show you briefly how to visualise some basic results

###### Visualising the results of the tournament[¶](#visualising-the-results-of-the-tournament "Permalink to this headline")

As shown in [Creating and running a simple tournament](index.html#creating-tournaments), let us create a tournament, but this

time we will include a player that acts randomly:

```

>>> import axelrod as axl

>>> players = [axl.Cooperator(), axl.Defector(),

...            axl.TitForTat(), axl.Grudger()]

>>> players.append(axl.Random())

>>> tournament = axl.Tournament(players)

>>> results = tournament.play()

```

We can view these results (which helps visualise the stochastic effects):

```

>>> plot = axl.Plot(results)

>>> p = plot.boxplot()

>>> p.show()

```

[![_images/demo_strategies_boxplot.svg](_images/demo_strategies_boxplot.svg)](_images/demo_strategies_boxplot.svg)

###### Visualising the distributions of wins[¶](#visualising-the-distributions-of-wins "Permalink to this headline")

We can view the distributions of wins for each strategy:

```

>>> p = plot.winplot()

>>> p.show()

```

[![_images/demo_strategies_winplot.svg](_images/demo_strategies_winplot.svg)](_images/demo_strategies_winplot.svg)

###### Visualising the payoff matrix[¶](#visualising-the-payoff-matrix "Permalink to this headline")

We can also easily view the payoff matrix described in

[Access tournament results](index.html#tournament-results), this becomes particularly useful when viewing the

outputs of tournaments with a large number of strategies:

```

>>> p = plot.payoff()

>>> p.show()

```

[![_images/demo_strategies_payoff.svg](_images/demo_strategies_payoff.svg)](_images/demo_strategies_payoff.svg)

###### Saving all plots[¶](#saving-all-plots "Permalink to this headline")

The `axelrod.Plot` class has a method: `save\_all\_plots` that will

save all the above plots to file.

###### Passing various objects to plot[¶](#passing-various-objects-to-plot "Permalink to this headline")

The library give access to underlying matplotlib axes objects of each plot, thus

the user can easily modify various aspects of a plot:

```

>>> import matplotlib.pyplot as plt

>>> \_, ax = plt.subplots()

>>> title = ax.set\_title('Payoff')

>>> xlabel = ax.set\_xlabel('Strategies')

>>> p = plot.boxplot(ax=ax)

>>> p.show()

```

[![_images/title_labels_payoff.png](_images/title_labels_payoff.png)](_images/title_labels_payoff.png)

##### Moran Process[¶](#moran-process "Permalink to this headline")

The strategies in the library can be pitted against one another in the

[Moran process](https://en.wikipedia.org/wiki/Moran_process), a population

process simulating natural selection.

The process works as follows. Given an

initial population of players, the population is iterated in rounds consisting

of:

* matches played between each pair of players, with the cumulative total

scores recorded

* a player is chosen to reproduce proportional to the player’s score in the

round

* a player is chosen at random to be replaced

The process proceeds in rounds until the population consists of a single player

type. That type is declared the winner. To run an instance of the process with

the library, proceed as follows:

```

>>> import axelrod as axl

>>> players = [axl.Cooperator(), axl.Defector(),

...            axl.TitForTat(), axl.Grudger()]

>>> mp = axl.MoranProcess(players, seed=1)

>>> populations = mp.play()

>>> mp.winning\_strategy\_name

'Tit For Tat'

```

You can access some attributes of the process, such as the number of rounds:

```

>>> len(mp)

15

```

The sequence of populations:

```

>>> import pprint

>>> pprint.pprint(populations)  

[Counter({'Defector': 1, 'Tit For Tat': 1, 'Grudger': 1, 'Cooperator': 1}),

 Counter({'Defector': 1, 'Tit For Tat': 1, 'Grudger': 1, 'Cooperator': 1}),

 Counter({'Cooperator': 2, 'Defector': 1, 'Tit For Tat': 1}),

 Counter({'Defector': 2, 'Cooperator': 2}),

 Counter({'Cooperator': 3, 'Defector': 1}),

 Counter({'Cooperator': 3, 'Defector': 1}),

 Counter({'Defector': 2, 'Cooperator': 2}),

 Counter({'Defector': 3, 'Cooperator': 1}),

 Counter({'Defector': 3, 'Cooperator': 1}),

 Counter({'Defector': 3, 'Cooperator': 1}),

 Counter({'Defector': 3, 'Cooperator': 1}),

 Counter({'Defector': 3, 'Cooperator': 1}),

 Counter({'Defector': 3, 'Cooperator': 1}),

 Counter({'Defector': 3, 'Cooperator': 1}),

 Counter({'Defector': 3, 'Cooperator': 1}),

 Counter({'Defector': 4})]

```

The scores in each round:

```

>>> for row in mp.score\_history:

...     print([round(element, 1) for element in row])

[6.0, 7.0, 7.0, 7.0]

[7.0, 3.1, 7.0, 7.0]

[7.0, 3.1, 7.0, 7.0]

[7.0, 3.1, 7.0, 7.0]

[7.0, 3.1, 7.0, 7.0]

[3.0, 3.0, 5.0, 5.0]

[3.0, 3.0, 5.0, 5.0]

[3.1, 7.0, 7.0, 7.0]

[3.1, 7.0, 7.0, 7.0]

[9.0, 9.0, 9.0, 9.0]

[9.0, 9.0, 9.0, 9.0]

[9.0, 9.0, 9.0, 9.0]

[9.0, 9.0, 9.0, 9.0]

[9.0, 9.0, 9.0, 9.0]

```

We can plot the results of a Moran process with mp.populations\_plot(). Let’s

use a larger population to get a bit more data:

```

>>> import random

>>> import matplotlib.pyplot as plt

>>> players = [axl.Defector(), axl.Defector(), axl.Defector(),

...        axl.Cooperator(), axl.Cooperator(), axl.Cooperator(),

...        axl.TitForTat(), axl.TitForTat(), axl.TitForTat(),

...        axl.Random()]

>>> mp = axl.MoranProcess(players=players, turns=200, seed=2)

>>> populations = mp.play()

>>> mp.winning\_strategy\_name

'Tit For Tat'

>>> ax = mp.populations\_plot()

>>> plt.show()  

```

[![_images/moran_example.svg](_images/moran_example.svg)](_images/moran_example.svg)

###### Moran Process with Mutation[¶](#moran-process-with-mutation "Permalink to this headline")

The `MoranProcess` class also accepts an argument for a mutation rate.

Nonzero mutation changes the Markov process so that it no longer has absorbing

states, and will iterate forever. To prevent this, iterate with a loop (or

function like `takewhile` from `itertools`):

```

>>> import axelrod as axl

>>> players = [axl.Cooperator(), axl.Defector(),

...            axl.TitForTat(), axl.Grudger()]

>>> mp = axl.MoranProcess(players, mutation\_rate=0.1, seed=10)

>>> for \_ in mp:

...     if len(mp.population\_distribution()) == 1:

...         break

>>> mp.population\_distribution()

Counter({'Defector': 4})

```

It is possible to pass a fitness function that scales the utility values. A common one

used in the literature, [[Ohtsuki2006]](index.html#ohtsuki2006), is \(f(s) = 1 - w + ws\) where \(w\)

denotes the intensity of selection:

```

>>> players = (axl.Cooperator(), axl.Defector(), axl.Defector(), axl.Defector())

>>> w = 0.95

>>> fitness\_transformation = lambda score: 1 - w + w \* score

>>> mp = axl.MoranProcess(players, turns=10, fitness\_transformation=fitness\_transformation, seed=3)

>>> populations = mp.play()

>>> mp.winning\_strategy\_name

'Defector'

```

Other types of implemented Moran processes:

* [Create Moran Processes On Graphs](index.html#moran-process-on-graphs)

* [Create Approximate Moran Process](index.html#approximate-moran-process)

##### Human Interaction[¶](#human-interaction "Permalink to this headline")

It is possible to play interactively using the Human strategy:

```

>>> import axelrod as axl

>>> me = axl.Human(name='me')

>>> players = [axl.TitForTat(), me]

>>> match = axl.Match(players, turns=3)

>>> match.play() 

```

You will be prompted for the action to play at each turn:

```

Starting new match

Turn 1 action [C or D] for me: C

Turn 1: me played C, opponent played C

Turn 2 action [C or D] for me: D

Turn 2: me played D, opponent played C

Turn 3 action [C or D] for me: C

[(C, C), (C, D), (D, C)]

```

after this, the `match` object can be manipulated as described in

[Creating Matches](index.html#creating-matches)

#### Running Axelrod’s First Tournament[¶](#running-axelrod-s-first-tournament "Permalink to this headline")

This tutorial will bring together topics from the previous tutorials to

reproduce Axelrod’s original tournament from [[Axelrod1980]](index.html#axelrod1980).

##### Selecting our players[¶](#selecting-our-players "Permalink to this headline")

We will use the players from Axelrod’s first tournament which are contained

in the axelrod.axelrod\_first\_strategies list:

```

>>> import axelrod as axl

>>> first\_tournament\_participants\_ordered\_by\_reported\_rank = [s() for s in axl.axelrod\_first\_strategies]

>>> number\_of\_strategies = len(first\_tournament\_participants\_ordered\_by\_reported\_rank)

>>> for player in first\_tournament\_participants\_ordered\_by\_reported\_rank:

...     print(player)

Tit For Tat

First by Tideman and Chieruzzi: (D, D)

First by Nydegger

First by Grofman

First by Shubik

First by Stein and Rapoport: 0.05: (D, D)

Grudger

First by Davis: 10

First by Graaskamp: 0.05

First by Downing

First by Feld: 1.0, 0.5, 200

First by Joss: 0.9

First by Tullock

First by Anonymous

Random: 0.5

```

##### Creating the tournament[¶](#creating-the-tournament "Permalink to this headline")

Now we create and run the tournament, we will set a seed to ensure

reproducibility and 5 repetitions to smooth the random effects. We use 5

repetitions as this is what was done in [[Axelrod1980]](index.html#axelrod1980):

```

>>> tournament = axl.Tournament(

...      players=first\_tournament\_participants\_ordered\_by\_reported\_rank,

...      turns=200,

...      repetitions=5,

...      seed=1,

... )

>>> results = tournament.play()

```

##### Viewing the ranks of the participants[¶](#viewing-the-ranks-of-the-participants "Permalink to this headline")

The results object contains the ranked names:

```

>>> for name in results.ranked\_names:

...     print(name)

First by Stein and Rapoport: 0.05: (D, D)

First by Grofman

First by Shubik

Tit For Tat

First by Nydegger

First by Tideman and Chieruzzi: (D, D)

Grudger

First by Davis: 10

First by Graaskamp: 0.05

First by Downing

First by Feld: 1.0, 0.5, 200

First by Tullock

First by Joss: 0.9

First by Anonymous

Random: 0.5

```

We see that TitForTat does not win. In fact TitForTat typically does not

win this tournament, possibly because our implementations differ from the original

strategies as their code is not available.

We can plot the reported rank (from [[Axelrod1980]](index.html#axelrod1980)) versus the reproduced one:

```

>>> import matplotlib.pyplot as plt

>>> plt.figure(figsize=(15, 6)) 

>>> plt.plot((0, 15), (0, 15), color="grey", linestyle="--")  

>>> for original\_rank, strategy in enumerate(first\_tournament\_participants\_ordered\_by\_reported\_rank):

...     rank = results.ranked\_names.index(str(strategy))

...     if rank == original\_rank:

...         symbol = "+"

...         plt.plot((rank, rank), (rank, 0), color="grey")

...     else:

...         symbol = "o"

...     plt.scatter([rank], [original\_rank], marker=symbol, color="black", s=50)  

>>> plt.xticks(

...     range(number\_of\_strategies),

...     results.ranked\_names,

...     rotation=90

... )  

>>> plt.ylabel("Reported rank")  

>>> plt.xlabel("Reproduced rank");  

>>> plt.show()

```

[![_images/rank_comparison.svg](_images/rank_comparison.svg)](_images/rank_comparison.svg)

##### Visualising the scores[¶](#visualising-the-scores "Permalink to this headline")

We see that the first 6 strategies do not match the ranks of the original paper,

we can take a look the variation in the scores:

```

>>> plot = axl.Plot(results)

>>> p = plot.boxplot()

>>> p.show()

```

[![_images/boxplot.svg](_images/boxplot.svg)](_images/boxplot.svg)

The first 6 strategies have similar scores which could indicate that the

original work by Axelrod was not run with sufficient repetitions. Another

explanation is that all the strategies are implemented from the descriptions

given in [[Axelrod1980]](index.html#axelrod1980) and there is no source code to base this on. This leads

to some strategies being ambiguous. These are all clearly explained in the

strategy docstrings. For example:

```

>>> print(axl.FirstByAnonymous.\_\_doc\_\_)

 Submitted to Axelrod's first tournament by a graduate student whose name was

 withheld.

 The description written in [Axelrod1980]\_ is:

 > "This rule has a probability of cooperating, P, which is initially 30% and

 > is updated every 10 moves. P is adjusted if the other player seems random,

 > very cooperative, or very uncooperative. P is also adjusted after move 130

 > if the rule has a lower score than the other player. Unfortunately, the

 > complex process of adjustment frequently left the probability of cooperation

 > in the 30% to 70% range, and therefore the rule appeared random to many

 > other players."

 Given the lack of detail this strategy is implemented based on the final

 sentence of the description which is to have a cooperation probability that

 is uniformly random in the 30 to 70% range.

 Names:

 - (Name withheld): [Axelrod1980]\_

```

##### Other outcomes[¶](#other-outcomes "Permalink to this headline")

If we run the tournament with other seeds, the results are different. For

example, with 1408 Tit For Tat wins:

```

>>> tournament = axl.Tournament(

...      players=first\_tournament\_participants\_ordered\_by\_reported\_rank,

...      turns=200,

...      repetitions=5,

...      seed=1408,

... )

>>> results = tournament.play()

>>> for name in results.ranked\_names:

...     print(name)

Tit For Tat

First by Stein and Rapoport: 0.05: (D, D)

First by Grofman

First by Shubik

First by Tideman and Chieruzzi: (D, D)

First by Nydegger

Grudger

First by Davis: 10

First by Graaskamp: 0.05

First by Downing

First by Feld: 1.0, 0.5, 200

First by Tullock

First by Joss: 0.9

First by Anonymous

Random: 0.5

```

With 136 the strategy submitted by Grofman wins:

```

>>> tournament = axl.Tournament(

...      players=first\_tournament\_participants\_ordered\_by\_reported\_rank,

...      turns=200,

...      repetitions=5,

...      seed=136

... )

>>> results = tournament.play()

>>> for name in results.ranked\_names:

...     print(name)

First by Grofman

First by Stein and Rapoport: 0.05: (D, D)

Tit For Tat

First by Shubik

First by Tideman and Chieruzzi: (D, D)

First by Nydegger

Grudger

First by Davis: 10

First by Downing

First by Graaskamp: 0.05

First by Feld: 1.0, 0.5, 200

First by Joss: 0.9

First by Tullock

Random: 0.5

First by Anonymous

```

#### Create Heterogeneous Moran Processes[¶](#create-heterogeneous-moran-processes "Permalink to this headline")

Axelrod Matches are homogeneous by nature but can be extended to utilize

additional attributes of heterogeneous players. This tutorial indicates how the

Axelrod `Match` class can be manipulated in order to play heterogeneous

tournaments and Moran processes using mass as a score modifier similarly to the

work of [[Krapohl2020]](index.html#krapohl2020).

The following lines of code creates a list of players from the available demo

strategies along with an ascending list of masses we will use for the players.

This is equivalent in principle to the country masses discussed in

[[Krapohl2020]](index.html#krapohl2020):

```

>>> import axelrod as axl

>>> players = [player() for player in axl.demo\_strategies]

>>> masses = [i for i in range(len(players))]

>>> players

[Cooperator, Defector, Tit For Tat, Grudger, Random: 0.5]

```

Using the `setattr()` function, additional attributes can be passed to

players to enable access during matches and tournaments without manual

modification of individual strategies:

```

>>> def set\_player\_mass(players, masses):

...  """Add mass attribute to player strategy classes to be accessable via self.mass"""

...     for player, mass in zip(players, masses):

...         setattr(player, "mass", mass)

...

>>> set\_player\_mass(players, masses)

```

The `Match` class can be partially altered to enable different behaviour

(see [Use custom matches](index.html#use-custom-matches)).

Here we extend `axl.Match` and overwrite its

`final\_score\_per\_turn()` function to utilize the player mass attribute as

a multiplier for the final score:

```

>>> class MassBaseMatch(axl.Match):

...  """Axelrod Match object with a modified final score function to enable mass to influence the final score as a multiplier"""

...     def final\_score\_per\_turn(self):

...         base\_scores = axl.Match.final\_score\_per\_turn(self)

...         return [player.mass \* score for player, score in zip(self.players, base\_scores)]

```

In [[Krapohl2020]](index.html#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:

```

>>> class MassBasedMoranProcess(axl.MoranProcess):

...  """Axelrod MoranProcess class """

...     def \_\_next\_\_(self):

...         set\_player\_mass(self.players, masses)

...         super().\_\_next\_\_()

...         return self

>>> mp = MassBasedMoranProcess(players, match\_class=MassBaseMatch, seed=0)

>>> populations = mp.play()

>>> print(mp.winning\_strategy\_name)

Random: 0.5

```

Note that the snippets here only influence the final score of matches. The

behavior of matches, and Moran processes can be more heavily influenced by

partially overwriting other `match` functions or `birth` and

`death` functions within `MoranProcess`.

#### Implement new games[¶](#id1 "Permalink to this headline")

Currently, the default `Strategy`, `Action` and `Game`

implementations in Axelrod are centred around the Iterated Prisoners’ Dilemma.

The stage game can be changed as shown in [Use different stage games](index.html#use-different-stage-games).

However, just changing the stage game may not be sufficient. Take, for example, the

game rock-paper-scissors:

```

>>> import axelrod as axl

>>> import numpy as np

>>> A = np.array([[0, -1, 1], [1, 0, -1], [-1, 1, 0]])

>>> rock\_paper\_scissors = axl.AsymmetricGame(A, -A)

>>> rock\_paper\_scissors  

Axelrod game with matrices: (array([[ 0, -1, 1],

 [ 1, 0, -1],

 [-1, 1, 0]]),

 array([[ 0, 1, -1],

 [-1, 0, 1],

 [ 1, -1, 0]]))

```

If we tried to run a rock-paper-scissors match with the `Tit-For-Tat` strategy,

it wouldn’t work properly. `Tit-For-Tat` only knows of two actions (cooperate and defect,

corresponding to rows 1 and 2 respectively). If we tried to use it on rock-paper-scissors, it would

interpret the game in the following way:

1. On the first turn, choose rock (option 1, cooperate)

2. If the opponent’s last move is the Python object

`axl.Action.D` (which it may never be unless the opponent also thinks it’s playing IPD!),

then choose paper (option 2, defection)

and so as we see, `Tit-For-Tat` would simply play Rock every turn, unless it

were playing against another Prisoners’ Dilemma strategy (then it

plays rock unless the opponent last played paper, in which case it plays paper). In

particular, it would never play scissors - it does not know that Scissors is something

it can even do. This is not a bug, or an issue with the strategy itself;

simply that `Tit-For-Tat` *thinks* it is playing the Iterated Prisoners’ Dilemma

and its `Action` set, regardless of what the actual game is.

Thus, if we wanted to implement new games we should also implement a new Action set,

and some new strategies.

The Actions are relatively simple; they’re an [Enum class](https://docs.python.org/3/library/enum.html),

with each action corresponding to a row/column (recall that Python starts counting from 0,

rather than 1). We can also implement some methods that we think might be useful for viewing

our actions and making strategies. (The Prisoners’ Dilemma `Action` class, for example,

has `flip`, which flips a `C` to a `D` and vice versa!)

A simple rock-paper-scissors action class would look like so:

```

>>> from enum import Enum

>>> class RPSAction(Enum):

...  """Actions for Rock-Paper-Scissors."""

...     R = 0  # rock

...     P = 1  # paper

...     S = 2  # scissors

...

...     def \_\_repr\_\_(self):

...         return self.name

...

...     def \_\_str\_\_(self):

...         return self.name

...

...     def rotate(self):

...  """

...  Cycles one step through the actions.

...  Maps R->P, P->S, S->R

...  """

...         rotations = {

...             RPSAction.R: RPSAction.P,

...             RPSAction.P: RPSAction.S,

...             RPSAction.S: RPSAction.R

...         }

...

...         return rotations[self]

```

We can then implement some strategies. Below we have the implementation of an

Axelrod strategy into Python. These follow the same format;

* A subclass of the `Player` class, with three parts:

	+ A `name` and a `classifier` dictionary.

	This is used for indexing strategies.

	+ (Optionally) an `\_\_init\_\_` method, which allows the setting

	of initialisation variables (like probabilities of doing certain

	actions, or starting moves)

	+ A `strategy` method, which takes the parameters `self`

	and `opponent`, representing both players in the match, and provides

	the algorithm for determining the player’s next move.

If we want, we can also initialise some shorthand for the actions to

avoid having to evoke their full names:

```

>>> R = RPSAction.R

>>> P = RPSAction.P

>>> S = RPSAction.S

```

Here are a couple of examples. One is a strategy which copies the opponent’s

previous move, and the other simply cycles through the moves. Both have

an initialisation parameter for which move they start with:

```

>>> from axelrod.player import Player

>>> class Copycat(Player):

...  """

...  Starts with a chosen move,

...  and then copies their opponent's previous move.

...

...  Parameters

...  ----------

...  starting\_move: RPSAction, default S

...  What move to play on the first round.

...  """

...     name = "Copycat"

...     classifier = {

...         "memory\_depth": 1,

...         "stochastic": False,

...         "long\_run\_time": False,

...         "inspects\_source": False,

...         "manipulates\_source": False,

...         "manipulates\_state": False,

...     }

...

...     def \_\_init\_\_(self, starting\_move=S):

...         self.starting\_move = starting\_move

...         super().\_\_init\_\_()

...

...     def strategy(self, opponent: Player) -> RPSAction:

...  """Actual strategy definition that determines player's action."""

...         if not self.history:

...             return self.starting\_move

...         return opponent.history[-1]

>>> class Rotator(Player):

...  """

...  Cycles through the moves from a chosen starting move.

...

...  Parameters

...  ----------

...  starting\_move: RPSAction, default S

...  What move to play on the first round.

...  """

...     name = "Rotator"

...     classifier = {

...         "memory\_depth": 1,

...         "stochastic": False,

...         "long\_run\_time": False,

...         "inspects\_source": False,

...         "manipulates\_source": False,

...         "manipulates\_state": False,

...     }

...

...     def \_\_init\_\_(self, starting\_move=S):

...         self.starting\_move = starting\_move

...         super().\_\_init\_\_()

...

...     def strategy(self, opponent: Player) -> RPSAction:

...  """Actual strategy definition that determines player's action."""

...         if not self.history:

...             return self.starting\_move

...         return self.history[-1].rotate()

```

We are now all set to run some matches and tournaments in our new game!

Let’s start with a match between our two new players:

```

>>> match = axl.Match(players=(Copycat(starting\_move=P), Rotator()),

...                   turns=5,

...                   game=rock\_paper\_scissors)

>>> match.play()

[(P, S), (S, R), (R, P), (P, S), (S, R)]

```

and as with the Prisoners’ Dilemma, we can run a tournament in the same way. Just

make sure you specify the game when creating the tournament!:

```

>>> tournament = axl.Tournament(players, game=rock\_paper\_scissors)  

>>> tournament.play()  

```

where `players` is set to a list of Rock-Paper-Scissors strategies; hopefully

more than two, else it isn’t a very interesting tournament!

### How to[¶](#how-to "Permalink to this headline")

This section contains short descriptions of how to accomplish specific tasks

with the Axelrod library.

#### Include noise[¶](#include-noise "Permalink to this headline")

A common variation on iterated prisoner’s dilemma tournaments is to add

stochasticity in the choice of actions, simply called noise. This noise is

introduced by flipping plays between C and D with some probability that is

applied to all plays after they are delivered by the player [[Bendor1993]](index.html#bendor1993).

The presence of this persistent background noise causes some strategies to

behave substantially differently. For example, `TitForTat` can fall into

defection loops with itself when there is noise. While `TitForTat` would

usually cooperate well with itself:

```

C C C C C ...

C C C C C ...

```

Noise can cause a C to flip to a D (or vice versa), disrupting the cooperative

chain:

```

C C C D C D C D D D ...

C C C C D C D D D D ...

```

To create a noisy tournament you simply need to add the noise argument:

```

>>> import axelrod as axl

>>> players = [axl.Cooperator(), axl.Defector(),

...            axl.TitForTat(), axl.Grudger()]

>>> noise = 0.1

>>> tournament = axl.Tournament(players, noise=noise)

>>> results = tournament.play()

>>> plot = axl.Plot(results)

>>> p = plot.boxplot()

>>> p.show()

```

[![_images/demo_strategies_noisy_boxplot.svg](_images/demo_strategies_noisy_boxplot.svg)](_images/demo_strategies_noisy_boxplot.svg)

Here is how the distribution of wins now looks:

```

>>> p = plot.winplot()

>>> p.show()

```

[![_images/demo_strategies_noisy_winplot.svg](_images/demo_strategies_noisy_winplot.svg)](_images/demo_strategies_noisy_winplot.svg)

#### Include probabilistic endings[¶](#include-probabilistic-endings "Permalink to this headline")

It is possible to create a tournament where the length of each Match is not

constant for all encounters: after each turn the Match ends with a given

probability, [[Axelrod1980b]](index.html#axelrod1980b):

```

>>> import axelrod as axl

>>> players = [axl.Cooperator(), axl.Defector(),

...            axl.TitForTat(), axl.Grudger()]

>>> tournament = axl.Tournament(players, prob\_end=0.5)

```

We can view the results in a similar way as described in

[Access tournament results](index.html#tournament-results):

```

>>> results = tournament.play()

>>> m = results.payoff\_matrix

>>> for row in m:  

...     print([round(ele, 1) for ele in row]) # Rounding output 

[3.0, 0.0, 3.0, 3.0]

[5.0, 1.0, 3.7, 3.6]

[3.0, 0.3, 3.0, 3.0]

[3.0, 0.4, 3.0, 3.0]

```

We see that `Cooperator` always scores 0 against `Defector` but

other scores seem variable as they are effected by the length of each match.

We can (as before) obtain the ranks for our players:

```

>>> results.ranked\_names  

['Defector', 'Tit For Tat', 'Grudger', 'Cooperator']

```

We can plot the results:

```

>>> plot = axl.Plot(results)

>>> p = plot.boxplot()

>>> p.show()

```

[![_images/prob_end_boxplot.svg](_images/prob_end_boxplot.svg)](_images/prob_end_boxplot.svg)

We can also view the length of the matches played by each player. The plot shows

that the length of each match (for each player) is not the same. The median

length is 4 which is the expected value with the probability of a match ending

being `0.5`.

```

>>> p = plot.lengthplot()

>>> p.show()

```

[![_images/prob_end_lengthplot.svg](_images/prob_end_lengthplot.svg)](_images/prob_end_lengthplot.svg)

#### Create spatial tournaments[¶](#create-spatial-tournaments "Permalink to this headline")

A spatial tournament is defined on a graph where the nodes correspond to players

and edges define whether or not a given player pair will have a match.

The initial work on spatial tournaments was done by Nowak and May in a 1992

paper: [[Nowak1992]](index.html#nowak1992).

Additionally, Szabó and Fáth in their 2007 paper [[Szabo2007]](index.html#szabo2007) consider a variety

of graphs, such as lattices, small world, scale-free graphs and evolving

networks.

Let’s create a tournament where `Cooperator` and `Defector` do not

play each other and neither do `TitForTat` and `Grudger` :

[![_images/spatial.png](_images/spatial.png)](_images/spatial.png)

Note that the edges have to be given as a list of tuples of player

indices:

```

>>> import axelrod as axl

>>> players = [axl.Cooperator(), axl.Defector(),

...            axl.TitForTat(), axl.Grudger()]

>>> edges = [(0, 2), (0, 3), (1, 2), (1, 3)]

```

To create a spatial tournament you pass the `edges` to the

`Tournament` class:

```

>>> spatial\_tournament = axl.Tournament(players, edges=edges)

>>> results = spatial\_tournament.play()

```

We can plot the results:

```

>>> plot = axl.Plot(results)

>>> p = plot.boxplot()

>>> p.show()

```

[![_images/spatial_results.png](_images/spatial_results.png)](_images/spatial_results.png)

We can, like any other tournament, obtain the ranks for our players:

```

>>> results.ranked\_names

['Cooperator', 'Tit For Tat', 'Grudger', 'Defector']

```

Let’s run a small tournament of 2 `turns` and 2 `repetitions`

and obtain the interactions:

```

>>> spatial\_tournament = axl.Tournament(players ,turns=2, repetitions=2, edges=edges)

>>> results = spatial\_tournament.play()

>>> results.payoffs

[[[], [], [3.0, 3.0], [3.0, 3.0]], [[], [], [3.0, 3.0], [3.0, 3.0]], [[3.0, 3.0], [0.5, 0.5], [], []], [[3.0, 3.0], [0.5, 0.5], [], []]]

```

As anticipated not all players interact with each other.

It is also possible to create a probabilistic ending spatial tournament:

```

>>> prob\_end\_spatial\_tournament = axl.Tournament(players, edges=edges, prob\_end=.1, repetitions=1, seed=10)

>>> prob\_end\_results = prob\_end\_spatial\_tournament.play()

```

We see that the match lengths are no longer all equal:

```

>>> prob\_end\_results.match\_lengths

[[[0, 0, 20.0, 1.0], [0, 0, 46.0, 13.0], [20.0, 46.0, 0, 0], [1.0, 13.0, 0, 0]]]

```

#### Create Moran Processes On Graphs[¶](#create-moran-processes-on-graphs "Permalink to this headline")

The library also provides a graph-based Moran process [[Shakarian2013]](index.html#shakarian2013) with

`MoranProcess`. To use this feature you must supply at least one

`Axelrod.graph.Graph` object, which can be initialized with just a list of

edges:

```

edges = [(source\_1, target1), (source2, target2), ...]

```

The nodes can be any hashable object (integers, strings, etc.). For example:

```

>>> import axelrod as axl

>>> from axelrod.graph import Graph

>>> edges = [(0, 1), (1, 2), (2, 3), (3, 1)]

>>> graph = Graph(edges)

```

Graphs are undirected by default but you can pass `directed=True` to

create a directed graph. Various intermediates such as the list of neighbors

are cached for efficiency by the graph object.

A Moran process can be invoked with one or two graphs. The first graph, the

*interaction graph*, dictates how players are matched up in the scoring phase.

Each player plays a match with each neighbor. The second graph dictates how

players replace another during reproduction. When an individual is selected to

reproduce, it replaces one of its neighbors in the *reproduction graph*. If only

one graph is supplied to the process, the two graphs are assumed to be the same.

To create a graph-based Moran process, use a graph as follows:

```

>>> from axelrod.graph import Graph

>>> edges = [(0, 1), (1, 2), (2, 3), (3, 1)]

>>> graph = Graph(edges)

>>> players = [axl.Cooperator(), axl.Cooperator(), axl.Cooperator(), axl.Defector()]

>>> mp = axl.MoranProcess(players, interaction\_graph=graph, seed=40)

>>> results = mp.play()

>>> mp.population\_distribution()

Counter({'Defector': 4})

```

You can supply the `reproduction\_graph` as a keyword argument. The

standard Moran process is equivalent to using a complete graph with no loops

for the `interaction\_graph` and with loops for the

`reproduction\_graph`.

#### Create Approximate Moran Process[¶](#create-approximate-moran-process "Permalink to this headline")

Due to the high computational cost of a single Moran process, an approximate

Moran process is implemented that can make use of cached outcomes of games. The

following code snippet will generate a Moran process in which the outcomes of

the matches played by a `Random: 0.5` are sampled from one possible

outcome against each opponent (`Defector` and `Random: 0.5`). First

the cache is built by passing counter objects of outcomes:

```

>>> import axelrod as axl

>>> from collections import Counter

>>> cached\_outcomes = {}

>>> cached\_outcomes[("Random: 0.5", "Defector")] = axl.Pdf(Counter([(1, 1)]))

>>> cached\_outcomes[("Random: 0.5", "Random: 0.5")] = axl.Pdf(Counter([(3, 3)]))

>>> cached\_outcomes[("Defector", "Defector")] = axl.Pdf(Counter([(1, 1)]))

```

Now let us create an Approximate Moran Process:

```

>>> players = [axl.Defector(), axl.Random(), axl.Random()]

>>> amp = axl.ApproximateMoranProcess(players, cached\_outcomes, seed=5)

>>> results = amp.play()

>>> amp.population\_distribution()

Counter({'Random: 0.5': 3})

```

Note that by nature of being an approximation, it’s possible that the results of an

ApproximateMoranProcess may not always match the results of a standard MoranProcess,

even for the same random seed. We see that, for this random seed, the `Random: 0.5`

won this Moran process. This is not what happens in a standard Moran process where the

`Random: 0.5` player will not win:

```

>>> mp = axl.MoranProcess(players, seed=5)

>>> results = mp.play()

>>> mp.population\_distribution()

Counter({'Defector': 3})

```

#### Calculate Morality Metrics[¶](#calculate-morality-metrics "Permalink to this headline")

Tyler Singer-Clark’s June 2014 paper, “Morality Metrics On Iterated Prisoner’s

Dilemma Players” [[Singer-Clark2014]](index.html#singer-clark2014)), describes several interesting metrics which

may be used to analyse IPD tournaments all of which are available within the

ResultSet class. (Tyler’s paper is available here:

<http://www.scottaaronson.com/morality.pdf>).

Each metric depends upon the cooperation rate of the players, defined by Tyler

Singer-Clark as:

\[CR(b) = \frac{C(b)}{TT}\]

where C(b) is the total number of turns where a player chose to cooperate and TT

is the total number of turns played.

A matrix of cooperation rates is available within a tournament’s ResultSet:

```

>>> import axelrod as axl

>>> players = [axl.Cooperator(), axl.Defector(),

...            axl.TitForTat(), axl.Grudger()]

>>> tournament = axl.Tournament(players)

>>> results = tournament.play()

>>> [[round(float(ele), 3) for ele in row] for row in results.normalised\_cooperation]

[[1.0, 1.0, 1.0, 1.0], [0.0, 0.0, 0.0, 0.0], [1.0, 0.005, 1.0, 1.0], [1.0, 0.005, 1.0, 1.0]]

```

There is also a ‘good partner’ matrix showing how often a player cooperated at

least as much as its opponent:

```

>>> results.good\_partner\_matrix

[[0, 10, 10, 10], [0, 0, 0, 0], [10, 10, 0, 10], [10, 10, 10, 0]]

```

Each of the metrics described in Tyler’s paper is available as follows (here they are rounded to 2 digits):

```

>>> [round(ele, 2) for ele in results.cooperating\_rating]

[1.0, 0.0, 0.67..., 0.67...]

>>> [round(ele, 2) for ele in results.good\_partner\_rating]

[1.0, 0.0, 1.0, 1.0]

>>> [round(ele, 2) for ele in results.eigenjesus\_rating]

[0.58, 0.0, 0.58, 0.58]

>>> [round(ele, 2) for ele in results.eigenmoses\_rating]

[0.37, -0.37, 0.6, 0.6]

```

#### Run Axelrod’s Ecological Variant[¶](#run-axelrod-s-ecological-variant "Permalink to this headline")

In Axelrod’s original work an ecological approach based on the payoff matrix of

the tournament was used to study the evolutionary stability of each strategy.

Whilst this bears some comparison to the [Moran Process](index.html#moran-process), the latter is

much more widely used in the literature.

To study the evolutionary stability of each strategy it is possible to create an

ecosystem based on the payoff matrix of a tournament:

```

>>> import axelrod as axl

>>> players = [axl.Cooperator(), axl.Defector(),

...            axl.TitForTat(), axl.Grudger(),

...            axl.Random()]

>>> tournament = axl.Tournament(players)

>>> results = tournament.play()

>>> eco = axl.Ecosystem(results)

>>> eco.reproduce(100) # Evolve the population over 100 time steps

```

Here is how we obtain a nice stackplot of the system evolving over time:

```

>>> plot = axl.Plot(results)

>>> p = plot.stackplot(eco)

>>> p.show()

```

[![_images/demo_strategies_stackplot.svg](_images/demo_strategies_stackplot.svg)](_images/demo_strategies_stackplot.svg)

#### Fingerprint[¶](#fingerprint "Permalink to this headline")

##### Ashlock Fingerprints[¶](#ashlock-fingerprints "Permalink to this headline")

In [[Ashlock2008]](index.html#ashlock2008), [[Ashlock2009]](index.html#ashlock2009) a methodology for obtaining visual

representation of a strategy’s behaviour is described. The basic method is to

play the strategy against a probe strategy with varying noise parameters.

These noise parameters are implemented through the `JossAnnTransformer`.

The Joss-Ann of a strategy is a new strategy which has a probability `x`

of cooperating, a probability `y` of defecting, and otherwise uses the

response appropriate to the original strategy. We can then plot the expected

score of the strategy against `x` and `y` and obtain a heat plot

over the unit square. When `x + y >= 1` the `JossAnn` is created

with parameters `(1-y, 1-x)` and plays against the Dual of the probe

instead. A full definition and explanation is given in

[[Ashlock2008]](index.html#ashlock2008), [[Ashlock2009]](index.html#ashlock2009).

Here is how to create a fingerprint of `WinStayLoseShift` using

`TitForTat` as a probe:

```

>>> import axelrod as axl

>>> strategy = axl.WinStayLoseShift

>>> probe = axl.TitForTat

>>> af = axl.AshlockFingerprint(strategy, probe)

>>> data = af.fingerprint(turns=10, repetitions=2, step=0.2, seed=1)

>>> data

{...

>>> data[(0, 0)]

3.0

```

The `fingerprint` method returns a dictionary mapping coordinates of the

form `(x, y)` to the mean score for the corresponding interactions.

We can then plot the above to get:

```

>>> p = af.plot()

>>> p.show()

```

[![_images/WSLS_small.png](_images/WSLS_small.png)](_images/WSLS_small.png)

In reality we would need much more detail to make this plot useful.

Running the above with the following parameters:

```

>>> af.fingerprint(turns=50, repetitions=2, step=0.01)  

```

We get the plot:

[![_images/WSLS_large.png](_images/WSLS_large.png)](_images/WSLS_large.png)

We are also able to specify a matplotlib colour map, interpolation and can

remove the colorbar and axis labels:

```

>>> p = af.plot(cmap='PuOr', interpolation='bicubic', colorbar=False, labels=False)  

>>> p.show()

```

[![_images/WSLS_large_alt.png](_images/WSLS_large_alt.png)](_images/WSLS_large_alt.png)

Note that it is also possible to pass a player instance to be fingerprinted

and/or as a probe.

This allows for the fingerprinting of parametrized strategies:

```

>>> player = axl.Random(p=.1)

>>> probe = axl.GTFT(p=.9)

>>> af = axl.AshlockFingerprint(player, probe)

>>> data = af.fingerprint(turns=10, repetitions=2, step=0.2, seed=2)

>>> data

{...

>>> data[(0, 0)]

3.75

```

##### Transitive Fingerprint[¶](#transitive-fingerprint "Permalink to this headline")

Another implemented fingerprint is the transitive fingerprint. The

transitive fingerprint represents the cooperation rate of a strategy against a

set of opponents over a number of turns.

By default the set of opponents consists of `50` Random players that

cooperate with increasing probability. This is how to obtain the transitive

fingerprint for `TitForTat`:

```

>>> player = axl.TitForTat()

>>> tf = axl.TransitiveFingerprint(player)

>>> data = tf.fingerprint(turns=40, seed=3)

```

The data produced is a `numpy` array showing the cooperation rate against

a given opponent (row) in a given turn (column):

```

>>> data.shape

(50, 40)

```

It is also possible to visualise the fingerprint:

```

>>> p = tf.plot()

>>> p.show()

```

[![_images/transitive_TFT.png](_images/transitive_TFT.png)](_images/transitive_TFT.png)

It is also possible to fingerprint against a given set of opponents:

```

>>> opponents = [s() for s in axl.demo\_strategies]

>>> tf = axl.TransitiveFingerprint(player, opponents=opponents)

>>> data = tf.fingerprint(turns=5, repetitions=10, seed=4)

```

The name of the opponents can be displayed in the plot:

```

>>> p = tf.plot(display\_names=True)

>>> p.show()

```

[![_images/transitive_TFT_against_demo.png](_images/transitive_TFT_against_demo.png)](_images/transitive_TFT_against_demo.png)

#### Evolve Players[¶](#evolve-players "Permalink to this headline")

Several strategies in the library derive from `EvolvablePlayer` which specifies methods

allowing evolutionary or particle swarm algorithms to be used with these strategies. The

[Axelrod Dojo library](https://github.com/Axelrod-Python/axelrod-dojo) [[Axelrod1980]](index.html#axelrod1980)

contains implementations of both algorithms for use with the Axelrod library. Examples include

FSMPlayers, ANN (neural networks), and LookerUp and Gambler (lookup tables).

New `EvolvablePlayer` subclasses can be added to the library. Any strategy that can

define `mutation` and `crossover` methods can be used with the evolutionary algorithm

and the atomic mutation version of the Moran process. To use the particle swarm algorithms, methods

to serialize the strategy to and from a vector of floats must be defined.

##### Moran Process: Atomic Mutation for Evolvable Players[¶](#moran-process-atomic-mutation-for-evolvable-players "Permalink to this headline")

Additionally, the Moran process implementation supports a second style of mutation suitable for

evolving new strategies utilizing the `EvolvablePlayer` class via its `mutate` method.

This is in contrast to the transitional mutation that selects one of the other player types rather than (possibly)

generating a new player variant. To use this mutation style set mutation\_method=atomic in the initialisation

of the Moran process:

```

>>> import axelrod as axl

>>> C = axl.Action.C

>>> players = [axl.EvolvableFSMPlayer(num\_states=2, initial\_state=1, initial\_action=C) for \_ in range(5)]

>>> mp = axl.MoranProcess(players, turns=10, mutation\_method="atomic", seed=1)

>>> population = mp.play()  

```

Note that this may cause the Moran process to fail to converge, if the mutation rates are very high or the

population size very large. See [Moran Process](index.html#moran-process) for more information.

##### Reproducible Seeding[¶](#reproducible-seeding "Permalink to this headline")

`EvolvablePlayers` are inherently stochastic. For reproducibility of results, they can be seeded. When

using the Moran process, a process level seed is sufficient. Child seeds will be created and propagated

in a reproducible way. If initialized without a seed, an `EvolvablePlayer` will be given a

random seed in a non-reproducible way.

#### Access collections of strategies[¶](#access-collections-of-strategies "Permalink to this headline")

All of the strategies are accessible from the main name space of the library.

For example:

```

>>> import axelrod as axl

>>> axl.TitForTat()

Tit For Tat

>>> axl.Cooperator()

Cooperator

```

The **main strategies** which obey the rules of Axelrod’s original tournament

can be found in a list: axelrod.strategies:

```

>>> axl.strategies

[...

```

This makes creating a full

tournament very straightforward:

```

>>> players = [s() for s in axl.strategies]

>>> tournament = axl.Tournament(players)

```

There are a list of various other strategies in the library to make it

easier to create a variety of tournaments:

```

>>> axl.demo\_strategies  # 5 simple strategies useful for demonstration.

[...

>>> axl.basic\_strategies  # A set of basic strategies.

[...

>>> axl.long\_run\_time\_strategies  # These have a high computational cost

[...

```

Furthermore there are some strategies that ‘cheat’ (for example by modifying

their opponents source code). These can be found in

`axelrod.cheating\_strategies`:

```

>>> axl.cheating\_strategies

[...

```

All of the strategies in the library are contained in:

`axelrod.all\_strategies`:

```

>>> axl.all\_strategies

[...

```

All strategies are also classified, you can read more about that in

[Classification of strategies](index.html#classification-of-strategies).

#### Classification of strategies[¶](#classification-of-strategies "Permalink to this headline")

Due to the large number of strategies, every class and instance of the class has

a `classifier` attribute which classifies that strategy according to

various dimensions.

Here is the `classifier` for the `Cooperator` strategy:

```

>>> import axelrod as axl

>>> expected\_dictionary = {

...    'manipulates\_state': False,

...    'long\_run\_time': False,

...    'stochastic': False,

...    'manipulates\_source': False,

...    'inspects\_source': False,

...    'memory\_depth': 0

... }  # Order of this dictionary might be different on your machine

>>> axl.Cooperator.classifier == expected\_dictionary

True

```

Note that instances of the class also have this classifier:

```

>>> s = axl.Cooperator()

>>> s.classifier == expected\_dictionary

True

```

The instance starts with a copy of the class’s classifier dictionary, but is

allowed to change this classifier dictionary at any point, and many

strategies do so upon initialization.

In addition to the classifier dictionary, each classifier is defined with

some logic that maps classifier definitions to values. To learn the

classification of a strategy, we first look in the strategy’s classifier

dictionary, then if the key is not present, then we refer to this logic.

This logic must be defined for a class, and not specific instances.

To lookup the classifier of a strategy, using the classifier dict, or the

strategy’s logic as default, we use `Classifiers[<classifier>](

<strategy>)`:

```

>>> from axelrod import Classifiers

>>> Classifiers['memory\_depth'](axl.TitForTat())

1

>>> Classifiers['stochastic'](axl.Random())

True

```

We can use this classification to generate sets of strategies according to

filters which we define in a ‘filterset’ dictionary and then pass to the

‘filtered\_strategies’ function. For example, to identify all the stochastic

strategies:

```

>>> filterset = {

...     'stochastic': True

... }

>>> strategies = axl.filtered\_strategies(filterset)

>>> len(strategies)

88

```

Or, to find out how many strategies only use 1 turn worth of memory to

make a decision:

```

>>> filterset = {

...     'memory\_depth': 1

... }

>>> strategies = axl.filtered\_strategies(filterset)

>>> len(strategies)

33

```

Multiple filters can be specified within the filterset dictionary. To specify a

range of memory\_depth values, we can use the ‘min\_memory\_depth’ and

‘max\_memory\_depth’ filters:

```

>>> filterset = {

...     'min\_memory\_depth': 1,

...     'max\_memory\_depth': 4

... }

>>> strategies = axl.filtered\_strategies(filterset)

>>> len(strategies)

57

```

We can also identify strategies that make use of particular properties of the

tournament. For example, here is the number of strategies that make use of the

length of each match of the tournament:

```

>>> filterset = {

...     'makes\_use\_of': ['length']

... }

>>> strategies = axl.filtered\_strategies(filterset)

>>> len(strategies)

22

```

Note that in the filterset dictionary, the value for the ‘makes\_use\_of’ key

must be a list. Here is how we might identify the number of strategies that use

both the length of the tournament and the game being played:

```

>>> filterset = {

...     'makes\_use\_of': ['length', 'game']

... }

>>> strategies = axl.filtered\_strategies(filterset)

>>> len(strategies)

15

```

Some strategies have been classified as having a particularly long run time:

```

>>> filterset = {

...     'long\_run\_time': True

... }

>>> strategies = axl.filtered\_strategies(filterset)

>>> len(strategies)

18

```

Strategies that `manipulate\_source`, `manipulate\_state`

and/or `inspect\_source` return `False` for the

`Classifier.obey\_axelrod` function:

```

>>> s = axl.Darwin()

>>> axl.Classifiers.obey\_axelrod(s)

False

>>> s = axl.TitForTat()

>>> axl.Classifiers.obey\_axelrod(s)

True

```

#### Strategy Transformers[¶](#strategy-transformers "Permalink to this headline")

##### What is a Strategy Transformer?[¶](#what-is-a-strategy-transformer "Permalink to this headline")

A strategy transformer is a function that modifies an existing strategy. For

example, `FlipTransformer` takes a strategy and flips the actions from

C to D and D to C:

```

>>> import axelrod as axl

>>> from axelrod.strategy\_transformers import \*

>>> FlippedCooperator = FlipTransformer()(axl.Cooperator)

>>> player = FlippedCooperator()

>>> opponent = axl.Cooperator()

>>> player.strategy(opponent)

D

>>> opponent.strategy(player)

C

```

Our player was switched from a `Cooperator` to a `Defector` when

we applied the transformer. The transformer also changed the name of the

class and player:

```

>>> player.name

'Flipped Cooperator'

>>> FlippedCooperator.name

'Flipped Cooperator'

```

This behavior can be suppressed by setting the `name\_prefix` argument:

```

>>> FlippedCooperator = FlipTransformer(name\_prefix=None)(axl.Cooperator)

>>> player = FlippedCooperator()

>>> player.name

'Cooperator'

```

Note carefully that the transformer returns a class, not an instance of a class.

This means that you need to use the Transformed class as you would normally to

create a new instance:

```

>>> from axelrod.strategy\_transformers import NoisyTransformer

>>> player = NoisyTransformer(0.5)(axl.Cooperator)()

```

rather than `NoisyTransformer(0.5)(axl.Cooperator())` or just `NoisyTransformer(0.5)(axl.Cooperator)`.

##### Included Transformers[¶](#included-transformers "Permalink to this headline")

The library includes the following transformers:

* `ApologyTransformer`: Apologizes after a round of `(D, C)`:

```

 >>> ApologizingDefector = ApologyTransformer([D], [C])(axl.Defector)

 >>> player = ApologizingDefector()

You can pass any two sequences in. In this example the player would apologize

after two consequtive rounds of `(D, C)`::

    >>> ApologizingDefector = ApologyTransformer([D, D], [C, C])(axl.Defector)

    >>> player = ApologizingDefector()

```

* `DeadlockBreakingTransformer`: Attempts to break `(D, C) -> (C, D)` deadlocks by cooperating:

```

>>> DeadlockBreakingTFT = DeadlockBreakingTransformer()(axl.TitForTat)

>>> player = DeadlockBreakingTFT()

```

* `DualTransformer`: The Dual of a strategy will return the exact opposite set of moves to the original strategy when both are faced with the same history. [[Ashlock2008]](index.html#ashlock2008):

```

>>> DualWSLS = DualTransformer()(axl.WinStayLoseShift)

>>> player = DualWSLS()

```

* `FlipTransformer`: Flips all actions:

```

>>> FlippedCooperator = FlipTransformer()(axl.Cooperator)

>>> player = FlippedCooperator()

```

* `FinalTransformer(seq=None)`: Ends the tournament with the moves in the sequence `seq`, if the tournament\_length is known. For example, to obtain a cooperator that defects on the last two rounds:

```

>>> FinallyDefectingCooperator = FinalTransformer([D, D])(axl.Cooperator)

>>> player = FinallyDefectingCooperator()

```

* `ForgiverTransformer(p)`: Flips defections with probability `p`:

```

>>> ForgivinDefector = ForgiverTransformer(0.1)(axl.Defector)

>>> player = ForgivinDefector()

```

* `GrudgeTransformer(N)`: Defections unconditionally after more than N defections:

```

>>> GrudgingCooperator = GrudgeTransformer(2)(axl.Cooperator)

>>> player = GrudgingCooperator()

```

* `InitialTransformer(seq=None)`: First plays the moves in the sequence `seq`, then plays as usual. For example, to obtain a defector that cooperates on the first two rounds:

```

>>> InitiallyCooperatingDefector = InitialTransformer([C, C])(axl.Defector)

>>> player = InitiallyCooperatingDefector()

```

* `JossAnnTransformer(probability)`: Where `probability = (x, y)`, the Joss-Ann of a strategy is a new strategy which has a probability `x` of choosing the move C, a probability `y` of choosing the move D, and otherwise uses the response appropriate to the original strategy. [[Ashlock2008]](index.html#ashlock2008):

```

>>> JossAnnTFT = JossAnnTransformer((0.2, 0.3))(axl.TitForTat)

>>> player = JossAnnTFT()

```

* `MixedTransformer`: Randomly plays a mutation to another strategy (or

set of strategies. Here is the syntax to do this with a set of strategies:

```

>>> strategies = [axl.Grudger, axl.TitForTat]

>>> probability = [.2, .3]  # .5 chance of mutated to one of above

>>> player =  MixedTransformer(probability, strategies)(axl.Cooperator)

```

Here is the syntax when passing a single strategy:

```

>>> strategy = axl.Grudger

>>> probability = .2

>>> player =  MixedTransformer(probability, strategy)(axl.Cooperator)

```

* `NiceTransformer()`: Prevents a strategy from defecting if the opponent

has not yet defected:

```

>>> NiceDefector = NiceTransformer()(axl.Defector)

>>> player = NiceDefector()

```

* `NoisyTransformer(noise)`: Flips actions with probability `noise`:

```

>>> NoisyCooperator = NoisyTransformer(0.5)(axl.Cooperator)

>>> player = NoisyCooperator()

```

* `RetaliationTransformer(N)`: Retaliation N times after a defection:

```

>>> TwoTitsForTat = RetaliationTransformer(2)(axl.Cooperator)

>>> player = TwoTitsForTat()

```

* `RetaliateUntilApologyTransformer()`: adds TitForTat-style retaliation:

```

>>> TFT = RetaliateUntilApologyTransformer()(axl.Cooperator)

>>> player = TFT()

```

* `TrackHistoryTransformer`: Tracks History internally in the

`Player` instance in a variable `\_recorded\_history`. This allows a

player to e.g. detect noise.:

```

>>> player = TrackHistoryTransformer()(axl.Random)()

```

##### Composing Transformers[¶](#composing-transformers "Permalink to this headline")

Transformers can be composed to form new composers, in two ways. You can

simply chain together multiple transformers:

```

>>> cls1 = FinalTransformer([D,D])(InitialTransformer([D,D])(axl.Cooperator))

>>> p1 = cls1()

```

This defines a strategy that cooperates except on the first two and last two

rounds. Alternatively, you can make a new class using

`compose\_transformers`:

```

>>> cls1 = compose\_transformers(FinalTransformer([D, D]), InitialTransformer([D, D]))

>>> p1 = cls1(axl.Cooperator)()

>>> p2 = cls1(axl.Defector)()

```

##### Usage as Class Decorators[¶](#usage-as-class-decorators "Permalink to this headline")

Transformers can also be used to decorate existing strategies. For example,

the strategy `BackStabber` defects on the last two rounds. We can encode this

behavior with a transformer as a class decorator:

```

@FinalTransformer([D, D]) # End with two defections

class BackStabber(Player):

 """

 Forgives the first 3 defections but on the fourth

 will defect forever. Defects on the last 2 rounds unconditionally.

 """

    name = 'BackStabber'

    classifier = {

        'memory\_depth': float('inf'),

        'stochastic': False,

        'inspects\_source': False,

        'manipulates\_source': False,

        'manipulates\_state': False

    }

    def strategy(self, opponent):

        if not opponent.history:

            return C

        if opponent.defections > 3:

            return D

        return C

```

##### Writing New Transformers[¶](#writing-new-transformers "Permalink to this headline")

To make a new transformer, you need to define a strategy wrapping function with

the following signature:

```

def strategy\_wrapper(player, opponent, proposed\_action, \*args, \*\*kwargs):

 """

 Strategy wrapper functions should be of the following form.

 Parameters

 ----------

 player: Player object or subclass (self)

 opponent: Player object or subclass

 proposed\_action: an axelrod.Action, C or D

 The proposed action by the wrapped strategy

 proposed\_action = Player.strategy(...)

 args, kwargs:

 Any additional arguments that you need.

 Returns

 -------

 action: an axelrod.Action, C or D

 """

    # This example just passes through the proposed\_action

    return proposed\_action

```

The proposed action will be the outcome of:

```

self.strategy(player)

```

in the underlying class (the one that is transformed). The strategy\_wrapper still

has full access to the player and the opponent objects and can have arguments.

To make a transformer from the `strategy\_wrapper` function, use

`StrategyTransformerFactory`, which has signature:

```

def StrategyTransformerFactory(strategy\_wrapper, name\_prefix=""):

 """Modify an existing strategy dynamically by wrapping the strategy

 method with the argument `strategy\_wrapper`.

 Parameters

 ----------

 strategy\_wrapper: function

 A function of the form `strategy\_wrapper(player, opponent, proposed\_action, \*args, \*\*kwargs)`

 Can also use a class that implements

 def \_\_call\_\_(self, player, opponent, action)

 name\_prefix: string, "Transformed "

 A string to prepend to the strategy and class name

 """

```

So we use `StrategyTransformerFactory` with `strategy\_wrapper`:

```

TransformedClass = StrategyTransformerFactory(generic\_strategy\_wrapper)

Cooperator2 = TransformedClass(\*args, \*\*kwargs)(axl.Cooperator)

```

If your wrapper requires no arguments, you can simply proceed as follows:

```

>>> TransformedClass = StrategyTransformerFactory(generic\_strategy\_wrapper)()

>>> Cooperator2 = TransformedClass(axl.Cooperator)

```

For more examples, see `axelrod/strategy\_transformers.py`.

#### Access tournament results[¶](#access-tournament-results "Permalink to this headline")

This tutorial will show you how to access the various results of a tournament:

* Wins: the number of matches won by each player

* Match lengths: the number of turns of each match played by each player

(relevant for tournaments with probabilistic ending).

* Scores: the total scores of each player.

* Normalised scores: the scores normalised by matches played and turns.

* Ranking: ranking of players based on median score.

* Ranked names: names of players in ranked order.

* Payoffs: average payoff per turn of each player.

* Payoff matrix: the payoff matrix showing the payoffs of each row player

against each column player.

* Payoff standard deviation: the standard deviation of the payoffs matrix.

* Score differences: the score difference between each player.

* Payoff difference means: the mean score differences.

* Cooperation counts: the number of times each player cooperated.

* Normalised cooperation: cooperation count per turn.

* Normalised cooperation: cooperation count per turn.

* State distribution: the count of each type of state of a match

* Normalised state distribution: the normalised count of each type of state of a

match

* State to action distribution: the count of each type of state to action pair

of a match

* Normalised state distribution: the normalised count of each type of state to

action pair of a match

* Initial cooperation count: the count of initial cooperation by each player.

* Initial cooperation rate: the rate of initial cooperation by each player.

* Cooperation rating: cooperation rating of each player

* Vengeful cooperation: a morality metric from the literature (see

[Calculate Morality Metrics](index.html#morality-metrics)).

* Good partner matrix: a morality metric from [[Singer-Clark2014]](index.html#singer-clark2014).

* Good partner rating: a morality metric from [[Singer-Clark2014]](index.html#singer-clark2014).

* Eigenmoses rating: a morality metric from [[Singer-Clark2014]](index.html#singer-clark2014).

* Eigenjesus rating: a morality metric from [[Singer-Clark2014]](index.html#singer-clark2014).

As shown in [Creating and running a simple tournament](index.html#creating-tournaments) let us create a tournament:

```

>>> import axelrod as axl

>>> players = [axl.Cooperator(), axl.Defector(),

...            axl.TitForTat(), axl.Grudger()]

>>> tournament = axl.Tournament(players, turns=10, repetitions=3)

>>> results = tournament.play()

```

##### Wins[¶](#wins "Permalink to this headline")

This gives the number of wins obtained by each player:

```

>>> results.wins

[[0, 0, 0], [3, 3, 3], [0, 0, 0], [0, 0, 0]]

```

The `Defector` is the only player to win any matches (all other matches

are ties).

##### Match lengths[¶](#match-lengths "Permalink to this headline")

This gives the length of the matches played by each player:

```

>>> import pprint  # Nicer formatting of output

>>> pprint.pprint(results.match\_lengths)

[[[10.0, 10.0, 10.0, 10.0],

 [10.0, 10.0, 10.0, 10.0],

 [10.0, 10.0, 10.0, 10.0],

 [10.0, 10.0, 10.0, 10.0]],

 [[10.0, 10.0, 10.0, 10.0],

 [10.0, 10.0, 10.0, 10.0],

 [10.0, 10.0, 10.0, 10.0],

 [10.0, 10.0, 10.0, 10.0]],

 [[10.0, 10.0, 10.0, 10.0],

 [10.0, 10.0, 10.0, 10.0],

 [10.0, 10.0, 10.0, 10.0],

 [10.0, 10.0, 10.0, 10.0]]]

```

Every player plays 10 turns against every other player (including themselves)

for every repetition of the tournament.

##### Scores[¶](#scores "Permalink to this headline")

This gives all the total tournament scores (per player and per repetition):

```

>>> results.scores

[[60, 60, 60], [78, 78, 78], [69, 69, 69], [69, 69, 69]]

```

##### Normalised scores[¶](#normalised-scores "Permalink to this headline")

This gives the scores, averaged per opponent and turns:

```

>>> results.normalised\_scores  

[[2.0, 2.0, 2.0], [2.6, 2.6, 2.6], [2.3, 2.3, 2.3], [2.3, 2.3, 2.3]]

```

We see that Cooperator got on average a score of 2 per turn per opponent:

```

>>> results.normalised\_scores[0]

[2.0, 2.0, 2.0]

```

##### Ranking[¶](#ranking "Permalink to this headline")

This gives the ranked index of each player:

```

>>> results.ranking

[1, 2, 3, 0]

```

The first player has index 1 (`Defector`) and the last has index 0

(`Cooperator`).

##### Ranked names[¶](#ranked-names "Permalink to this headline")

This gives the player names in ranked order:

```

>>> results.ranked\_names

['Defector', 'Tit For Tat', 'Grudger', 'Cooperator']

```

##### Payoffs[¶](#payoffs "Permalink to this headline")

This gives for each player, against each opponent every payoff received for

each repetition:

```

>>> pprint.pprint(results.payoffs)  

[[[3.0, 3.0, 3.0], [0.0, 0.0, 0.0], [3.0, 3.0, 3.0], [3.0, 3.0, 3.0]],

 [[5.0, 5.0, 5.0], [1.0, 1.0, 1.0], [1.4, 1.4, 1.4], [1.4, 1.4, 1.4]],

 [[3.0, 3.0, 3.0], [0.9, 0.9, 0.9], [3.0, 3.0, 3.0], [3.0, 3.0, 3.0]],

 [[3.0, 3.0, 3.0], [0.9, 0.9, 0.9], [3.0, 3.0, 3.0], [3.0, 3.0, 3.0]]]

```

##### Payoff matrix[¶](#payoff-matrix "Permalink to this headline")

This gives the mean payoff of each player against every opponent:

```

>>> pprint.pprint(results.payoff\_matrix)  

[[3.0, 0.0, 3.0, 3.0],

 [5.0, 1.0, 1.4, 1.4],

 [3.0, 0.9, 3.0, 3.0],

 [3.0, 0.9, 3.0, 3.0]]

```

We see that the `Cooperator` gets a mean score of 3 against all players

except the `Defector`:

```

>>> results.payoff\_matrix[0]

[3.0, 0.0, 3.0, 3.0]

```

##### Payoff standard deviation[¶](#payoff-standard-deviation "Permalink to this headline")

This gives the standard deviation of the payoff of each player against

every opponent:

```

>>> pprint.pprint(results.payoff\_stddevs)  

[[0.0, 0.0, 0.0, 0.0],

 [0.0, 0.0, 2.2, 2.2],

 [0.0, 0.0, 0.0, 0.0],

 [0.0, 0.0, 0.0, 0.0]]

```

We see that there is no variation for the payoff for `Cooperator`:

```

>>> results.payoff\_stddevs[0]

[0.0, 0.0, 0.0, 0.0]

```

##### Score differences[¶](#score-differences "Permalink to this headline")

This gives the score difference for each player against each opponent for every

repetition:

```

>>> pprint.pprint(results.score\_diffs)  

[[[0.0, 0.0, 0.0], [-5.0, -5.0, -5.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]],

 [[5.0, 5.0, 5.0], [0.0, 0.0, 0.0], [0.5, 0.5, 0.5], [0.5, 0.5, 0.5]],

 [[0.0, 0.0, 0.0], [-0.5, -0.5, -0.5], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]],

 [[0.0, 0.0, 0.0], [-0.5, -0.5, -0.5], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]]]

```

We see that `Cooperator` has no difference in score with all players

except against the `Defector`:

```

>>> results.score\_diffs[0][1]

[-5.0, -5.0, -5.0]

```

##### Payoff difference means[¶](#payoff-difference-means "Permalink to this headline")

This gives the mean payoff differences over each repetition:

```

>>> pprint.pprint(results.payoff\_diffs\_means)  

[[0.0, -5.0, 0.0, 0.0],

 [5.0, 0.0, 0.49999999999999983, 0.49999999999999983],

 [0.0, -0.49999999999999983, 0.0, 0.0],

 [0.0, -0.49999999999999983, 0.0, 0.0]]

```

Here is the mean payoff difference for the `Cooperator` strategy, shows

that it has no difference with all players except against the

`Defector`:

```

>>> results.payoff\_diffs\_means[0]

[0.0, -5.0, 0.0, 0.0]

```

##### Cooperation counts[¶](#cooperation-counts "Permalink to this headline")

This gives a total count of cooperation for each player against each opponent:

```

>>> results.cooperation

[[30, 30, 30, 30], [0, 0, 0, 0], [30, 3, 30, 30], [30, 3, 30, 30]]

```

##### Normalised cooperation[¶](#normalised-cooperation "Permalink to this headline")

This gives the average rate of cooperation against each opponent:

```

>>> pprint.pprint(results.normalised\_cooperation)  

[[1.0, 1.0, 1.0, 1.0],

 [0.0, 0.0, 0.0, 0.0],

 [1.0, 0.1, 1.0, 1.0],

 [1.0, 0.1, 1.0, 1.0]]

```

We see that `Cooperator` for all the rounds (as expected):

```

>>> results.normalised\_cooperation[0]

[1.0, 1.0, 1.0, 1.0]

```

##### State distribution counts[¶](#state-distribution-counts "Permalink to this headline")

This gives a total state count against each opponent. A state corresponds to 1

turn of a match and can be one of `(C, C), (C, D), (D, C),

(D, D)` where the first element is the action of the player in question and

the second the action of the opponent:

```

>>> pprint.pprint(results.state\_distribution)

[[Counter(),

 Counter({(C, D): 30}),

 Counter({(C, C): 30}),

 Counter({(C, C): 30})],

 [Counter({(D, C): 30}),

 Counter(),

 Counter({(D, D): 27, (D, C): 3}),

 Counter({(D, D): 27, (D, C): 3})],

 [Counter({(C, C): 30}),

 Counter({(D, D): 27, (C, D): 3}),

 Counter(),

 Counter({(C, C): 30})],

 [Counter({(C, C): 30}),

 Counter({(D, D): 27, (C, D): 3}),

 Counter({(C, C): 30}),

 Counter()]]

```

##### Normalised state distribution[¶](#normalised-state-distribution "Permalink to this headline")

This gives the average rate state distribution against each opponent.

A state corresponds to 1

turn of a match and can be one of `(C, C), (C, D), (D, C),

(D, D)` where the first element is the action of the player in question and

the second the action of the opponent:

```

>>> pprint.pprint(results.normalised\_state\_distribution)

[[Counter(),

 Counter({(C, D): 1.0}),

 Counter({(C, C): 1.0}),

 Counter({(C, C): 1.0})],

 [Counter({(D, C): 1.0}),

 Counter(),

 Counter({(D, D): 0.9..., (D, C): 0.1...}),

 Counter({(D, D): 0.9..., (D, C): 0.1...})],

 [Counter({(C, C): 1.0}),

 Counter({(D, D): 0.9..., (C, D): 0.1...}),

 Counter(),

 Counter({(C, C): 1.0})],

 [Counter({(C, C): 1.0}),

 Counter({(D, D): 0.9..., (C, D): 0.1...}),

 Counter({(C, C): 1.0}),

 Counter()]]

```

##### State to action distribution counts[¶](#state-to-action-distribution-counts "Permalink to this headline")

This gives a total state action pair count against each opponent. A state

corresponds to 1 turn of a match and can be one of `(C, C), (C,

D), (D, C), (D, D)` where the first element is the action of the

player in question and the second the action of the opponent:

```

>>> pprint.pprint(results.state\_to\_action\_distribution)  

[[Counter(),

 Counter({((C, D), C): 27}),

 Counter({((C, C), C): 27}),

 Counter({((C, C), C): 27})],

 [Counter({((D, C), D): 27}),

 Counter(),

 Counter({((D, D), D): 24, ((D, C), D): 3}),

 Counter({((D, D), D): 24, ((D, C), D): 3})],

 [Counter({((C, C), C): 27}),

 Counter({((D, D), D): 24, ((C, D), D): 3}),

 Counter(),

 Counter({((C, C), C): 27})],

 [Counter({((C, C), C): 27}),

 Counter({((D, D), D): 24, ((C, D), D): 3}),

 Counter({((C, C), C): 27}),

 Counter()]]

```

##### Normalised state to action distribution[¶](#normalised-state-to-action-distribution "Permalink to this headline")

This gives the average rate state to action pair distribution against each

opponent. A state corresponds to 1 turn of a match and can be one of

`(C, C), (C, D), (D, C), (D, D)` where the first element

is the action of the player in question and the second the action of the

opponent:

```

>>> pprint.pprint(results.normalised\_state\_to\_action\_distribution) 

[[Counter(),

 Counter({((C, D), C): 1.0}),

 Counter({((C, C), C): 1.0}),

 Counter({((C, C), C): 1.0})],

 [Counter({((D, C), D): 1.0}),

 Counter(),

 Counter({((D, C), D): 1.0, ((D, D), D): 1.0}),

 Counter({((D, C), D): 1.0, ((D, D), D): 1.0})],

 [Counter({((C, C), C): 1.0}),

 Counter({((C, D), D): 1.0, ((D, D), D): 1.0}),

 Counter(),

 Counter({((C, C), C): 1.0})],

 [Counter({((C, C), C): 1.0}),

 Counter({((C, D), D): 1.0, ((D, D), D): 1.0}),

 Counter({((C, C), C): 1.0}),

 Counter()]]

```

##### Initial cooperation counts[¶](#initial-cooperation-counts "Permalink to this headline")

This gives the count of cooperations made by each player during the first turn

of every match:

```

>>> results.initial\_cooperation\_count

[9, 0, 9, 9]

```

Each player plays an opponent a total of 9 times (3 opponents and 3

repetitions). Apart from the `Defector`, they all cooperate on the first

turn.

##### Initial cooperation rates[¶](#initial-cooperation-rates "Permalink to this headline")

This gives the rate of which a strategy cooperates during the first turn:

```

>>> results.initial\_cooperation\_rate

[1.0, 0.0, 1.0, 1.0]

```

##### Morality Metrics[¶](#morality-metrics "Permalink to this headline")

The following morality metrics are available, they are calculated as a function

of the cooperation rating:

```

>>> results.cooperating\_rating  

[1.0, 0.0, 0.7, 0.7]

>>> pprint.pprint(results.vengeful\_cooperation)  

[[1.0, 1.0, 1.0, 1.0],

 [-1.0, -1.0, -1.0, -1.0],

 [1.0, -0.8, 1.0, 1.0],

 [1.0, -0.78 1.0, 1.0]]

>>> pprint.pprint(results.good\_partner\_matrix)

[[0, 3, 3, 3], [0, 0, 0, 0], [3, 3, 0, 3], [3, 3, 3, 0]]

>>> pprint.pprint(results.good\_partner\_rating)

[1.0, 0.0, 1.0, 1.0]

>>> results.eigenmoses\_rating

[0.37..., -0.37..., 0.59..., 0.59...]

>>> results.eigenjesus\_rating

[0.57..., 0.0, 0.57..., 0.57...]

```

For more information about these see [Calculate Morality Metrics](index.html#morality-metrics).

#### Read and write interactions from/to file[¶](#read-and-write-interactions-from-to-file "Permalink to this headline")

When dealing with large tournaments it might be desirable to separate the

analysis from the actual running of the tournaments. This can be done by passing

a `filename` argument to the `play` method of a tournament:

```

>>> import axelrod as axl

>>> players = [s() for s in axl.basic\_strategies]

>>> tournament = axl.Tournament(players, turns=4, repetitions=2)

>>> results = tournament.play(filename="basic\_tournament.csv")

```

This will create a file basic\_tournament.csv with data that looks something

like:

```

Interaction index,Player index,Opponent index,Repetition,Player name,Opponent name,Actions,Score,Score difference,Turns,Score per turn,Score difference per turn,Win,Initial cooperation,Cooperation count,CC count,CD count,DC count,DD count,CC to C count,CC to D count,CD to C count,CD to D count,DC to C count,DC to D count,DD to C count,DD to D count,Good partner

0,0,0,0,Alternator,Alternator,CDCD,8,0,4,2.0,0.0,0,True,2,2,0,0,2,0,2,0,0,0,0,1,0,1

0,0,0,0,Alternator,Alternator,CDCD,8,0,4,2.0,0.0,0,True,2,2,0,0,2,0,2,0,0,0,0,1,0,1

1,0,0,1,Alternator,Alternator,CDCD,8,0,4,2.0,0.0,0,True,2,2,0,0,2,0,2,0,0,0,0,1,0,1

1,0,0,1,Alternator,Alternator,CDCD,8,0,4,2.0,0.0,0,True,2,2,0,0,2,0,2,0,0,0,0,1,0,1

2,0,1,0,Alternator,Anti Tit For Tat,CDCD,8,0,4,2.0,0.0,0,True,2,2,0,0,2,0,2,0,0,0,0,1,0,1

2,1,0,0,Anti Tit For Tat,Alternator,CDCD,8,0,4,2.0,0.0,0,True,2,2,0,0,2,0,2,0,0,0,0,1,0,1

3,0,1,1,Alternator,Anti Tit For Tat,CDCD,8,0,4,2.0,0.0,0,True,2,2,0,0,2,0,2,0,0,0,0,1,0,1

3,1,0,1,Anti Tit For Tat,Alternator,CDCD,8,0,4,2.0,0.0,0,True,2,2,0,0,2,0,2,0,0,0,0,1,0,1

4,0,2,0,Alternator,Bully,CDCD,5,-5,4,1.25,-1.25,0,True,2,1,1,0,2,0,1,0,1,0,0,1,0,1

4,2,0,0,Bully,Alternator,DDCD,10,5,4,2.5,1.25,1,False,1,1,0,1,2,0,1,0,0,0,1,1,0,0

5,0,2,1,Alternator,Bully,CDCD,5,-5,4,1.25,-1.25,0,True,2,1,1,0,2,0,1,0,1,0,0,1,0,1

5,2,0,1,Bully,Alternator,DDCD,10,5,4,2.5,1.25,1,False,1,1,0,1,2,0,1,0,0,0,1,1,0,0

6,0,3,0,Alternator,Cooperator,CDCD,16,10,4,4.0,2.5,1,True,2,2,0,2,0,0,2,0,0,1,0,0,0,0

6,3,0,0,Cooperator,Alternator,CCCC,6,-10,4,1.5,-2.5,0,True,4,2,2,0,0,2,0,1,0,0,0,0,0,1

7,0,3,1,Alternator,Cooperator,CDCD,16,10,4,4.0,2.5,1,True,2,2,0,2,0,0,2,0,0,1,0,0,0,0

7,3,0,1,Cooperator,Alternator,CCCC,6,-10,4,1.5,-2.5,0,True,4,2,2,0,0,2,0,1,0,0,0,0,0,1

8,0,4,0,Alternator,Cycler DC,CDCD,10,0,4,2.5,0.0,0,True,2,0,2,2,0,0,0,0,2,1,0,0,0,1

8,4,0,0,Cycler DC,Alternator,DCDC,10,0,4,2.5,0.0,0,False,2,0,2,2,0,0,0,0,1,2,0,0,0,1

9,0,4,1,Alternator,Cycler DC,CDCD,10,0,4,2.5,0.0,0,True,2,0,2,2,0,0,0,0,2,1,0,0,0,1

9,4,0,1,Cycler DC,Alternator,DCDC,10,0,4,2.5,0.0,0,False,2,0,2,2,0,0,0,0,1,2,0,0,0,1

10,0,5,0,Alternator,Defector,CDCD,2,-10,4,0.5,-2.5,0,True,2,0,2,0,2,0,0,0,2,0,0,1,0,1

10,5,0,0,Defector,Alternator,DDDD,12,10,4,3.0,2.5,1,False,0,0,0,2,2,0,0,0,0,0,2,0,1,0

11,0,5,1,Alternator,Defector,CDCD,2,-10,4,0.5,-2.5,0,True,2,0,2,0,2,0,0,0,2,0,0,1,0,1

11,5,0,1,Defector,Alternator,DDDD,12,10,4,3.0,2.5,1,False,0,0,0,2,2,0,0,0,0,0,2,0,1,0

12,0,6,0,Alternator,Grudger,CDCD,9,0,4,2.25,0.0,0,True,2,1,1,1,1,0,1,0,1,1,0,0,0,1

12,6,0,0,Grudger,Alternator,CCDD,9,0,4,2.25,0.0,0,True,2,1,1,1,1,1,0,0,1,0,1,0,0,1

13,0,6,1,Alternator,Grudger,CDCD,9,0,4,2.25,0.0,0,True,2,1,1,1,1,0,1,0,1,1,0,0,0,1

13,6,0,1,Grudger,Alternator,CCDD,9,0,4,2.25,0.0,0,True,2,1,1,1,1,1,0,0,1,0,1,0,0,1

14,0,7,0,Alternator,Suspicious Tit For Tat,CDCD,10,0,4,2.5,0.0,0,True,2,0,2,2,0,0,0,0,2,1,0,0,0,1

14,7,0,0,Suspicious Tit For Tat,Alternator,DCDC,10,0,4,2.5,0.0,0,False,2,0,2,2,0,0,0,0,1,2,0,0,0,1

15,0,7,1,Alternator,Suspicious Tit For Tat,CDCD,10,0,4,2.5,0.0,0,True,2,0,2,2,0,0,0,0,2,1,0,0,0,1

15,7,0,1,Suspicious Tit For Tat,Alternator,DCDC,10,0,4,2.5,0.0,0,False,2,0,2,2,0,0,0,0,1,2,0,0,0,1

16,0,8,0,Alternator,Tit For Tat,CDCD,13,5,4,3.25,1.25,1,True,2,1,1,2,0,0,1,0,1,1,0,0,0,0

16,8,0,0,Tit For Tat,Alternator,CCDC,8,-5,4,2.0,-1.25,0,True,3,1,2,1,0,1,0,0,1,1,0,0,0,1

17,0,8,1,Alternator,Tit For Tat,CDCD,13,5,4,3.25,1.25,1,True,2,1,1,2,0,0,1,0,1,1,0,0,0,0

17,8,0,1,Tit For Tat,Alternator,CCDC,8,-5,4,2.0,-1.25,0,True,3,1,2,1,0,1,0,0,1,1,0,0,0,1

18,0,9,0,Alternator,Win-Shift Lose-Stay: D,CDCD,9,0,4,2.25,0.0,0,True,2,1,1,1,1,0,1,0,1,1,0,0,0,1

18,9,0,0,Win-Shift Lose-Stay: D,Alternator,DCCD,9,0,4,2.25,0.0,0,False,2,1,1,1,1,0,1,1,0,1,0,0,0,1

19,0,9,1,Alternator,Win-Shift Lose-Stay: D,CDCD,9,0,4,2.25,0.0,0,True,2,1,1,1,1,0,1,0,1,1,0,0,0,1

19,9,0,1,Win-Shift Lose-Stay: D,Alternator,DCCD,9,0,4,2.25,0.0,0,False,2,1,1,1,1,0,1,1,0,1,0,0,0,1

20,0,10,0,Alternator,Win-Stay Lose-Shift: C,CDCD,9,0,4,2.25,0.0,0,True,2,1,1,1,1,0,1,0,1,1,0,0,0,1

20,10,0,0,Win-Stay Lose-Shift: C,Alternator,CCDD,9,0,4,2.25,0.0,0,True,2,1,1,1,1,1,0,0,1,0,1,0,0,1

21,0,10,1,Alternator,Win-Stay Lose-Shift: C,CDCD,9,0,4,2.25,0.0,0,True,2,1,1,1,1,0,1,0,1,1,0,0,0,1

21,10,0,1,Win-Stay Lose-Shift: C,Alternator,CCDD,9,0,4,2.25,0.0,0,True,2,1,1,1,1,1,0,0,1,0,1,0,0,1

22,1,1,0,Anti Tit For Tat,Anti Tit For Tat,CDCD,8,0,4,2.0,0.0,0,True,2,2,0,0,2,0,2,0,0,0,0,1,0,1

22,1,1,0,Anti Tit For Tat,Anti Tit For Tat,CDCD,8,0,4,2.0,0.0,0,True,2,2,0,0,2,0,2,0,0,0,0,1,0,1

23,1,1,1,Anti Tit For Tat,Anti Tit For Tat,CDCD,8,0,4,2.0,0.0,0,True,2,2,0,0,2,0,2,0,0,0,0,1,0,1

23,1,1,1,Anti Tit For Tat,Anti Tit For Tat,CDCD,8,0,4,2.0,0.0,0,True,2,2,0,0,2,0,2,0,0,0,0,1,0,1

24,1,2,0,Anti Tit For Tat,Bully,CCCC,0,-20,4,0.0,-5.0,0,True,4,0,4,0,0,0,0,3,0,0,0,0,0,1

24,2,1,0,Bully,Anti Tit For Tat,DDDD,20,20,4,5.0,5.0,1,False,0,0,0,4,0,0,0,0,0,0,3,0,0,0

25,1,2,1,Anti Tit For Tat,Bully,CCCC,0,-20,4,0.0,-5.0,0,True,4,0,4,0,0,0,0,3,0,0,0,0,0,1

25,2,1,1,Bully,Anti Tit For Tat,DDDD,20,20,4,5.0,5.0,1,False,0,0,0,4,0,0,0,0,0,0,3,0,0,0

26,1,3,0,Anti Tit For Tat,Cooperator,CDDD,18,15,4,4.5,3.75,1,True,1,1,0,3,0,0,1,0,0,0,2,0,0,0

26,3,1,0,Cooperator,Anti Tit For Tat,CCCC,3,-15,4,0.75,-3.75,0,True,4,1,3,0,0,1,0,2,0,0,0,0,0,1

27,1,3,1,Anti Tit For Tat,Cooperator,CDDD,18,15,4,4.5,3.75,1,True,1,1,0,3,0,0,1,0,0,0,2,0,0,0

27,3,1,1,Cooperator,Anti Tit For Tat,CCCC,3,-15,4,0.75,-3.75,0,True,4,1,3,0,0,1,0,2,0,0,0,0,0,1

28,1,4,0,Anti Tit For Tat,Cycler DC,CCDC,7,-5,4,1.75,-1.25,0,True,3,2,1,0,1,0,1,1,0,0,0,1,0,1

28,4,1,0,Cycler DC,Anti Tit For Tat,DCDC,12,5,4,3.0,1.25,1,False,2,2,0,1,1,0,1,0,0,1,0,1,0,0

29,1,4,1,Anti Tit For Tat,Cycler DC,CCDC,7,-5,4,1.75,-1.25,0,True,3,2,1,0,1,0,1,1,0,0,0,1,0,1

29,4,1,1,Cycler DC,Anti Tit For Tat,DCDC,12,5,4,3.0,1.25,1,False,2,2,0,1,1,0,1,0,0,1,0,1,0,0

30,1,5,0,Anti Tit For Tat,Defector,CCCC,0,-20,4,0.0,-5.0,0,True,4,0,4,0,0,0,0,3,0,0,0,0,0,1

30,5,1,0,Defector,Anti Tit For Tat,DDDD,20,20,4,5.0,5.0,1,False,0,0,0,4,0,0,0,0,0,0,3,0,0,0

31,1,5,1,Anti Tit For Tat,Defector,CCCC,0,-20,4,0.0,-5.0,0,True,4,0,4,0,0,0,0,3,0,0,0,0,0,1

31,5,1,1,Defector,Anti Tit For Tat,DDDD,20,20,4,5.0,5.0,1,False,0,0,0,4,0,0,0,0,0,0,3,0,0,0

32,1,6,0,Anti Tit For Tat,Grudger,CDDC,9,0,4,2.25,0.0,0,True,2,1,1,1,1,0,1,0,0,0,1,1,0,1

32,6,1,0,Grudger,Anti Tit For Tat,CCDD,9,0,4,2.25,0.0,0,True,2,1,1,1,1,1,0,0,1,0,0,0,1,1

33,1,6,1,Anti Tit For Tat,Grudger,CDDC,9,0,4,2.25,0.0,0,True,2,1,1,1,1,0,1,0,0,0,1,1,0,1

33,6,1,1,Grudger,Anti Tit For Tat,CCDD,9,0,4,2.25,0.0,0,True,2,1,1,1,1,1,0,0,1,0,0,0,1,1

34,1,7,0,Anti Tit For Tat,Suspicious Tit For Tat,CCDD,9,0,4,2.25,0.0,0,True,2,1,1,1,1,0,1,1,0,0,1,0,0,1

34,7,1,0,Suspicious Tit For Tat,Anti Tit For Tat,DCCD,9,0,4,2.25,0.0,0,False,2,1,1,1,1,1,0,0,1,1,0,0,0,1

35,1,7,1,Anti Tit For Tat,Suspicious Tit For Tat,CCDD,9,0,4,2.25,0.0,0,True,2,1,1,1,1,0,1,1,0,0,1,0,0,1

35,7,1,1,Suspicious Tit For Tat,Anti Tit For Tat,DCCD,9,0,4,2.25,0.0,0,False,2,1,1,1,1,1,0,0,1,1,0,0,0,1

...

```

Note that depending on the order in which the matches have been played, the rows

could also be in a different order.

It is possible to read in this data file to obtain interactions:

```

>>> interactions = axl.interaction\_utils.read\_interactions\_from\_file("basic\_tournament.csv")

```

This gives a dictionary mapping pairs of player indices to interaction

histories:

```

>>> interactions[(0, 1)]

[[(C, C), (D, D), (C, C), (D, D)], [(C, C), (D, D), (C, C), (D, D)]]

```

This should allow for easy manipulation of data outside of the capabilities

within the library.

Note that you can supply build\_results=False as a keyword

argument to tournament.play() to prevent keeping or loading interactions in

memory, since the total memory footprint can be large for various combinations

of parameters. The memory usage scales as \(O(\text{players}^2 \times \text{turns} \times \text{repetitions})\).

#### Use Parallel processing[¶](#use-parallel-processing "Permalink to this headline")

When dealing with large tournaments on a multi core machine it is possible to

run the tournament in parallel **although this is not currently supported on

Windows**. Using `processes=0` will simply use all available cores:

```

>>> import axelrod as axl

>>> players = [s() for s in axl.basic\_strategies]

>>> tournament = axl.Tournament(players, turns=4, repetitions=2)

>>> results = tournament.play(processes=0)

```

#### Use a cache[¶](#use-a-cache "Permalink to this headline")

Whilst for stochastic strategies, every repetition of a Match will give a

different result, for deterministic strategies, when there is no noise there is

no need to re run the match. The library has a `DeterministicCache` class

that allows us to quickly replay matches.

##### Caching a Match[¶](#caching-a-match "Permalink to this headline")

To illustrate this, let us time the play of a match **without** a cache:

```

>>> import axelrod as axl

>>> import timeit

>>> def run\_match():

...     p1, p2 = axl.GoByMajority(), axl.Alternator()

...     match = axl.Match((p1, p2), turns=200)

...     return match.play()

>>> time\_with\_no\_cache = timeit.timeit(run\_match, number=500)

>>> time\_with\_no\_cache  

2.2295279502868652

```

Here is how to create a new empty cache:

```

>>> cache = axl.DeterministicCache()

>>> len(cache)

0

```

Let us rerun the above match but using the cache:

```

>>> p1, p2 = axl.GoByMajority(), axl.Alternator()

>>> match = axl.Match((p1, p2), turns=200, deterministic\_cache=cache)

>>> match.play()  

[(C, C), ..., (C, D)]

```

We can take a look at the cache:

```

>>> cache  

{('Soft Go By Majority', 'Alternator'): [(C, C), ..., (C, D)]}

>>> len(cache)

1

>>> len(cache[(axl.GoByMajority(), axl.Alternator())])

200

```

This maps a triplet of 2 player names and the match length to the resulting

interactions. We can rerun the code and compare the timing:

```

>>> def run\_match\_with\_cache():

...     p1, p2 = axl.GoByMajority(), axl.Alternator()

...     match = axl.Match((p1, p2), turns=200, deterministic\_cache=cache)

...     return match.play()

>>> time\_with\_cache = timeit.timeit(run\_match\_with\_cache, number=500)

>>> time\_with\_cache  

0.04215192794799805

>>> time\_with\_cache < time\_with\_no\_cache

True

```

We can write the cache to file:

```

>>> cache.save("cache.txt")

True

```

##### Caching a Tournament[¶](#caching-a-tournament "Permalink to this headline")

Tournaments will automatically create caches as needed on a match by match

basis.

##### Caching a Moran Process[¶](#caching-a-moran-process "Permalink to this headline")

A prebuilt cache can also be used in a Moran process (by default a new cache is

used):

```

>>> cache = axl.DeterministicCache("cache.txt")

>>> players = [axl.GoByMajority(), axl.Alternator(),

...            axl.Cooperator(), axl.Grudger()]

>>> mp = axl.MoranProcess(players, deterministic\_cache=cache)

>>> populations = mp.play()

>>> mp.winning\_strategy\_name   

Defector

```

We see that the cache has been augmented, although note that this

particular number will depend on the stochastic behaviour of the Moran process:

```

>>> len(cache)  

18

```

#### Use different stage games[¶](#use-different-stage-games "Permalink to this headline")

As described in [Play Contexts and Generic Prisoner’s Dilemma](index.html#play-contexts) the default game used for the Prisoner’s

Dilemma is given by:

```

>>> import axelrod as axl

>>> pd = axl.game.Game()

>>> pd

Axelrod game: (R,P,S,T) = (3, 1, 0, 5)

>>> pd.RPST()

(3, 1, 0, 5)

```

These `Game` objects are used to score [matches](index.html#creating-matches),

[tournaments](index.html#creating-tournaments) and [Moran processes](index.html#moran-process):

```

>>> pd.score((axl.Action.C, axl.Action.C))

(3, 3)

>>> pd.score((axl.Action.C, axl.Action.D))

(0, 5)

>>> pd.score((axl.Action.D, axl.Action.C))

(5, 0)

>>> pd.score((axl.Action.D, axl.Action.D))

(1, 1)

```

It is possible to run a matches, tournaments and Moran processes with a

different game. For example here is the game of chicken:

```

>>> chicken = axl.game.Game(r=0, s=-1, t=1, p=-10)

>>> chicken

Axelrod game: (R,P,S,T) = (0, -10, -1, 1)

>>> chicken.RPST()

(0, -10, -1, 1)

```

Here is a simple tournament run with this game:

```

>>> players = [axl.Cooperator(), axl.Defector(), axl.TitForTat()]

>>> tournament = axl.Tournament(players, game=chicken)

>>> results = tournament.play()

>>> results.ranked\_names

['Cooperator', 'Defector', 'Tit For Tat']

```

The default Prisoner’s dilemma has different results:

```

>>> tournament = axl.Tournament(players)

>>> results = tournament.play()

>>> results.ranked\_names

['Defector', 'Tit For Tat', 'Cooperator']

```

Asymmetric games can also be implemented via the AsymmetricGame class

with two Numpy arrays for payoff matrices:

```

>>> import numpy as np

>>> A = np.array([[3, 1], [1, 3]])

>>> B = np.array([[1, 3], [2, 1]])

>>> asymmetric\_game = axl.AsymmetricGame(A, B)

>>> asymmetric\_game  

Axelrod game with matrices: (array([[3, 1],

 [1, 3]]),

 array([[1, 3],

 [2, 1]]))

```

Asymmetric games can also be different sizes (even if symmetric; regular games

can currently only be 2x2), such as Rock Paper Scissors:

```

>>> A = np.array([[0, -1, 1], [1, 0, -1], [-1, 1, 0]])

>>> rock\_paper\_scissors = axl.AsymmetricGame(A, -A)

>>> rock\_paper\_scissors  

Axelrod game with matrices: (array([[ 0, -1, 1],

 [ 1, 0, -1],

 [-1, 1, 0]]),

 array([[ 0, 1, -1],

 [-1, 0, 1],

 [ 1, -1, 0]]))

```

**NB: Some features of Axelrod, such as strategy transformers, are specifically created for

use with the iterated Prisoner’s Dilemma; they may break with games of other sizes.**

Note also that most strategies in Axelrod are Prisoners’ Dilemma strategies, so behave

as though they are playing the Prisoners’ Dilemma; in the rock-paper-scissors example above,

they will certainly never choose scissors (because their strategy action set is two actions!)

For a more detailed tutorial on how to implement another game into Axelrod, [here is a

tutorial using rock paper scissors as an example.](index.html#implement-new-games)

#### Use custom matches[¶](#use-custom-matches "Permalink to this headline")

The Moran process supports custom match classes. Below

creates a new class of a match where both players end with a score of 2:

```

>>> import axelrod as axl

>>> class MassBaseMatch(axl.Match):

...  """Axelrod Match object with a modified final score function to enable mass to influence the final score as a multiplier"""

...     def final\_score\_per\_turn(self):

...         return 2, 2

```

We then create a Moran process with the custom match class by passing our custom

`MassBaseMatch` to the Moran process with the `match\_class` keyword

argument:

```

>>> players = [axl.Cooperator(), axl.Defector(), axl.TitForTat(), axl.Grudger()]

>>> mp = axl.MoranProcess(players=players, match\_class=MassBaseMatch, seed=0)

>>> population = mp.play()

>>> print(mp.winning\_strategy\_name)

Defector

```

#### Set a random seed[¶](#set-a-random-seed "Permalink to this headline")

The library has a variety of strategies whose behaviour is stochastic. To ensure

reproducible results a random seed should be set. The library abstracts away the

propagation of seeds in matches and tournaments, so you typically only need to

supply a seed to those objects.

##### Matches[¶](#matches "Permalink to this headline")

For a match, set a seed by passing a parameter to Match

```

>>> import axelrod as axl

>>> players = (axl.Random(), axl.MetaMixer())  # Two stochastic strategies

>>> match = axl.Match(players, turns=3, seed=101)

>>> results = match.play()

```

We obtain the same results if it is played with the same seed:

```

>>> match2 = axl.Match(players, turns=3, seed=101)

>>> result2 = match2.play()

>>> results == result2

True

```

For noisy matches, a seed also needs to be set for reproducibility, even if the players are

deterministic.

```

>>> import axelrod as axl

>>> players = (axl.Cooperator(), axl.Defector())  # Two deterministic strategies

>>> match = axl.Match(players, turns=200, seed=101, noise=0.25)

>>> results = match.play()

>>> match2 = axl.Match(players, turns=200, seed=101, noise=0.25)

>>> results2 = match2.play()

>>> results == results2

True

```

##### Tournaments[¶](#tournaments "Permalink to this headline")

For tournaments, an initial seed is used to generate subsequent seeds for each match in a

a manner that will yield identical results. Note that if the tournament is run with multiple

processes, the order of the matches may be computed differently, but the seeds used for each

match will be the same.

To seed a tournament we also pass a seed to the tournament at creation time:

```

>>> import axelrod as axl

>>> seed = 201

>>> players = (axl.Random(), axl.Cooperator(), axl.MetaMixer())

>>> tournament = axl.Tournament(players, turns=5, repetitions=5, seed=seed)

>>> results = tournament.play(processes=1)

>>> tournament2 = axl.Tournament(players, turns=5, repetitions=5, seed=seed)

>>> results2 = tournament2.play(processes=1)

>>> results.ranked\_names == results2.ranked\_names

True

```

For parallel processing, the ordering of match results may differ, but the actual results, and the final

rankings, will be the same.

```

>>> import axelrod as axl

>>> players = (axl.Random(), axl.Cooperator(), axl.MetaMixer())

>>> tournament = axl.Tournament(players, turns=5, repetitions=5, seed=201)

>>> results = tournament.play(processes=2)

>>> tournament2 = axl.Tournament(players, turns=5, repetitions=5, seed=201)

>>> results2 = tournament2.play(processes=2)

>>> results.ranked\_names == results2.ranked\_names

True

```

##### Moran Process[¶](#moran-process "Permalink to this headline")

Similarly, a Moran process is essentially another type of tournament. The library’s implementation

will propagate child seeds to each match to ensure reproducibility. See also the documentation on

`EvolvablePlayers`.

##### Fingerprints[¶](#fingerprints "Permalink to this headline")

Since fingerprint generation depends on tournaments, fingerprints can also be given a seed for

reproducibility.

#### Set Player information[¶](#set-player-information "Permalink to this headline")

It is possible to determine what information players know about their matches.

By default all known information is given. For example let us create a match

with 5 turns between `FirstBySteinAndRapoport` and `Alternator`. The

latter of these two always defects on the last 2 turns:

```

>>> import axelrod as axl

>>> players = (axl.Alternator(), axl.FirstBySteinAndRapoport())

>>> axl.Match(players, turns=5).play()

[(C, C), (D, C), (C, C), (D, D), (C, D)]

```

We can play the same match but let us tell the players that the match lasts 6

turns:

```

>>> axl.Match(players, turns=5, match\_attributes={"length": 6}).play()

[(C, C), (D, C), (C, C), (D, C), (C, D)]

```

We can also pass this information to a tournament. Let us create a

tournament with 5 turns but ensure the players believe the match length is

infinite (unknown):

```

>>> tournament = axl.Tournament(players, turns=5,

...                             match\_attributes={"length": float('inf')})

```

The `match\_attributes` dictionary can also be used to pass `game`

and `noise`.

#### Check Player equality[¶](#check-player-equality "Permalink to this headline")

It is possible to test for player equality using `==`:

```

>>> import axelrod as axl

>>> p1, p2, p3 = axl.Alternator(), axl.Alternator(), axl.TitForTat()

>>> p1 == p2

True

>>> p1 == p3

False

```

Note that this checks all the attributes of an instance:

```

>>> p1.name = "John Nash"

>>> p1 == p2

False

```

This however does not check if the players will behave in the same way. For

example here are two equivalent players:

```

>>> p1 = axl.Alternator()

>>> p2 = axl.Cycler("CD")

>>> p1 == p2

False

```

To check if player strategies are equivalent you can use [Fingerprint](index.html#fingerprinting).

#### Cite the library[¶](#cite-the-library "Permalink to this headline")

We would be delighted if anyone wanted to use and/or reference this library for

their own research.

If you do please let us know and reference the library: as described in the

[CITATION.rst file on the library

repository](https://github.com/Axelrod-Python/Axelrod/blob/master/CITATION.rst).

#### Contribute[¶](#contribute "Permalink to this headline")

This section contains a variety of tutorials that should help you contribute to

the library.

Contents:

##### Guidelines[¶](#guidelines "Permalink to this headline")

All contributions to this repository are welcome via pull request on the [github repository](https://github.com/Axelrod-Python/Axelrod).

The project follows the following guidelines:

1. Use the base Python library unless completely necessary. A few external

libraries (such as numpy) have been included in requirements.txt – feel free

to use these as needed.

2. Try as best as possible to follow [PEP8](https://www.python.org/dev/peps/pep-0008/) which includes **using

descriptive variable names**.

3. Code Format: Use the [Black formatter](https://github.com/ambv/black) to format

all code and the [isort utility](https://github.com/timothycrosley/isort) to

sort import statements. You can run black on all code with:

```

$ python -m black -l 80 .

```

4. Commits: Please try to use commit messages that give a meaningful history

for anyone using git’s log features. Try to use messages that complete sentence,

“This commit will…” There is some excellent guidance on the subject

from [Chris Beams](https://chris.beams.io/posts/git-commit/)

5. Testing: the project uses the [unittest](https://docs.python.org/2/library/unittest.html) library and has a nice

testing suite that makes some things easy to write tests for. Please try

to increase the test coverage on pull requests.

6. Merging pull-requests: We require two of the (currently three) core-team

maintainers to merge. Opening a PR for early

feedback or to check test coverage is OK, just indicate that the PR is not ready

to merge (and update when it is).

By submitting a pull request, you are agreeing that your work may be distributed

under the terms of the project’s [licence](https://raw.githubusercontent.com/Axelrod-Python/Axelrod/master/LICENSE.txt) and you will become one of the project’s joint copyright holders.

##### Setting up the environment[¶](#setting-up-the-environment "Permalink to this headline")

###### Installing all dependencies[¶](#installing-all-dependencies "Permalink to this headline")

All development dependencies can be installed by running:

```

$ pip install -r requirements/development.txt

```

It is recommended to do this using a virtual environment tool of your choice.

For example, when using the virtual environment library `venv`:

```

$ python -m venv axelrod_development

$ source axelrod_development/bin/activate

$ pip install -r requirements/development.txt

```

Alternatively, you can specify the development variant rather than the path:

```

$ python -m venv axelrod_development

$ source axelrod_development/bin/activate

$ pip install .[development]

```

###### The git workflow[¶](#the-git-workflow "Permalink to this headline")

There are two important branches in this repository:

* `dev`: The most up to date branch with no failing tests.

This is the default branch on github.

* `release`: The latest release.

When working on a new contribution branch from the latest `dev` branch and

open a Pull Request on github from your branch to the `dev` branch.

The procedure for a new release (this is carried out by one of core maintainers):

1. Create a Pull Request from `dev` to `release` which should

include an update to `axelrod/version.py` and `CHANGES.md`

2. Create a git tag.

3. Push to github.

4. Create a release on github.

5. Push to PyPi: `python setup.py sdist bdist\_wheel upload`

##### Contributing a strategy[¶](#contributing-a-strategy "Permalink to this headline")

This section contains a variety of tutorials that should help you contribute a

new strategy to the library.

Contents:

###### Instructions[¶](#instructions "Permalink to this headline")

Here is the file structure for the Axelrod repository:

```

.

├── axelrod

│   └── __init__.py

│   └── ecosystem.py

│   └── game.py

│   └── player.py

│   └── plot.py

│   └── result_set.py

│   └── round_robin.py

│   └── tournament.py

│   └── /strategies/

│       └── __init__.py

│       └── _strategies.py

│       └── cooperator.py

│       └── defector.py

│       └── grudger.py

│       └── titfortat.py

│       └── gobymajority.py

│       └── ...

│   └── /tests/

│       └── integration

│       └── strategies

│       └── unit

│           └── test_*.py

└── README.md

```

To contribute a strategy you need to follow as many of the following steps as possible:

1. Fork the [github repository](https://github.com/Axelrod-Python/Axelrod).

2. Add a `<strategy>.py` file to the strategies directory or add a

strategy to a pre existing `<strategy>.py` file.

3. Update the `./axelrod/strategies/\_strategies.py` file.

4. If you created a new `<strategy>.py` file add it to

`.docs/reference/all\_strategies.rst`.

5. Write some unit tests in the `./axelrod/tests/strategies/` directory.

6. This one is also optional: ping us a message and we’ll add you to the

Contributors team. This would add an Axelrod-Python organisation badge to

your profile.

7. Send us a pull request.

**If you would like a hand with any of the above please do get in touch: we’re

always delighted to have new strategies.**

###### Writing the new strategy[¶](#writing-the-new-strategy "Permalink to this headline")

####### Identify a new strategy[¶](#identify-a-new-strategy "Permalink to this headline")

If you’re not sure if you have a strategy that has already been implemented, you

can search the [Strategy index](index.html#strategies-index) to see if they are implemented. If you

are still unsure please get in touch: [via the gitter room](https://gitter.im/Axelrod-Python/Axelrod) or [open an issue](https://github.com/Axelrod-Python/Axelrod/issues).

Several strategies are special cases of other strategies. For example, both

`Cooperator` and `Defector` are special cases of `Random`,

`Random(1)` and `Random(0)` respectively. While we could eliminate

`Cooperator` in its current

form, these strategies are intentionally left as is as simple examples for new

users and contributors. Nevertheless, please feel free to update the docstrings

of strategies like `Random` to point out such cases.

####### The code[¶](#the-code "Permalink to this headline")

There are a couple of things that need to be created in a strategy.py file. Let

us take a look at the [`TitForTat`](index.html#axelrod.strategies.titfortat.TitForTat "axelrod.strategies.titfortat.TitForTat") class (located in the

`axelrod/strategies/titfortat.py` file):

```

class TitForTat(Player):

 """

 A player starts by cooperating and then mimics previous move by

 opponent.

 Note that the code for this strategy is written in a fairly verbose

 way. This is done so that it can serve as an example strategy for

 those who might be new to Python.

 Names

 - Rapoport's strategy: [Axelrod1980]\_

 - TitForTat: [Axelrod1980]\_

 """

    # These are various properties for the strategy

    name = 'Tit For Tat'

    classifier = {

        'memory\_depth': 1,  # Four-Vector = (1.,0.,1.,0.)

        'stochastic': False,

        'inspects\_source': False,

        'manipulates\_source': False,

        'manipulates\_state': False

    }

    def strategy(self, opponent):

 """This is the actual strategy"""

        # First move

        if len(self.history) == 0:

            return C

        # React to the opponent's last move

        if opponent.history[-1] == D:

            return D

        return C

```

The first thing that is needed is a docstring that explains what the strategy

does:

```

"""A player starts by cooperating and then mimics previous move by opponent."""

```

Secondly, any alternate names should be included and if possible references

provided (this helps when trying to identify if a strategy has already been

implemented or not):

```

- Rapoport's strategy: [Axelrod1980]\_

- TitForTat: [Axelrod1980]\_

```

These references can be found in the [Bibliography](index.html#bibliography). If a required

references is not there please feel free to add it or just get in touch and we’d

be happy to help.

After that simply add in the string that will appear as the name of the

strategy:

```

name = 'Tit For Tat'

```

Note that this is mainly used in plots by `matplotlib` so you can use

LaTeX if you want to. For example there is strategy with \(\pi\) as a

name:

```

name = '$\pi$'

```

Following that you can add in the `classifier` dictionary:

```

classifier = {

    'memory\_depth': 1,  # Four-Vector = (1.,0.,1.,0.)

    'stochastic': False,

    'inspects\_source': False,

    'manipulates\_source': False,

    'manipulates\_state': False

}

```

This helps classify the strategy as described in

[Classification of strategies](index.html#classification-of-strategies).

After that the only thing required is to write the `strategy` method

which takes an opponent as an argument. In the case of

[`TitForTat`](index.html#axelrod.strategies.titfortat.TitForTat "axelrod.strategies.titfortat.TitForTat") the

strategy checks if it has any history (`if len(self.history) == 0`). If

it does not (ie this is the first play of the match) then it returns `C`.

If not, the strategy simply repeats the opponent’s last move (`return

opponent.history[-1]`):

```

def strategy(opponent):

 """This is the actual strategy"""

    # First move

    if len(self.history) == 0:

        return C

    # Repeat the opponent's last move

    return opponent.history[-1]

```

The variables `C` and `D` represent the cooperate and defect actions

respectively.

Some strategies make specific use of the variables of a match to create their

own attributes. In principle these attributes could change throughout a match

or tournament if the match properties (like the game matrix) change, so we

require that this logic live in the `receive\_match\_attributes` method for

correct dynamic updating. Here is how this is done for [`Stalker`](index.html#axelrod.strategies.stalker.Stalker "axelrod.strategies.stalker.Stalker"):

```

def receive\_match\_attributes(self)

    R, P, S, T = self.match\_attributes["game"].RPST()

    self.very\_good\_score = R

    self.very\_bad\_score = P

    self.wish\_score = (R + P) / 2

```

There are various examples of helpful functions and properties that make

writing strategies easier. Do not hesitate to get in touch with the

Axelrod-Python team for guidance.

###### Writing docstrings[¶](#writing-docstrings "Permalink to this headline")

The project takes pride in its documentation for the strategies

and its corresponding bibliography. The docstring is a string

which describes a method, module or class. The docstrings help

the user in understanding the working of the strategy

and the source of the strategy. The docstring must be written in

the following way, i.e.:

```

 """This is a docstring.

It can be written over multiple lines.

"""

```

####### Sections[¶](#sections "Permalink to this headline")

The Sections of the docstring are:

1. **Working of the strategy**

A brief summary on how the strategy works, E.g.:

```

class TitForTat(Player):

"""

A player starts by cooperating and then mimics the

previous action of the opponent.

"""

```

2. **Bibliography/Source of the strategy**

A section to mention the source of the strategy

or the paper from which the strategy was taken.

The section must start with the Names section.

For E.g.:

```

class TitForTat(Player):

"""

A player starts by cooperating and then mimics the

previous action of the opponent.

Names:

- Rapoport's strategy: [Axelrod1980]\_

- TitForTat: [Axelrod1980]\_

"""

```

Here, the info written under the Names section

tells about the source of the TitforTat strategy.

`[Axelrod1980]\_` corresponds to the bibliographic item in

`docs/reference/bibliography.rst`. If you are using a source

that is not in the bibliography please add it.

###### Adding the new strategy[¶](#adding-the-new-strategy "Permalink to this headline")

To get the strategy to be recognised by the library we need to add it to the

files that initialise when someone types `import axelrod`. This is done

in the `axelrod/strategies/\_strategies.py` file.

To classify the new strategy, run rebuild\_classifier\_table:

```

python rebuild\_classifier\_table.py

```

This will update `axelrod/strategies/\_strategies.py`. Check that the

recorded classifications for the strategies are what you expected.

If you have added your strategy to a file that already existed (perhaps you

added a new variant of `titfortat` to the `titfortat.py` file),

simply add your strategy to the list of strategies already imported from

`<file\_name>.py`:

```

from <file\_name> import <list-of-strategies>

```

If you have added your strategy to a new file then simply add a line similar to

above with your new strategy.

Once you have done that, you need to add the class itself to the

`all\_strategies` list (in `axelrod/strategies/\_strategies.py`).

You will also need to increment the doctest in

`axelrod/docs/index.rst`.

Finally, if you have created a new module (a new `<strategy.py>` file)

please add it to the `docs/references/all\_strategies.rst` file so that it

will automatically be documented.

###### Classifying the new strategy[¶](#classifying-the-new-strategy "Permalink to this headline")

Every strategy class has a classifier dictionary that gives some classification

of the strategy according to certain dimensions. Some of the classifiers have

formulas that try to compute the value for different strategies. Where these

exist, they’re overridden by the values defined in this dictionary. When

creating a new strategy, you should try to fill out all of the dictionary.

Let us take a look at the dimensions available by looking at `TitForTat`:

```

>>> import axelrod

>>> classifier = axelrod.TitForTat.classifier

>>> for key in sorted(classifier.keys()):

...    print(key)

inspects\_source

long\_run\_time

manipulates\_source

manipulates\_state

memory\_depth

stochastic

```

You can read more about this in the [Classification of strategies](index.html#classification-of-strategies) section

but here are some tips about filling this part in correctly.

Note that when an instance of a class is created it gets it’s own copy of the

default classifier dictionary from the class. This might sometimes be modified by

the initialisation depending on input parameters. A good example of this is the

`Joss` strategy:

```

>>> joss = axelrod.FirstByJoss()

>>> boring\_joss = axelrod.FirstByJoss(p=1)

>>> axelrod.Classifiers["stochastic"](joss)

True

>>> axelrod.Classifiers["stochastic"](boring\_joss)

False

```

A classifier value defined on the instance overrides the value defined for the

class.

There are currently three important dimensions that help identify if a strategy

obeys axelrod’s original tournament rules.

1. `inspects\_source` - does the strategy ‘read’ any source code that

it would not normally have access to. An example of this is `Geller`.

2. `manipulates\_source` - does the strategy ‘write’ any source code that

it would not normally be able to. An example of this is `Mind Bender`.

3. `manipulates\_state` - does the strategy ‘change’ any attributes that

it would not normally be able to. An example of this is `Mind Reader`.

These dimensions are currently relevant to the obey\_axelrod function which

checks if a strategy obeys Axelrod’s original rules.

###### Writing tests for the new strategy[¶](#writing-tests-for-the-new-strategy "Permalink to this headline")

To write tests you either need to create a file called `test\_<library>.py`

where `<library>.py` is the name of the file you have created or similarly

add tests to the test file that is already present in the

`axelrod/tests/strategies/` directory.

Typically we want to test the following:

* That the strategy behaves as intended on the first move and subsequent

moves, triggering any expected actions

* That the strategy initializes correctly

A `TestPlayer` class has been written that has

a member function `versus\_test` which can be used to test how the player

plays against a given opponent.

It takes an optional keyword

argument `seed` (useful and necessary for stochastic strategies,

`None` by default):

```

self.versus\_test(opponent=axelrod.MockPlayer(actions=[C, D]),

                 expected\_actions=[(D, C), (C, D), (C, C)], seed=None)

```

In this case the player is tested against an opponent that will cycle through

`C, D`. The `expected\_actions` are the actions played by both

the tested player and the opponent in the match. In this case we see that the

player is expected to play `D, C, C` against `C, D, C`.

Note that you can either user a `MockPlayer` that will cycle through a

given sequence or you can use another strategy from the Axelrod library.

The function `versus\_test` also accepts a dictionary parameter of

attributes to check at the end of the match. For example this test checks

if the player’s internal variable `opponent\_class` is set to

`"Cooperative"`:

```

actions = [(C, C)] \* 6

self.versus\_test(axelrod.Cooperator(), expected\_actions=actions

                 attrs={"opponent\_class": "Cooperative"})

```

Note here that instead of passing a sequence of actions as an opponent we are

passing an actual player from the axelrod library.

The function `versus\_test` also accepts a dictionary parameter of match

attributes that dictate the knowledge of the players. For example this test

assumes that players do not know the length of the match:

```

actions = [(C, C), (C, D), (D, C), (C, D)]

self.versus\_test(axelrod.Alternator(), expected\_actions=actions,

                 match\_attributes={"length": float("inf")})

```

The function `versus\_test` also accepts a dictionary parameter of

keyword arguments that dictate how the player is initiated. For example this

tests how the player plays when initialised with `p=1`:

```

actions = [(C, C), (C, D), (C, C), (C, D)]

self.versus\_test(axelrod.Alternator(), expected\_actions=actions,

                 init\_kwargs={"p": 1})

```

As an example, the tests for Tit-For-Tat are as follows:

```

import axelrod

from test\_player import TestPlayer

C, D = axelrod.Action.C, axelrod.Action.D

class TestTitForTat(TestPlayer):

 """

 Note that this test is referred to in the documentation as an example on

 writing tests. If you modify the tests here please also modify the

 documentation.

 """

    name = "Tit For Tat"

    player = axelrod.TitForTat

    expected\_classifier = {

        'memory\_depth': 1,

        'stochastic': False,

        'makes\_use\_of': set(),

        'inspects\_source': False,

        'manipulates\_source': False,

        'manipulates\_state': False

    }

    def test\_strategy(self):

        self.first\_play\_test(C)

        self.second\_play\_test(rCC=C, rCD=D, rDC=C, rDD=D)

        # Play against opponents

        actions = [(C, C), (C, D), (D, C), (C, D)]

        self.versus\_test(axelrod.Alternator(), expected\_actions=actions)

        actions = [(C, C), (C, C), (C, C), (C, C)]

        self.versus\_test(axelrod.Cooperator(), expected\_actions=actions)

        actions = [(C, D), (D, D), (D, D), (D, D)]

        self.versus\_test(axelrod.Defector(), expected\_actions=actions)

        # This behaviour is independent of knowledge of the Match length

        actions = [(C, C), (C, D), (D, C), (C, D)]

        self.versus\_test(axelrod.Alternator(), expected\_actions=actions,

                         match\_attributes={"length": float("inf")})

        # We can also test against random strategies

        actions = [(C, D), (D, D), (D, C), (C, C)]

        self.versus\_test(axelrod.Random(), expected\_actions=actions,

                         seed=0)

        actions = [(C, C), (C, D), (D, D), (D, C)]

        self.versus\_test(axelrod.Random(), expected\_actions=actions,

                         seed=1)

        # If you would like to test against a sequence of moves you should use

        # a MockPlayer

        opponent = axelrod.MockPlayer(actions=[C, D])

        actions = [(C, C), (C, D), (D, C), (C, D)]

        self.versus\_test(opponent, expected\_actions=actions)

        opponent = axelrod.MockPlayer(actions=[C, C, D, D, C, D])

        actions = [(C, C), (C, C), (C, D), (D, D), (D, C), (C, D)]

        self.versus\_test(opponent, expected\_actions=actions)

```

There are other examples of using this testing framework in

`axelrod/tests/strategies/test\_titfortat.py`.

The `expected\_classifier` dictionary tests that the classification of the

strategy is as expected (the tests for this is inherited in the `init`

method). Please be sure to classify new strategies according to the already

present dimensions but if you create a new dimension you do not **need** to re

classify all the other strategies (but feel free to! :)), but please do add it

to the `default\_classifier` in the `axelrod/player.py` parent class.

##### Contributing to the library[¶](#contributing-to-the-library "Permalink to this headline")

All contributions (docs, tests, etc) are very welcome, if there is a specific

functionality that you would like to add then please open an issue (or indeed

take a look at the ones already there and jump in the conversation!).

If you want to work on documentation please keep in mind that doctests are

encouraged to help keep the documentation up to date.

##### Running tests[¶](#running-tests "Permalink to this headline")

###### Basic test runners[¶](#basic-test-runners "Permalink to this headline")

The project has an extensive test suite which is run each time a new

contribution is made to the repository. If you want to check that all the tests

pass before you submit a pull request you can run the tests yourself:

```

$ python -m unittest discover

```

If you are developing new tests for the suite, it is useful to run a single test

file so that you don’t have to wait for the entire suite each time. For

example, to run only the tests for the Grudger strategy:

```

$ python -m unittest axelrod.tests.strategies.test_grudger

```

The test suite is divided into three categories: strategy tests, unit tests and integration tests.

Each can be run individually:

```

$ python -m unittest discover -s axelrod.tests.strategies

$ python -m unittest discover -s axelrod.tests.unit

$ python -m unittest discover -s axelrod.tests.integration

```

###### Testing coverage of tests[¶](#testing-coverage-of-tests "Permalink to this headline")

The library has 100% test coverage. This can be tested using the Python

`coverage` package. Once installed (`pip install coverage`), to run

the tests and check the coverage for the entire library:

```

$ coverage run --source=axelrod -m unittest discover

```

You can then view a report of the coverage:

```

$ coverage report -m

```

You can also run the coverage on a subset of the tests. For example, to run the

tests with coverage for the Grudger strategy:

```

$ coverage run --source=axelrod -m unittest axelrod.tests.strategies.test_grudger

```

###### Testing the documentation[¶](#testing-the-documentation "Permalink to this headline")

The documentation is doctested, to run those tests you can run

the script:

```

$ python doctests.py

```

You can also run the doctests on any given file. For example, to run the

doctests for the `docs/tutorials/getting\_started/match.rst` file:

```

$ python -m doctest docs/tutorials/getting_started/match.rst

```

###### Type checking[¶](#type-checking "Permalink to this headline")

The library makes use of type hinting, this can be checked using the Python

`mypy` package. Once installed (`pip install mypy`), to run the type checker:

```

$ python run_mypy.py

```

You can also run the type checker on a given file. For example, to run the type

checker on the Grudger strategy:

```

$ mypy --ignore-missing-imports --follow-imports skip axelrod/strategies/grudger.py

```

### Discussion[¶](#discussion "Permalink to this headline")

This section is a discussion of various aspects of Game Theory related to the

Axelrod library.

Contents:

#### Background to Axelrod’s Tournament[¶](#background-to-axelrod-s-tournament "Permalink to this headline")

[In the 1980s, professor of Political Science Robert Axelrod ran a tournament inviting strategies from collaborators all over the world for the Iterated Prisoner’s Dilemma](http://en.wikipedia.org/wiki/The_Evolution_of_Cooperation#Axelrod.27s_tournaments).

Another nice write up of Axelrod’s work and this tournament on github was put together by [Artem Kaznatcheev](https://plus.google.com/101780559173703781847/posts) [here](https://egtheory.wordpress.com/2015/03/02/ipd/).

##### The Prisoner’s Dilemma[¶](#the-prisoner-s-dilemma "Permalink to this headline")

The [Prisoner’s dilemma](http://en.wikipedia.org/wiki/Prisoner%27s_dilemma) is the simple two player game shown below:

|  | Cooperate | Defect |

| --- | --- | --- |

| Cooperate | (3,3) | (0,5) |

| Defect | (5,0) | (1,1) |

If both players cooperate they will each go to prison for 2 years and receive an

equivalent utility of 3.

If one cooperates and the other defects: the defector does not go to prison and the cooperator goes to prison for 5 years, the cooperator receives a utility of 0 and the defector a utility of 5.

If both defect: they both go to prison for 4 years and receive an equivalent

utility of 1.

Note

Years in prison doesn’t equal to utility directly. The formula is U = 5 - Y for Y in [0, 5], where `U` is the utility, `Y` are years in prison. The reason is to follow the original Axelrod’s scoring.

By simply investigating the best responses against both possible actions of each player it is immediate to see that the Nash equilibrium for this game is for both players to defect.

##### The Iterated Prisoner’s Dilemma[¶](#the-iterated-prisoner-s-dilemma "Permalink to this headline")

We can use the basic Prisoner’s Dilemma as a *stage* game in a repeated game.

Players now aim to maximise the utility (corresponding to years in prison) over a repetition of the game.

Strategies can take in to account both players history and so can take the form:

> 

> “I will cooperate unless you defect 3 times in a row at which point I will defect forever.”

Axelrod ran such a tournament (twice) and invited strategies from anyone who would contribute.

The tournament was a round robin and the winner was the strategy who had the lowest total amount of time in prison.

This tournament has been used to study how cooperation can evolve from a very simple set of rules.

This is mainly because the winner of both tournaments was ‘tit for tat’: a strategy that would never defect first (referred to as a ‘nice’ strategy).

#### Strategy Archetypes[¶](#strategy-archetypes "Permalink to this headline")

##### Finite State Machines[¶](#finite-state-machines "Permalink to this headline")

A finite state machine (FSM) is a general computation model. In the context of Axelrod, it’s a set of states and “transitions.” A transition for a given state/previous-opponent-action combination says how the strategy will respond, both in what action it will take and in what state it will transitions to. That is a transition will specify that in state \(a\), the strategy will respond to action \(X\) by taking action \(Y\) and moving to state \(b\) (which will tell us which transitions to use in later moves). We may write this transition \((a, X, b, Y)\). For Axelrod, a FSM must have a full set of transitions, which specifies a unique response for each

state/previous-opponent-action combination.

See [[Harper2017]](index.html#harper2017) for a more-detailed explanation.

Representing a strategy as a finite state machine has been useful in some research (see [[Harper2017]](index.html#harper2017) or [[Ashlock2006b]](index.html#ashlock2006b)). Though it’s theoretically possible to represent all strategies as FSMs, this is impractical for most strategies. However, some strategies lend themselves naturally to a FSM representation. For example, for the Iterated Prisoner’s Dilemma, we could consider a strategy that cooperates (C) until the opponent defects (D) twice in a row, then defect forever thereafter. (We’ll call this strategy grudger\_2 for the example.) We could call state 1, the state where the opponent hasn’t started a defect streak; state 2, the state where the opponent is on a 1-defect streak; and state 3, the state where the opponent has defected twice in a row at some point. Then the transitions would be:

```

>>> from axelrod import Action

>>> C, D = Action.C, Action.D

>>> grudger\_2\_transitions = (

...    (1, C, 1, C),

...    (1, D, 2, C),

...    (2, C, 1, C),

...    (2, D, 3, D),

...    (3, C, 3, D),

...    (3, D, 3, D)

... )

```

The Axelrod library includes a FSM meta-strategy player, which will you let you specify a player’s strategy by this transition matrix, along with an initial state and initial action. The syntax for this is:

```

>>> from axelrod.strategies.finite\_state\_machines import FSMPlayer

>>> grudger\_2 = FSMPlayer(transitions=grudger\_2\_transitions,

...                       initial\_state=1, initial\_action=C)

```

The library also includes the functionality to compute the memory from the set of transitions. In the grudger\_2 example, the memory would be 2. Because either the strategy’s own previous move was a defect (in which case, continue to defect) or we just need to check if the last two opponent moves were defects or not. Though this function takes the transitions in a slightly different format:

```

>>> transition\_dict = {

...    (t[0], t[1]): (t[2], t[3]) for t in grudger\_2\_transitions

... }

>>> from axelrod.compute\_finite\_state\_machine\_memory import \*

>>> get\_memory\_from\_transitions(transitions=transition\_dict,

...                             initial\_state=1)

2

```

#### Overview of past Tournaments[¶](#overview-of-past-tournaments "Permalink to this headline")

##### Axelrod’s first tournament[¶](#axelrod-s-first-tournament "Permalink to this headline")

Axelrod’s first tournament is described in his 1980 paper entitled [‘Effective

choice in the Prisoner’s Dilemma’](http://www.jstor.org/stable/173932) [[Axelrod1980]](index.html#axelrod1980). This

tournament included 14 strategies (plus a random “strategy”) and they are listed

below, (ranked in the order in which they appeared).

An indication is given as to whether or not this strategy is implemented in the

`axelrod` library. If this strategy is not implemented please do send us a

[pull request](https://github.com/Axelrod-Python/Axelrod/pulls).

Strategies in Axelrod’s first tournament[¶](#id20 "Permalink to this table")

| Name | Author | Axelrod Library Name |

| --- | --- | --- |

| Tit For Tat | Anatol Rapoport | [`TitForTat`](index.html#axelrod.strategies.titfortat.TitForTat "axelrod.strategies.titfortat.TitForTat") |

| Tideman and Chieruzzi | T Nicolaus Tideman and Paula Chieruzz | [`TidemanAndChieruzzi`](index.html#axelrod.strategies.axelrod_first.FirstByTidemanAndChieruzzi "axelrod.strategies.axelrod_first.FirstByTidemanAndChieruzzi") |

| Nydegger | Rudy Nydegger | [`Nydegger`](index.html#axelrod.strategies.axelrod_first.FirstByNydegger "axelrod.strategies.axelrod_first.FirstByNydegger") |

| Grofman | Bernard Grofman | [`Grofman`](index.html#axelrod.strategies.axelrod_first.FirstByGrofman "axelrod.strategies.axelrod_first.FirstByGrofman") |

| Shubik | Martin Shubik | [`Shubik`](index.html#axelrod.strategies.axelrod_first.FirstByShubik "axelrod.strategies.axelrod_first.FirstByShubik") |

| Stein and Rapoport | Stein and Anatol Rapoport | [`SteinAndRapoport`](index.html#axelrod.strategies.axelrod_first.FirstBySteinAndRapoport "axelrod.strategies.axelrod_first.FirstBySteinAndRapoport") |

| Grudger | James W Friedman | [`Grudger`](index.html#axelrod.strategies.grudger.Grudger "axelrod.strategies.grudger.Grudger") |

| Davis | Morton Davis | [`Davis`](index.html#axelrod.strategies.axelrod_first.FirstByDavis "axelrod.strategies.axelrod_first.FirstByDavis") |

| Graaskamp | Jim Graaskamp | [`Graaskamp`](index.html#axelrod.strategies.axelrod_first.FirstByGraaskamp "axelrod.strategies.axelrod_first.FirstByGraaskamp") |

| FirstByDowning | Leslie Downing | [`RevisedDowning`](index.html#axelrod.strategies.axelrod_first.FirstByDowning "axelrod.strategies.axelrod_first.FirstByDowning") |

| Feld | Scott Feld | [`Feld`](index.html#axelrod.strategies.axelrod_first.FirstByFeld "axelrod.strategies.axelrod_first.FirstByFeld") |

| Joss | Johann Joss | [`Joss`](index.html#axelrod.strategies.axelrod_first.FirstByJoss "axelrod.strategies.axelrod_first.FirstByJoss") |

| Tullock | Gordon Tullock | [`Tullock`](index.html#axelrod.strategies.axelrod_first.FirstByTullock "axelrod.strategies.axelrod_first.FirstByTullock") |

| (Name withheld) | Unknown | `UnnamedStrategy` |

| Random | Unknownd | [`Random`](index.html#axelrod.strategies.rand.Random "axelrod.strategies.rand.Random") |

##### Axelrod’s second tournament[¶](#axelrod-s-second-tournament "Permalink to this headline")

The code for Axelrod’s second touranment was originally published by the

[University of Michigan Center for the Study of Complex Systems](http://lsa.umich.edu/cscs/)

and is now available from

[Robert Axelrod’s personal website](http://www-personal.umich.edu/~axe/research/Software/CC/CC2.html)

subject to a [disclaimer](http://www-personal.umich.edu/~axe/research/Software/CC/CCDisclaimer.html)

which states:

> 

> “All materials in this archive are copyright (c) 1996, Robert Axelrod, unless

> otherwise noted. You are free to download these materials and use them without

> restriction.”

The Axelrod-Python organisation has published a

[modified version of the original code](https://github.com/Axelrod-Python/TourExec).

In the following table, links to original code point to the Axelrod-Python

repository.

Strategies in Axelrod’s second tournament[¶](#id21 "Permalink to this table")

| Original Code | Author | Axelrod Library Name |

| --- | --- | --- |

| [GRASR](https://github.com/Axelrod-Python/TourExec/blob/v0.2.0/src/strategies/grasr.f) | Unknown | Not Implemented |

| [K31R](https://github.com/Axelrod-Python/TourExec/blob/v0.2.0/src/strategies/k31r.f) | Gail Grisell | [`GoByMajority`](index.html#axelrod.strategies.gobymajority.GoByMajority "axelrod.strategies.gobymajority.GoByMajority") |

| [K32R](https://github.com/Axelrod-Python/TourExec/blob/v0.2.0/src/strategies/k32r.f) | Charles Kluepfel | [`SecondByKluepfel`](index.html#axelrod.strategies.axelrod_second.SecondByKluepfel "axelrod.strategies.axelrod_second.SecondByKluepfel") |

| [K33R](https://github.com/Axelrod-Python/TourExec/blob/v0.2.0/src/strategies/k33r.f) | Harold Rabbie | Not Implemented |

| [K34R](https://github.com/Axelrod-Python/TourExec/blob/v0.2.0/src/strategies/k34r.f) | James W Friedman | [`Grudger`](index.html#axelrod.strategies.grudger.Grudger "axelrod.strategies.grudger.Grudger") |

| [K35R](https://github.com/Axelrod-Python/TourExec/blob/v0.2.0/src/strategies/k35r.f) | Abraham Getzler | Not Implemented |

| [K36R](https://github.com/Axelrod-Python/TourExec/blob/v0.2.0/src/strategies/k36r.f) | Roger Hotz | Not Implemented |

| [K37R](https://github.com/Axelrod-Python/TourExec/blob/v0.2.0/src/strategies/k37r.f) | George Lefevre | Not Implemented |

| [K38R](https://github.com/Axelrod-Python/TourExec/blob/v0.2.0/src/strategies/k38r.f) | Nelson Weiderman | Not Implemented |

| [K39R](https://github.com/Axelrod-Python/TourExec/blob/v0.2.0/src/strategies/k39r.f) | Tom Almy | Not Implemented |

| [K40R](https://github.com/Axelrod-Python/TourExec/blob/v0.2.0/src/strategies/k40r.f) | Robert Adams | Not Implemented |

| [K41R](https://github.com/Axelrod-Python/TourExec/blob/v0.2.0/src/strategies/k41r.f) | Herb Weiner | [`SecondByWeiner`](index.html#axelrod.strategies.axelrod_second.SecondByWeiner "axelrod.strategies.axelrod_second.SecondByWeiner") |

| [K42R](https://github.com/Axelrod-Python/TourExec/blob/v0.2.0/src/strategies/k42r.f) | Otto Borufsen | [`SecondByBorufsen`](index.html#axelrod.strategies.axelrod_second.SecondByBorufsen "axelrod.strategies.axelrod_second.SecondByBorufsen") |

| [K43R](https://github.com/Axelrod-Python/TourExec/blob/v0.2.0/src/strategies/k43r.f) | R D Anderson | Not Implemented |

| [K44R](https://github.com/Axelrod-Python/TourExec/blob/v0.2.0/src/strategies/k44r.f) | William Adams | [`SecondByWmAdams`](index.html#axelrod.strategies.axelrod_second.SecondByWmAdams "axelrod.strategies.axelrod_second.SecondByWmAdams") |

| [K45R](https://github.com/Axelrod-Python/TourExec/blob/v0.2.0/src/strategies/k45r.f) | Michael F McGurrin | Not Implemented |

| [K46R](https://github.com/Axelrod-Python/TourExec/blob/v0.2.0/src/strategies/k46r.f) | Graham J Eatherley | [`SecondByEatherley`](index.html#axelrod.strategies.axelrod_second.SecondByEatherley "axelrod.strategies.axelrod_second.SecondByEatherley") |

| [K47R](https://github.com/Axelrod-Python/TourExec/blob/v0.2.0/src/strategies/k47r.f) | Richard Hufford | [`SecondByRichardHufford`](index.html#axelrod.strategies.axelrod_second.SecondByRichardHufford "axelrod.strategies.axelrod_second.SecondByRichardHufford") |

| [K48R](https://github.com/Axelrod-Python/TourExec/blob/v0.2.0/src/strategies/k48r.f) | George Hufford | Not Implemented |

| [K49R](https://github.com/Axelrod-Python/TourExec/blob/v0.2.0/src/strategies/k49r.f) | Rob Cave | [`SecondByCave`](index.html#axelrod.strategies.axelrod_second.SecondByCave "axelrod.strategies.axelrod_second.SecondByCave") |

| [K50R](https://github.com/Axelrod-Python/TourExec/blob/v0.2.0/src/strategies/k50r.f) | Rik Smoody | Not Implemented |

| [K51R](https://github.com/Axelrod-Python/TourExec/blob/v0.2.0/src/strategies/k51r.f) | John Willaim Colbert | Not Implemented |

| [K52R](https://github.com/Axelrod-Python/TourExec/blob/v0.2.0/src/strategies/k52r.f) | David A Smith | Not Implemented |

| [K53R](https://github.com/Axelrod-Python/TourExec/blob/v0.2.0/src/strategies/k53r.f) | Henry Nussbacher | Not Implemented |

| [K54R](https://github.com/Axelrod-Python/TourExec/blob/v0.2.0/src/strategies/k54r.f) | William H Robertson | Not Implemented |

| [K55R](https://github.com/Axelrod-Python/TourExec/blob/v0.2.0/src/strategies/k55r.f) | Steve Newman | Not Implemented |

| [K56R](https://github.com/Axelrod-Python/TourExec/blob/v0.2.0/src/strategies/k56r.f) | Stanley F Quayle | Not Implemented |

| [K57R](https://github.com/Axelrod-Python/TourExec/blob/v0.2.0/src/strategies/k57r.f) | Rudy Nydegger | Not Implemented |

| [K58R](https://github.com/Axelrod-Python/TourExec/blob/v0.2.0/src/strategies/k58r.f) | Glen Rowsam | [`SecondByRowsam`](index.html#axelrod.strategies.axelrod_second.SecondByRowsam "axelrod.strategies.axelrod_second.SecondByRowsam") |

| [K59R](https://github.com/Axelrod-Python/TourExec/blob/v0.2.0/src/strategies/K59R.f) | Leslie Downing | [`RevisedDowning`](index.html#axelrod.strategies.revised_downing.RevisedDowning "axelrod.strategies.revised_downing.RevisedDowning") |

| [K60R](https://github.com/Axelrod-Python/TourExec/blob/v0.2.0/src/strategies/k60r.f) | Jim Graaskamp and Ken Katzen | [`SecondByGraaskampKatzen`](index.html#axelrod.strategies.axelrod_second.SecondByGraaskampKatzen "axelrod.strategies.axelrod_second.SecondByGraaskampKatzen") |

| [K61R](https://github.com/Axelrod-Python/TourExec/blob/v0.2.0/src/strategies/k61r.f) | Danny C Champion | [`SecondByChampion`](index.html#axelrod.strategies.axelrod_second.SecondByChampion "axelrod.strategies.axelrod_second.SecondByChampion") |

| [K62R](https://github.com/Axelrod-Python/TourExec/blob/v0.2.0/src/strategies/k62r.f) | Howard R Hollander | Not Implemented |

| [K63R](https://github.com/Axelrod-Python/TourExec/blob/v0.2.0/src/strategies/k63r.f) | George Duisman | Not Implemented |

| [K64R](https://github.com/Axelrod-Python/TourExec/blob/v0.2.0/src/strategies/k64r.f) | Brian Yamachi | [`SecondByYamachi`](index.html#axelrod.strategies.axelrod_second.SecondByYamachi "axelrod.strategies.axelrod_second.SecondByYamachi") |

| [K65R](https://github.com/Axelrod-Python/TourExec/blob/v0.2.0/src/strategies/k65r.f) | Mark F Batell | Not Implemented |

| [K66R](https://github.com/Axelrod-Python/TourExec/blob/v0.2.0/src/strategies/k66r.f) | Ray Mikkelson | Not Implemented |

| [K67R](https://github.com/Axelrod-Python/TourExec/blob/v0.2.0/src/strategies/k67r.f) | Craig Feathers | [`SecondByTranquilizer`](index.html#axelrod.strategies.axelrod_second.SecondByTranquilizer "axelrod.strategies.axelrod_second.SecondByTranquilizer") |

| [K68R](https://github.com/Axelrod-Python/TourExec/blob/v0.2.0/src/strategies/k68r.f) | Fransois Leyvraz | [`SecondByLeyvraz`](index.html#axelrod.strategies.axelrod_second.SecondByLeyvraz "axelrod.strategies.axelrod_second.SecondByLeyvraz") |

| [K69R](https://github.com/Axelrod-Python/TourExec/blob/v0.2.0/src/strategies/k69r.f) | Johann Joss | Not Implemented |

| [K70R](https://github.com/Axelrod-Python/TourExec/blob/v0.2.0/src/strategies/k70r.f) | Robert Pebly | Not Implemented |

| [K71R](https://github.com/Axelrod-Python/TourExec/blob/v0.2.0/src/strategies/k71r.f) | James E Hall | Not Implemented |

| [K72R](https://github.com/Axelrod-Python/TourExec/blob/v0.2.0/src/strategies/k72r.f) | Edward C White Jr | [`SecondByWhite`](index.html#axelrod.strategies.axelrod_second.SecondByWhite "axelrod.strategies.axelrod_second.SecondByWhite") |

| [K73R](https://github.com/Axelrod-Python/TourExec/blob/v0.2.0/src/strategies/K73R.f) | George Zimmerman | Not Implemented |

| [K74R](https://github.com/Axelrod-Python/TourExec/blob/v0.2.0/src/strategies/K74R.f) | Edward Friedland | Not Implemented |

| [K74RXX](https://github.com/Axelrod-Python/TourExec/blob/v0.2.0/src/strategies/K74RXX.f) | Edward Friedland | Not Implemented |

| [K75R](https://github.com/Axelrod-Python/TourExec/blob/v0.2.0/src/strategies/K75R.f) | Paul D Harrington | [`SecondByHarrington`](index.html#axelrod.strategies.axelrod_second.SecondByHarrington "axelrod.strategies.axelrod_second.SecondByHarrington") |

| [K76R](https://github.com/Axelrod-Python/TourExec/blob/v0.2.0/src/strategies/k76r.f) | David Gladstein | [`SecondByGladstein`](index.html#axelrod.strategies.axelrod_second.SecondByGladstein "axelrod.strategies.axelrod_second.SecondByGladstein") |

| [K77R](https://github.com/Axelrod-Python/TourExec/blob/v0.2.0/src/strategies/k77r.f) | Scott Feld | Not Implemented |

| [K78R](https://github.com/Axelrod-Python/TourExec/blob/v0.2.0/src/strategies/k78r.f) | Fred Mauk | Not Implemented |

| [K79R](https://github.com/Axelrod-Python/TourExec/blob/v0.2.0/src/strategies/k79r.f) | Dennis Ambuehl and Kevin Hickey | Not Implemented |

| [K80R](https://github.com/Axelrod-Python/TourExec/blob/v0.2.0/src/strategies/k80r.f) | Robyn M Dawes and Mark Batell | Not Implemented |

| [K81R](https://github.com/Axelrod-Python/TourExec/blob/v0.2.0/src/strategies/k81r.f) | Martyn Jones | Not Implemented |

| [K82R](https://github.com/Axelrod-Python/TourExec/blob/v0.2.0/src/strategies/k82r.f) | Robert A Leyland | Not Implemented |

| [K83R](https://github.com/Axelrod-Python/TourExec/blob/v0.2.0/src/strategies/k83r.f) | Paul E Black | [`SecondByWhite`](index.html#axelrod.strategies.axelrod_second.SecondByWhite "axelrod.strategies.axelrod_second.SecondByWhite") |

| [K84R](https://github.com/Axelrod-Python/TourExec/blob/v0.2.0/src/strategies/k84r.f) | T Nicolaus Tideman and Paula Chieruzzi | [`SecondByTidemanChieruzzi`](index.html#axelrod.strategies.axelrod_second.SecondByTidemanAndChieruzzi "axelrod.strategies.axelrod_second.SecondByTidemanAndChieruzzi") |

| [K85R](https://github.com/Axelrod-Python/TourExec/blob/v0.2.0/src/strategies/k85r.f) | Robert B Falk and James M Langsted | Not Implemented |

| [K86R](https://github.com/Axelrod-Python/TourExec/blob/v0.2.0/src/strategies/k86r.f) | Bernard Grofman | Not Implemented |

| [K87R](https://github.com/Axelrod-Python/TourExec/blob/v0.2.0/src/strategies/k87r.f) | E E H Schurmann | Not Implemented |

| [K88R](https://github.com/Axelrod-Python/TourExec/blob/v0.2.0/src/strategies/k88r.f) | Scott Appold | [`SecondByAppold`](index.html#axelrod.strategies.axelrod_second.SecondByAppold "axelrod.strategies.axelrod_second.SecondByAppold") |

| [K89R](https://github.com/Axelrod-Python/TourExec/blob/v0.2.0/src/strategies/k89r.f) | Gene Snodgrass | Not Implemented |

| [K90R](https://github.com/Axelrod-Python/TourExec/blob/v0.2.0/src/strategies/k90r.f) | John Maynard Smith | [`TitFor2Tats`](index.html#axelrod.strategies.titfortat.TitFor2Tats "axelrod.strategies.titfortat.TitFor2Tats") |

| [K91R](https://github.com/Axelrod-Python/TourExec/blob/v0.2.0/src/strategies/k91r.f) | Jonathan Pinkley | Not Implemented |

| [K92R](https://github.com/Axelrod-Python/TourExec/blob/v0.2.0/src/strategies/K92R.f) | Anatol Rapoport | [`TitForTat`](index.html#axelrod.strategies.titfortat.TitForTat "axelrod.strategies.titfortat.TitForTat") |

| [K93R](https://github.com/Axelrod-Python/TourExec/blob/v0.2.0/src/strategies/k93r.f) | Unknown | Not Implemented |

| [KPAVLOVC](https://github.com/Axelrod-Python/TourExec/blob/v0.2.0/src/strategies/KPavlovC.f) | Unknown | [`WinStayLoseShift`](index.html#axelrod.strategies.memoryone.WinStayLoseShift "axelrod.strategies.memoryone.WinStayLoseShift") |

| [KRANDOMC](https://github.com/Axelrod-Python/TourExec/blob/v0.2.0/src/strategies/KRandomC.f) | Unknown | [`Random`](index.html#axelrod.strategies.rand.Random "axelrod.strategies.rand.Random") |

| [KTF2TC](https://github.com/Axelrod-Python/TourExec/blob/v0.2.0/src/strategies/KTF2TC.f) | Unknown | [`TitFor2Tats`](index.html#axelrod.strategies.titfortat.TitFor2Tats "axelrod.strategies.titfortat.TitFor2Tats") |

| [KTITFORTATC](https://github.com/Axelrod-Python/TourExec/blob/v0.2.0/src/strategies/KTitForTatC.f) | Unknown | [`TitForTat`](index.html#axelrod.strategies.titfortat.TitForTat "axelrod.strategies.titfortat.TitForTat") |

##### Stewart and Plotkin’s Tournament (2012)[¶](#stewart-and-plotkin-s-tournament-2012 "Permalink to this headline")

In 2012, [Alexander Stewart and Joshua Plotkin](http://www.pnas.org/content/109/26/10134.full.pdf) ran a variant of

Axelrod’s tournament with 19 strategies to test the effectiveness of the then

newly discovered Zero-Determinant strategies.

The paper is identified as *doi: 10.1073/pnas.1208087109* and referred to as

[[Stewart2012]](index.html#stewart2012) below. Unfortunately the details of the tournament and the

implementation of strategies is not clear in the manuscript. We can, however,

make reasonable guesses to the implementation of many strategies based on their

names and classical definitions.

The following classical strategies are included in the library:

Strategies in Stewart and Plotkin’s tournament[¶](#id22 "Permalink to this table")

| S&P Name | Long Name | Axelrod Library Name |

| --- | --- | --- |

| ALLC | Always Cooperate | [`Cooperator`](index.html#axelrod.strategies.cooperator.Cooperator "axelrod.strategies.cooperator.Cooperator") |

| ALLD | Always Defect | [`Defector`](index.html#axelrod.strategies.defector.Defector "axelrod.strategies.defector.Defector") |

| [EXTORT-2](#extort-2) | Extort-2 | `ZDExtort2` |

| [HARD\_MAJO](#hard-majo) | Hard majority | [`HardGoByMajority`](index.html#axelrod.strategies.gobymajority.HardGoByMajority "axelrod.strategies.gobymajority.HardGoByMajority") |

| [HARD\_JOSS](#hard-joss) | Hard Joss | `Joss` |

| [HARD\_TFT](#hard-tft) | Hard tit for tat | [`HardTitForTat`](index.html#axelrod.strategies.titfortat.HardTitForTat "axelrod.strategies.titfortat.HardTitForTat") |

| [HARD\_TF2T](#hard-tf2t) | Hard tit for 2 tats | [`HardTitFor2Tats`](index.html#axelrod.strategies.titfortat.HardTitFor2Tats "axelrod.strategies.titfortat.HardTitFor2Tats") |

| TFT | Tit-For-Tat | [`TitForTat`](index.html#axelrod.strategies.titfortat.TitForTat "axelrod.strategies.titfortat.TitForTat") |

| [GRIM](#grim) | Grim | [`Grudger`](index.html#axelrod.strategies.grudger.Grudger "axelrod.strategies.grudger.Grudger") |

| [GTFT](#gtft) | Generous Tit-For-Tat | [`GTFT`](index.html#axelrod.strategies.memoryone.GTFT "axelrod.strategies.memoryone.GTFT") |

| [TF2T](#tf2t) | Tit-For-Two-Tats | [`TitFor2Tats`](index.html#axelrod.strategies.titfortat.TitFor2Tats "axelrod.strategies.titfortat.TitFor2Tats") |

| [WSLS](#wsls) | Win-Stay-Lose-Shift | [`WinStayLoseShift`](index.html#axelrod.strategies.memoryone.WinStayLoseShift "axelrod.strategies.memoryone.WinStayLoseShift") |

| RANDOM | Random | [`Random`](index.html#axelrod.strategies.rand.Random "axelrod.strategies.rand.Random") |

| [ZDGTFT-2](#zdgtft-2) | ZDGTFT-2 | `ZDGTFT2` |

ALLC, ALLD, TFT and RANDOM are defined above. The remaining classical

strategies are defined below. The tournament also included two Zero Determinant

strategies, both implemented in the library. The full table of strategies and

results is [available

online](https://www.pnas.org/content/pnas/109/26/10134/F1.large.jpg?width=800&height=600&carousel=1).

###### Memory one strategies[¶](#memory-one-strategies "Permalink to this headline")

In 2012 [Press and Dyson](http://www.pnas.org/content/109/26/10409.full.pdf)

[[Press2012]](index.html#press2012) showed interesting results with regards to so called memory one

strategies. Stewart and Plotkin implemented a number of these. A memory one

strategy is simply a probabilistic strategy that is defined by 4 parameters.

These four parameters dictate the probability of cooperating given 1 of 4

possible outcomes of the previous round:

* \(P(C\,|\,CC) = p\_1\)

* \(P(C\,|\,CD) = p\_2\)

* \(P(C\,|\,DC) = p\_3\)

* \(P(C\,|\,DD) = p\_4\)

The memory one strategy class is used to define a number of strategies below.

###### GTFT[¶](#gtft "Permalink to this headline")

Generous-Tit-For-Tat plays Tit-For-Tat with occasional forgiveness, which

prevents cycling defections against itself.

GTFT is defined as a memory-one strategy as follows:

* \(P(C\,|\,CC) = 1\)

* \(P(C\,|\,CD) = p\)

* \(P(C\,|\,DC) = 1\)

* \(P(C\,|\,DD) = p\)

where \(p = \min\left(1 - \frac{T-R}{R-S}, \frac{R-P}{T-P}\right)\).

*GTFT came 2nd in average score and 18th in wins in S&P’s tournament.*

###### TF2T[¶](#tf2t "Permalink to this headline")

Tit-For-Two-Tats is like Tit-For-Tat but only retaliates after two defections

rather than one. This is not a memory-one strategy.

*TF2T came 3rd in average score and last (?) in wins in S&P’s tournament.*

###### WSLS[¶](#wsls "Permalink to this headline")

Win-Stay-Lose-Shift is a strategy that shifts if the highest payoff was not

earned in the previous round. WSLS is also known as “Win-Stay-Lose-Switch” and

“Pavlov”. It can be seen as a memory-one strategy as follows:

* \(P(C\,|\,CC) = 1\)

* \(P(C\,|\,CD) = 0\)

* \(P(C\,|\,DC) = 0\)

* \(P(C\,|\,DD) = 1\)

*WSLS came 7th in average score and 13th in wins in S&P’s tournament.*

###### RANDOM[¶](#random "Permalink to this headline")

Random is a strategy that was defined in [Axelrod’s first tournament](#axelrod-s-first-tournament), note that this is also a memory-one strategy:

* \(P(C\,|\,CC) = 0.5\)

* \(P(C\,|\,CD) = 0.5\)

* \(P(C\,|\,DC) = 0.5\)

* \(P(C\,|\,DD) = 0.5\)

*RANDOM came 8th in average score and 8th in wins in S&P’s tournament.*

###### ZDGTFT-2[¶](#zdgtft-2 "Permalink to this headline")

This memory-one strategy is defined by the following four conditional

probabilities based on the last round of play:

* \(P(C\,|\,CC) = 1\)

* \(P(C\,|\,CD) = 1/8\)

* \(P(C\,|\,DC) = 1\)

* \(P(C\,|\,DD) = 1/4\)

*This strategy came 1st in average score and 16th in wins in S&P’s tournament.*

###### EXTORT-2[¶](#extort-2 "Permalink to this headline")

This memory-one strategy is defined by the following four conditional

probabilities based on the last round of play:

* \(P(C\,|\,CC) = 8/9\)

* \(P(C\,|\,CD) = 1/2\)

* \(P(C\,|\,DC) = 1/3\)

* \(P(C\,|\,DD) = 0\)

*This strategy came 18th in average score and 2nd in wins in S&P’s tournament.*

###### GRIM[¶](#grim "Permalink to this headline")

Grim is not defined in [[Stewart2012]](index.html#stewart2012) but it is defined elsewhere as follows.

GRIM (also called “Grim trigger”), cooperates until the opponent defects and

then always defects thereafter. In the library this strategy is called

*Grudger*.

*GRIM came 10th in average score and 11th in wins in S&P’s tournament.*

###### HARD\_JOSS[¶](#hard-joss "Permalink to this headline")

HARD\_JOSS is not defined in [[Stewart2012]](index.html#stewart2012) but is otherwise defined as a

strategy that plays like TitForTat but cooperates only with probability

\(0.9\). This is a memory-one strategy with the following probabilities:

* \(P(C\,|\,CC) = 0.9\)

* \(P(C\,|\,CD) = 0\)

* \(P(C\,|\,DC) = 1\)

* \(P(C\,|\,DD) = 0\)

*HARD\_JOSS came 16th in average score and 4th in wins in S&P’s tournament.*

HARD\_JOSS as described above is implemented in the library as Joss and is

the same as the Joss strategy from [Axelrod’s first tournament](#axelrod-s-first-tournament).

###### HARD\_MAJO[¶](#hard-majo "Permalink to this headline")

HARD\_MAJO is not defined in [[Stewart2012]](index.html#stewart2012) and is presumably the same as “Go by Majority”, defined as follows: the strategy defects on the first move, defects

if the number of defections of the opponent is greater than or equal to the

number of times it has cooperated, and otherwise cooperates,

*HARD\_MAJO came 13th in average score and 5th in wins in S&P’s tournament.*

###### HARD\_TFT[¶](#hard-tft "Permalink to this headline")

Hard TFT is not defined in [[Stewart2012]](index.html#stewart2012) but is

[elsewhere](http://www.prisoners-dilemma.com/strategies.html)

defined as follows. The strategy cooperates on the

first move, defects if the opponent has defected on any of the previous three

rounds, and otherwise cooperates.

*HARD\_TFT came 12th in average score and 10th in wins in S&P’s tournament.*

###### HARD\_TF2T[¶](#hard-tf2t "Permalink to this headline")

Hard TF2T is not defined in [[Stewart2012]](index.html#stewart2012) but is elsewhere defined as

follows. The strategy cooperates on the first move, defects if the opponent

has defected twice (successively) of the previous three rounds, and otherwise

cooperates.

*HARD\_TF2T came 6th in average score and 17th in wins in S&P’s tournament.*

###### Calculator[¶](#calculator "Permalink to this headline")

This strategy is not unambiguously defined in [[Stewart2012]](index.html#stewart2012) but is defined

elsewhere. Calculator plays like Joss for 20 rounds. On the 21 round,

Calculator attempts to detect a cycle in the opponents history, and defects

unconditionally thereafter if a cycle is found. Otherwise Calculator plays like

TFT for the remaining rounds.

###### Prober[¶](#prober "Permalink to this headline")

PROBE is not unambiguously defined in [[Stewart2012]](index.html#stewart2012) but is defined

elsewhere as Prober. The strategy starts by playing D, C, C on the first three

rounds and then defects forever if the opponent cooperates on rounds

two and three. Otherwise Prober plays as TitForTat would.

*Prober came 15th in average score and 9th in wins in S&P’s tournament.*

###### Prober2[¶](#prober2 "Permalink to this headline")

PROBE2 is not unambiguously defined in [[Stewart2012]](index.html#stewart2012) but is defined

elsewhere as Prober2. The strategy starts by playing D, C, C on the first three

rounds and then cooperates forever if the opponent played D then C on rounds

two and three. Otherwise Prober2 plays as TitForTat would.

*Prober2 came 9th in average score and 12th in wins in S&P’s tournament.*

###### Prober3[¶](#prober3 "Permalink to this headline")

PROBE3 is not unambiguously defined in [[Stewart2012]](index.html#stewart2012) but is defined

elsewhere as Prober3. The strategy starts by playing D, C on the first two

rounds and then defects forever if the opponent cooperated on round two.

Otherwise Prober3 plays as TitForTat would.

*Prober3 came 17th in average score and 7th in wins in S&P’s tournament.*

###### HardProber[¶](#hardprober "Permalink to this headline")

HARD\_PROBE is not unambiguously defined in [[Stewart2012]](index.html#stewart2012) but is defined

elsewhere as HardProber. The strategy starts by playing D, D, C, C on the first

four rounds and then defects forever if the opponent cooperates on rounds

two and three. Otherwise Prober plays as TitForTat would.

*HardProber came 5th in average score and 6th in wins in S&P’s tournament.*

###### NaiveProber[¶](#naiveprober "Permalink to this headline")

NAIVE\_PROBER is a modification of Tit For Tat strategy which with a small

probability randomly defects. Default value for a probability of defection is

0.1.

##### Beaufils et al.’s tournament (1997)[¶](#beaufils-et-al-s-tournament-1997 "Permalink to this headline")

In 1997, [[Beaufils1997]](index.html#beaufils1997) the authors used a tournament to describe a new

strategy of their called “Gradual”. The description given in the paper of

“Gradual” is:

> 

> This strategy acts as tit-for-tat, except when it is time to forgive and

> remember the past. It uses cooperation on the first move and then continues

> to do so as long as the other player cooperates. Then after the first

> defection of the other player, it defects one time and cooperates two times;

> after the second defection of the opponent, it defects two times and

> cooperates two times, … after the nth defection it reacts with n

> consecutive defections and then calms down its opponent with two

> cooperations.

This is the only description of the strategy however the paper does include a

table of results of the tournament. The scores of “Gradual” against the

opponents (including itself) are:

Score of Gradual reported in [[Beaufils1997]](index.html#beaufils1997)[¶](#id23 "Permalink to this table")

| Name | Name used in [[Beaufils1997]](index.html#beaufils1997) | Score (1000 turns) |

| --- | --- | --- |

| Cooperator | coop | 3000 |

| Defector | def | 915 |

| Random | rand | 2815 |

| Tit For Tat | tft | 3000 |

| Grudger | spite | 3000 |

| Cycler DDC | p\_nst | 2219 |

| Cycler CCD | p\_kn | 3472 |

| Go By Majority | sft\_mj | 3000 |

| Suspicious Tit For Tat | mist | 2996 |

| Prober | prob | 2999 |

| Gradual | grad | 3000 |

| Win Stay Lose Shift | pav | 3000 |

The following code reproduces the above:

```

>>> import axelrod as axl

>>> players = [axl.Cooperator(),

...            axl.Defector(),

...            axl.Random(),

...            axl.TitForTat(),

...            axl.Grudger(),

...            axl.CyclerDDC(),

...            axl.CyclerCCD(),

...            axl.GoByMajority(),

...            axl.SuspiciousTitForTat(),

...            axl.Prober(),

...            axl.OriginalGradual(),

...            axl.WinStayLoseShift(),

...            ]

>>> turns = 1000

>>> tournament = axl.Tournament(players, turns=turns, repetitions=1, seed=75)

>>> results = tournament.play(progress\_bar=False)

>>> for average\_score\_per\_turn in results.payoff\_matrix[-2]:

...     print(round(average\_score\_per\_turn \* turns, 1))

3000.0

915.0

2763.0

3000.0

3000.0

2219.0

3472.0

3000.0

2996.0

2999.0

3000.0

3000.0

```

The `OriginalGradual` strategy implemented has the following description:

> 

> A player that punishes defections with a growing number of defections

> but after punishing for punishment\_limit number of times enters a calming

> state and cooperates no matter what the opponent does for two rounds.

> 

> 

> The punishment\_limit is incremented whenever the opponent defects and the

> strategy is not in either calming or punishing state.

> 

> 

> 

Note that a different version of Gradual appears in [[CRISTAL-SMAC2018]](index.html#cristal-smac2018).

This was brought to the attention of the maintainers of the library by one of the

authors of [[Beaufils1997]](index.html#beaufils1997) and is documented here <https://github.com/Axelrod-Python/Axelrod/issues/1294>.

The strategy implemented in [[CRISTAL-SMAC2018]](index.html#cristal-smac2018) and defined here as `Gradual` has the following description:

> 

> Similar to OriginalGradual, this is a player that punishes defections with a

> growing number of defections but after punishing for punishment\_limit

> number of times enters a calming state and cooperates no matter what the

> opponent does for two rounds.

> 

> 

> This version of Gradual is an update of OriginalGradual and the difference

> is that the punishment\_limit is incremented whenever the opponent defects

> (regardless of the state of the player).

> 

> 

> 

This highlights the importance of best practice and reproducible computational

research. Both strategies implemented in this library are fully tested and

documented clearly and precisely.

#### Play Contexts and Generic Prisoner’s Dilemma[¶](#play-contexts-and-generic-prisoner-s-dilemma "Permalink to this headline")

There are four possible round outcomes:

* Mutual cooperation: \((C, C)\)

* Defection: \((C, D)\) or \((D, C)\)

* Mutual defection: \((D, D)\)

Each of these corresponds to one particular set of payoffs in the following

generic Prisoner’s dilemma:

|  | Cooperate | Defect |

| --- | --- | --- |

| Cooperate | (R,R) | (S,T) |

| Defect | (T,S) | (P,P) |

For the above to constitute a Prisoner’s dilemma, the following must hold:

\(T>R>P>S\).

These payoffs are commonly referred to as:

* \(R\): the **Reward** payoff (default value in the library: 3)

* \(P\): the **Punishment** payoff (default value in the library: 1)

* \(S\): the **Sucker** payoff (default value in the library: 0)

* \(T\): the **Temptation** payoff (default value in the library: 5)

A particular Prisoner’s Dilemma is often described by the 4-tuple: \((R, P,

S, T)\):

```

>>> import axelrod

>>> axelrod.game.DefaultGame.RPST()

(3, 1, 0, 5)

```

#### Community[¶](#community "Permalink to this headline")

Contents:

##### Part of the team[¶](#part-of-the-team "Permalink to this headline")

If you’re reading this you’re probably interested in contributing to and/or

using the Axelrod library! Firstly: **thank you** and **welcome**!

We are proud of the library and the environment that surrounds it. A primary

goal of the project is to cultivate an open and welcoming community, considerate

and respectful to newcomers to python and game theory.

The Axelrod library has been a first contribution to open source software for

many, and this is in large part due to the fact that we all aim to help and

encourage all levels of contribution. If you’re a beginner, that’s awesome!

You’re very welcome and don’t hesitate to ask for help.

**With regards to any contribution**, please do not feel the need to wait until

your contribution is perfectly polished and complete: we’re happy to offer

early feedback, help with git, and anything else that you need to have a

positive experience.

**If you are using the library for your own work** and there’s anything in the

documentation that is unclear: we want to know so that we can fix it. We also

want to help so please don’t hesitate to get in touch.

##### Communication[¶](#communication "Permalink to this headline")

There are various ways of communicating with the team:

* [Gitter: a web based chat client, you can talk directly to the users and

maintainers of the library.](https://gitter.im/Axelrod-Python/Axelrod)

* Irc: we have an irc channel. It’s #axelrod-python on freenode.

* [Email forum.](https://groups.google.com/forum/#!forum/axelrod-python)

* [Issues: you are also very welcome to open an issue on

github](https://github.com/Axelrod-Python/Axelrod/issues)

* [Twitter.](https://twitter.com/AxelrodPython) This account periodically

tweets out random match and tournament results; you’re welcome to get in

touch through twitter as well.

##### Code of Conduct[¶](#code-of-conduct "Permalink to this headline")

###### Our Pledge[¶](#our-pledge "Permalink to this headline")

In the interest of fostering an open and welcoming environment, we as

contributors and maintainers pledge to making participation in our project and

our community a harassment-free experience for everyone, regardless of age, body

size, disability, ethnicity, gender identity and expression, level of experience,

nationality, personal appearance, race, religion, or sexual identity and

orientation.

###### Our Standards[¶](#our-standards "Permalink to this headline")

Examples of behavior that contributes to creating a positive environment

include:

* Using welcoming and inclusive language

* Being respectful of differing viewpoints and experiences

* Gracefully accepting constructive criticism

* Focusing on what is best for the community

* Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or advances

* Trolling, insulting/derogatory comments, and personal or political attacks

* Public or private harassment

* Publishing others’ private information, such as a physical or electronic address, without explicit permission

* Other conduct which could reasonably be considered inappropriate in a professional setting

###### Our Responsibilities[¶](#our-responsibilities "Permalink to this headline")

Project maintainers are responsible for clarifying the standards of acceptable

behavior and are expected to take appropriate and fair corrective action in

response to any instances of unacceptable behavior.

Project maintainers have the right and responsibility to remove, edit, or

reject comments, commits, code, wiki edits, issues, and other contributions

that are not aligned to this Code of Conduct, or to ban temporarily or

permanently any contributor for other behaviors that they deem inappropriate,

threatening, offensive, or harmful.

###### Scope[¶](#scope "Permalink to this headline")

This Code of Conduct applies both within project spaces and in public spaces

when an individual is representing the project or its community. Examples of

representing a project or community include using an official project e-mail

address, posting via an official social media account, or acting as an appointed

representative at an online or offline event. Representation of a project may be

further defined and clarified by project maintainers.

###### Enforcement[¶](#enforcement "Permalink to this headline")

Instances of abusive, harassing, or otherwise unacceptable behavior may be

reported by contacting a member of the core team. All

complaints will be reviewed and investigated and will result in a response that

is deemed necessary and appropriate to the circumstances. The project team is

obligated to maintain confidentiality with regard to the reporter of an incident.

Further details of specific enforcement policies may be posted separately.

Project maintainers who do not follow or enforce the Code of Conduct in good

faith may face temporary or permanent repercussions as determined by other

members of the project’s leadership.

###### Attribution[¶](#attribution "Permalink to this headline")

This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.4,

available at <http://contributor-covenant.org/version/1/4>

### Reference[¶](#reference "Permalink to this headline")

This section is the reference guide for the various components of the library.

#### Bibliography[¶](#bibliography "Permalink to this headline")

This is a collection of various bibliographic items referenced in the

documentation.

| [Adami2013] | Adami C and Hintze A. (2013) Evolutionary instability of zero-determinant strategies demonstrates that winning is not everything. Nature communications. <https://www.nature.com/articles/ncomms3193> |

| [Akin2015] | Akin, Ethan. “What you gotta know to play good in the Iterated Prisoner’s Dilemma.” Games 6.3 (2015): 175-190. |

| [Amaral2016] | Amaral, M. A., Wardil, L., Perc, M., & Da Silva, J. K. L. (2016). Stochastic win-stay-lose-shift strategy with dynamic aspirations in evolutionary social dilemmas. Physical Review E - Statistical, Nonlinear, and Soft Matter Physics, 94(3), 1–9. <https://doi.org/10.1103/PhysRevE.94.032317> |

| [Andre2013] | Andre L. C., Honovan P., Felipe T. and Frederico G. (2013). Iterated Prisoner’s Dilemma - An extended analysis, <http://abricom.org.br/wp-content/uploads/2016/03/bricsccicbic2013_submission_202.pdf> |

| [Ashlock2006] | Ashlock, D., & Kim E. Y, & Leahy, N. (2006). Understanding Representational Sensitivity in the Iterated Prisoner’s Dilemma with Fingerprints. IEEE Transactions On Systems, Man, And Cybernetics, Part C: Applications And Reviews, 36 (4) |

| [Ashlock2006b] | Ashlock, W. & Ashlock, D. (2006). Changes in Prisoner’s Dilemma Strategies Over Evolutionary Time With Different Population Sizes 2006 IEEE International Conference on Evolutionary Computation. <http://DOI.org/10.1109/CEC.2006.1688322> |

| [Ashlock2008] | Ashlock, D., & Kim, E. Y. (2008). Fingerprinting: Visualization and automatic analysis of prisoner’s dilemma strategies. IEEE Transactions on Evolutionary Computation, 12(5), 647–659. <http://doi.org/10.1109/TEVC.2008.920675> |

| [Ashlock2009] | Ashlock, D., Kim, E. Y., & Ashlock, W. (2009) Fingerprint analysis of the noisy prisoner’s dilemma using a finite-state representation. IEEE Transactions on Computational Intelligence and AI in Games. 1(2), 154-167 <http://doi.org/10.1109/TCIAIG.2009.2018704> |

| [Ashlock2014] | Ashlock, W., Tsang, J. & Ashlock, D. (2014) The evolution of exploitation. 2014 IEEE Symposium on Foundations of Computational Intelligence (FOCI) <http://DOI.org/10.1109/FOCI.2014.7007818> |

| [Ashlock2015] | Ashlock, D., Brown, J.A., & Hingston P. (2015). Multiple Opponent Optimization of Prisoner’s Dilemma Playing Agents. Multiple Opponent Optimization of Prisoner’s Dilemma Playing Agents <http://DOI.org/10.1109/TCIAIG.2014.2326012> |

| [Au2006] | Au, T.-C. and Nau, D. S. (2006) Accident or intention: That is the question (in the iterated prisoner’s dilemma). In Proc. Int. Conf. Auton. Agents and Multiagent Syst. (AAMAS), pp. 561–568. <http://www.cs.umd.edu/~nau/papers/au2006accident.pdf> |

| [Axelrod1980] | Axelrod, R. (1980). Effective Choice in the Prisoner’s Dilemma. Journal of Conflict Resolution, 24(1), 3–25. |

| [Axelrod1980b] | Axelrod, R. (1980). More Effective Choice in the Prisoner’s Dilemma. Journal of Conflict Resolution, 24(3), 379-403. |

| [Axelrod1984] | The Evolution of Cooperation. Basic Books. ISBN 0-465-02121-2. |

| [Axelrod1995] | Wu, J. and Axelrod, R. (1995). How to cope with noise in the Iterated prisoner’s dilemma, Journal of Conflict Resolution, 39(1), pp. 183–189. doi: 10.1177/0022002795039001008. |

| [Banks1990] | Banks, J. S., & Sundaram, R. K. (1990). Repeated games, finite automata, and complexity. Games and Economic Behavior, 2(2), 97–117. <http://doi.org/10.1016/0899-8256(90)90024-O> |

| [Bendor1993] | Bendor, Jonathan. “Uncertainty and the Evolution of Cooperation.” The Journal of Conflict Resolution, 37(4), 709–734. |

| [Beaufils1997] | Beaufils, B. & Delahaye, J. & Mathieu, P. (1997). Our Meeting With Gradual: A Good Strategy For The Iterated Prisoner’s Dilemma. <http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.42.4041> |

| [Berg2015] | Berg, P. Van Den, & Weissing, F. J. (2015). The importance of mechanisms for the evolution of cooperation. Proceedings of the Royal Society B-Biological Sciences, 282. |

| [CRISTAL-SMAC2018] | CRISTAL Lab, SMAC Team, Lille University (2018). IPD : the Iterated Prisoner’s Dilemma. <https://github.com/cristal-smac/ipd> |

| [Downing1975] | Downing, Leslie L. “The Prisoner’s Dilemma game as a problem-solving phenomenon: An outcome maximization interpretation.” Simulation & Games 6.4 (1975): 366-391. |

| [Eckhart2015] | Eckhart Arnold (2016) CoopSim v0.9.9 beta 6. <https://github.com/jecki/CoopSim/> |

| [Frean1994] | Frean, Marcus R. “The Prisoner’s Dilemma without Synchrony.” Proceedings: Biological Sciences, vol. 257, no. 1348, 1994, pp. 75–79. www.jstor.org/stable/50253. |

| [Harper2017] | Harper, M., Knight, V., Jones, M., Koutsovoulos, G., Glynatsi, N. E., & Campbell, O. (2017) Reinforcement learning produces dominant strategies for the Iterated Prisoner’s Dilemma. PloS one. <https://doi.org/10.1371/journal.pone.0188046> |

| [Hauert2002] | Hauert, Christoph, and Olaf Stenull. “Simple adaptive strategy wins the prisoner’s dilemma.” Journal of Theoretical Biology 218.3 (2002): 261-272. |

| [Hilbe2013] | Hilbe, C., Nowak, M.A. and Traulsen, A. (2013). Adaptive dynamics of extortion and compliance, PLoS ONE, 8(11), p. e77886. doi: 10.1371/journal.pone.0077886. |

| [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. |

| [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/> |

| [Kraines1989] | Kraines, David, and Vivian Kraines. “Pavlov and the prisoner’s dilemma.” Theory and decision 26.1 (1989): 47-79. doi:10.1007/BF00134056 |

| [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> |

| [LessWrong2011] | Zoo of Strategies (2011) LessWrong. Available at: <http://lesswrong.com/lw/7f2/prisoners_dilemma_tournament_results/> |

| [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. |

| [Li2009] | Li, J. & Kendall, G. (2009). A Strategy with Novel Evolutionary Features for the Iterated Prisoner’s Dilemma. Evolutionary Computation 17(2): 257–274. |

| [Li2011] | Li, J., Hingston, P., Member, S., & Kendall, G. (2011). Engineering Design of Strategies for Winning Iterated Prisoner ’ s Dilemma Competitions, 3(4), 348–360. |

| [Li2014] | Li, J. and Kendall, G. (2014). The Effect of Memory Size on the Evolutionary Stability of Strategies in Iterated Prisoner’s Dilemma. IEEE Transactions on Evolutionary Computation, 18(6) 819-826 |

| [LiS2014] | Li, Siwei. (2014). Strategies in the Stochastic Iterated Prisoner’s Dilemma. Available at: <http://math.uchicago.edu/~may/REU2014/REUPapers/Li,Siwei.pdf> |

| [Luis2008] | Luis R. Izquierdo and Segismundo S. Izquierdo (2008). Dynamics of the Bush-Mosteller Learning Algorithm in 2x2 Games, Reinforcement Learning, Cornelius Weber, Mark Elshaw and Norbert Michael Mayer (Ed.), InTech, DOI: 10.5772/5282. Available from: <https://www.intechopen.com/books/reinforcement_learning/dynamics_of_the_bush-mosteller_learning_algorithm_in_2x2_games> |

| [Marinoff1992] | Marinoff, Louis. (1992). Maximizing expected utilities in the prisoner’s dilemma. Journal of Conflict Resolution 36.1: 183-216. |

| [Mathieu2015] | Mathieu, P. and Delahaye, J. (2015). New Winning Strategies for the Iterated Prisoner’s Dilemma. Proceedings of the 2015 International Conference on Autonomous Agents and Multiagent Systems. |

| [Mittal2009] | Mittal, S., & Deb, K. (2009). Optimal strategies of the iterated prisoner’s dilemma problem for multiple conflicting objectives. IEEE Transactions on Evolutionary Computation, 13(3), 554–565. <https://doi.org/10.1109/TEVC.2008.2009459> |

| [Murase2020] | Murase, Y., & Baek, S.K. (2020). Five Rules for Friendly Rivalry in Direct Reciprocity. Scientific Reports 10:16904 <https://doi.org/10.1038/s41598-020-73855-x> |

| [Nachbar1992] | Nachbar J., Evolution in the finitely repeated prisoner’s dilemma, Journal of Economic Behavior & Organization, 19(3): 307-326, 1992. |

| [NC2019] | <https://github.com/ncase/trust> (Accessed: 30 October 2019) |

| [Nowak1989] | Nowak, Martin, and Karl Sigmund. “Game-dynamical aspects of the prisoner’s dilemma.” Applied Mathematics and Computation 30.3 (1989): 191-213. |

| [Nowak1990] | Nowak, M., & Sigmund, K. (1990). The evolution of stochastic strategies in the Prisoner’s Dilemma. Acta Applicandae Mathematica. <https://link.springer.com/article/10.1007/BF00049570> |

| [Nowak1992] | Nowak, M.., & May, R. M. (1992). Evolutionary games and spatial chaos. Nature. <http://doi.org/10.1038/359826a0> |

| [Nowak1993] | Nowak, M., & Sigmund, K. (1993). A strategy of win-stay, lose-shift that outperforms tit-for-tat in the Prisoner’s Dilemma game. Nature, 364(6432), 56–58. <http://doi.org/10.1038/364056a0> |

| [Ohtsuki2006] | Ohtsuki, Hisashi, et al. “A simple rule for the evolution of cooperation on graphs and social networks.” Nature 441.7092 (2006): 502. |

| [PD2017] | <http://www.prisoners-dilemma.com/competition.html> (Accessed: 6 June 2017). Archived at <https://web.archive.org/web/20171227021632/http://www.prisoners-dilemma.com/competition.html> |

| [Press2012] | Press, W. H., & Dyson, F. J. (2012). Iterated Prisoner’s Dilemma contains strategies that dominate any evolutionary opponent. Proceedings of the National Academy of Sciences, 109(26), 10409–10413. <http://doi.org/10.1073/pnas.1206569109> |

| [Prison1998] | LIFL (1998) PRISON. Available at: <http://www.lifl.fr/IPD/ipd.frame.html> (Accessed: 19 September 2016). |

| [Robson1990] | Robson, Arthur J. “Efficiency in evolutionary games: Darwin, Nash and the secret handshake.” Journal of theoretical Biology 144.3 (1990): 379-396. |

| [Roemheld2013] | Roemheld, Lars. “Evolutionary Extortion and Mischief: Zero Determinant strategies in iterated 2x2 games”. Available at: <https://arxiv.org/abs/1308.2576> |

| [Singer-Clark2014] | Singer-Clark, T. (2014). Morality Metrics On Iterated Prisoner’s Dilemma Players. |

| [Shakarian2013] | Shakarian, P., Roos, P. & Moores, G. A Novel Analytical Method for Evolutionary Graph Theory Problems. |

| [Slany2007] | Slany W. and Kienreich W., On some winning strategies for the iterated prisoner’s dilemma, in Kendall G., Yao X. and Chong S. (eds.) The iterated prisoner’s dilemma: 20 years on. World Scientific, chapter 8, pp. 171-204, 2007. |

| [Stewart2012] | Stewart, a. J., & Plotkin, J. B. (2012). Extortion and cooperation in the Prisoner’s Dilemma. Proceedings of the National Academy of Sciences, 109(26), 10134–10135. <http://doi.org/10.1073/pnas.1208087109> |

| [Szabo2007] | Szabó, G., & Fáth, G. (2007). Evolutionary games on graphs. Physics Reports, 446(4-6), 97–216. <http://doi.org/10.1016/j.physrep.2007.04.004> |

| [Gaudesi2016] | Gaudesi, Marco, et al. “Exploiting evolutionary modeling to prevail in iterated prisoner’s dilemma tournaments.” IEEE Transactions on Computational Intelligence and AI in Games 8.3 (2016): 288-300. |

| [Tzafestas2000] | Tzafestas, E. (2000). Toward adaptive cooperative behavior. From Animals to Animals: Proceedings of the 6th International Conference on the Simulation of Adaptive Behavior {(SAB-2000)}, 2, 334–340. |

#### Strategy index[¶](#strategy-index "Permalink to this headline")

Here are the docstrings of all the strategies in the library.

*class* `axelrod.strategies.adaptive.``Adaptive`(*initial\_plays: List[axelrod.action.Action] = None*)[[source]](_modules/axelrod/strategies/adaptive.html#Adaptive)[¶](#axelrod.strategies.adaptive.Adaptive "Permalink to this definition")

Start with a specific sequence of C and D, then play the strategy that

has worked best, recalculated each turn.

Names:

* Adaptive: [[Li2011]](index.html#li2011)

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/adaptive.html#Adaptive.strategy)[¶](#axelrod.strategies.adaptive.Adaptive.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.adaptor.``AbstractAdaptor`(*delta: Dict[Tuple[axelrod.action.Action, axelrod.action.Action], float], perr: float = 0.01*)[[source]](_modules/axelrod/strategies/adaptor.html#AbstractAdaptor)[¶](#axelrod.strategies.adaptor.AbstractAdaptor "Permalink to this definition")

An adaptive strategy that updates an internal state based on the last

round of play. Using this state the player Cooperates with a probability

derived from the state.

s, float:

the internal state, initially 0

perr, float:

an error threshold for misinterpreted moves

delta, a dictionary of floats:

additive update values for s depending on the last round’s outcome

Names:

* Adaptor: [[Hauert2002]](index.html#hauert2002)

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/adaptor.html#AbstractAdaptor.strategy)[¶](#axelrod.strategies.adaptor.AbstractAdaptor.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.adaptor.``AdaptorBrief`[[source]](_modules/axelrod/strategies/adaptor.html#AdaptorBrief)[¶](#axelrod.strategies.adaptor.AdaptorBrief "Permalink to this definition")

An Adaptor trained on short interactions.

Names:

* AdaptorBrief: [[Hauert2002]](index.html#hauert2002)

*class* `axelrod.strategies.adaptor.``AdaptorLong`[[source]](_modules/axelrod/strategies/adaptor.html#AdaptorLong)[¶](#axelrod.strategies.adaptor.AdaptorLong "Permalink to this definition")

An Adaptor trained on long interactions.

Names:

* AdaptorLong: [[Hauert2002]](index.html#hauert2002)

*class* `axelrod.strategies.alternator.``Alternator`[[source]](_modules/axelrod/strategies/alternator.html#Alternator)[¶](#axelrod.strategies.alternator.Alternator "Permalink to this definition")

A player who alternates between cooperating and defecting.

Names

* Alternator: [[Axelrod1984]](index.html#axelrod1984)

* Periodic player CD: [[Mittal2009]](index.html#mittal2009)

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/alternator.html#Alternator.strategy)[¶](#axelrod.strategies.alternator.Alternator.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.ann.``ANN`(*num\_features: int*, *num\_hidden: int*, *weights: List[float] = None*)[[source]](_modules/axelrod/strategies/ann.html#ANN)[¶](#axelrod.strategies.ann.ANN "Permalink to this definition")

Artificial Neural Network based strategy.

A single layer neural network based strategy, with the following

features:

\* Opponent’s first move is C

\* Opponent’s first move is D

\* Opponent’s second move is C

\* Opponent’s second move is D

\* Player’s previous move is C

\* Player’s previous move is D

\* Player’s second previous move is C

\* Player’s second previous move is D

\* Opponent’s previous move is C

\* Opponent’s previous move is D

\* Opponent’s second previous move is C

\* Opponent’s second previous move is D

\* Total opponent cooperations

\* Total opponent defections

\* Total player cooperations

\* Total player defections

\* Round number

Original Source: <https://gist.github.com/mojones/550b32c46a8169bb3cd89d917b73111a#file-ann-strategy-test-L60>

Names

* Artificial Neural Network based strategy: Original name by Martin Jones

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/ann.html#ANN.strategy)[¶](#axelrod.strategies.ann.ANN.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.ann.``EvolvableANN`(*num\_features: int*, *num\_hidden: int*, *weights: List[float] = None*, *mutation\_probability: float = None*, *mutation\_distance: int = 5*, *seed: int = None*)[[source]](_modules/axelrod/strategies/ann.html#EvolvableANN)[¶](#axelrod.strategies.ann.EvolvableANN "Permalink to this definition")

Evolvable version of ANN.

`crossover`(*other*)[[source]](_modules/axelrod/strategies/ann.html#EvolvableANN.crossover)[¶](#axelrod.strategies.ann.EvolvableANN.crossover "Permalink to this definition")

Optional method to allow Player to produce variants in combination with another player. Returns a new

Player.

`mutate`()[[source]](_modules/axelrod/strategies/ann.html#EvolvableANN.mutate)[¶](#axelrod.strategies.ann.EvolvableANN.mutate "Permalink to this definition")

Optional method to allow Player to produce a variant (not in place).

*class* `axelrod.strategies.ann.``EvolvedANN`[[source]](_modules/axelrod/strategies/ann.html#EvolvedANN)[¶](#axelrod.strategies.ann.EvolvedANN "Permalink to this definition")

A strategy based on a pre-trained neural network with 17 features and a

hidden layer of size 10.

Trained using the axelrod\_dojo version: 0.0.8

Training data is archived at doi.org/10.5281/zenodo.1306926

Names:

> 

> * Evolved ANN: Original name by Martin Jones.

> 

> 

> 

*class* `axelrod.strategies.ann.``EvolvedANN5`[[source]](_modules/axelrod/strategies/ann.html#EvolvedANN5)[¶](#axelrod.strategies.ann.EvolvedANN5 "Permalink to this definition")

A strategy based on a pre-trained neural network with 17 features and a

hidden layer of size 5.

Trained using the axelrod\_dojo version: 0.0.8

Training data is archived at doi.org/10.5281/zenodo.1306931

Names:

> 

> * Evolved ANN 5: Original name by Marc Harper.

> 

> 

> 

*class* `axelrod.strategies.ann.``EvolvedANNNoise05`[[source]](_modules/axelrod/strategies/ann.html#EvolvedANNNoise05)[¶](#axelrod.strategies.ann.EvolvedANNNoise05 "Permalink to this definition")

A strategy based on a pre-trained neural network with a hidden layer of

size 5, trained with noise=0.05.

Trained using the axelrod\_dojo version: 0.0.8

Training data i archived at doi.org/10.5281/zenodo.1314247.

Names:

> 

> * Evolved ANN Noise 5: Original name by Marc Harper.

> 

> 

> 

`axelrod.strategies.ann.``activate`(*bias: List[float], hidden: List[float], output: List[float], inputs: numpy.ndarray*) → float[[source]](_modules/axelrod/strategies/ann.html#activate)[¶](#axelrod.strategies.ann.activate "Permalink to this definition")

Compute the output of the neural network:

output = relu(inputs \* hidden\_weights + bias) \* output\_weights

`axelrod.strategies.ann.``compute_features`(*player: axelrod.player.Player*, *opponent: axelrod.player.Player*) → numpy.ndarray[[source]](_modules/axelrod/strategies/ann.html#compute_features)[¶](#axelrod.strategies.ann.compute_features "Permalink to this definition")

Compute history features for Neural Network:

\* Opponent’s first move is C

\* Opponent’s first move is D

\* Opponent’s second move is C

\* Opponent’s second move is D

\* Player’s previous move is C

\* Player’s previous move is D

\* Player’s second previous move is C

\* Player’s second previous move is D

\* Opponent’s previous move is C

\* Opponent’s previous move is D

\* Opponent’s second previous move is C

\* Opponent’s second previous move is D

\* Total opponent cooperations

\* Total opponent defections

\* Total player cooperations

\* Total player defections

\* Round number

`axelrod.strategies.ann.``split_weights`(*weights: List[float], num\_features: int, num\_hidden: int*) → Tuple[List[List[float]], List[float], List[float]][[source]](_modules/axelrod/strategies/ann.html#split_weights)[¶](#axelrod.strategies.ann.split_weights "Permalink to this definition")

Splits the input vector into the the NN bias weights and layer

parameters.

*class* `axelrod.strategies.apavlov.``APavlov2006`[[source]](_modules/axelrod/strategies/apavlov.html#APavlov2006)[¶](#axelrod.strategies.apavlov.APavlov2006 "Permalink to this definition")

APavlov attempts to classify its opponent as one of five strategies:

Cooperative, ALLD, STFT, PavlovD, or Random. APavlov then responds in a

manner intended to achieve mutual cooperation or to defect against

uncooperative opponents.

Names:

* Adaptive Pavlov 2006: [[Li2007]](index.html#li2007)

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/apavlov.html#APavlov2006.strategy)[¶](#axelrod.strategies.apavlov.APavlov2006.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.apavlov.``APavlov2011`[[source]](_modules/axelrod/strategies/apavlov.html#APavlov2011)[¶](#axelrod.strategies.apavlov.APavlov2011 "Permalink to this definition")

APavlov attempts to classify its opponent as one of four strategies:

Cooperative, ALLD, STFT, or Random. APavlov then responds in a manner

intended to achieve mutual cooperation or to defect against

uncooperative opponents.

Names:

* Adaptive Pavlov 2011: [[Li2011]](index.html#li2011)

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/apavlov.html#APavlov2011.strategy)[¶](#axelrod.strategies.apavlov.APavlov2011.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.appeaser.``Appeaser`[[source]](_modules/axelrod/strategies/appeaser.html#Appeaser)[¶](#axelrod.strategies.appeaser.Appeaser "Permalink to this definition")

A player who tries to guess what the opponent wants.

Switch the classifier every time the opponent plays D.

Start with C, switch between C and D when opponent plays D.

Names:

* Appeaser: Original Name by Jochen Müller

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/appeaser.html#Appeaser.strategy)[¶](#axelrod.strategies.appeaser.Appeaser.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.averagecopier.``AverageCopier`[[source]](_modules/axelrod/strategies/averagecopier.html#AverageCopier)[¶](#axelrod.strategies.averagecopier.AverageCopier "Permalink to this definition")

The player will cooperate with probability p if the opponent’s cooperation

ratio is p. Starts with random decision.

Names:

* Average Copier: Original name by Geraint Palmer

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/averagecopier.html#AverageCopier.strategy)[¶](#axelrod.strategies.averagecopier.AverageCopier.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.averagecopier.``NiceAverageCopier`[[source]](_modules/axelrod/strategies/averagecopier.html#NiceAverageCopier)[¶](#axelrod.strategies.averagecopier.NiceAverageCopier "Permalink to this definition")

Same as Average Copier, but always starts by cooperating.

Names:

* Average Copier: Original name by Owen Campbell

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/averagecopier.html#NiceAverageCopier.strategy)[¶](#axelrod.strategies.averagecopier.NiceAverageCopier.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

Strategies submitted to Axelrod’s first tournament. All strategies in this

module are prefixed by FirstBy to indicate that they were submitted in

Axelrod’s First tournament by the given author.

Note that these strategies are implemented from the descriptions presented

in:

Axelrod, R. (1980). Effective Choice in the Prisoner’s Dilemma.

Journal of Conflict Resolution, 24(1), 3–25.

These descriptions are not always clear and/or precise and when assumptions have

been made they are explained in the strategy docstrings.

*class* `axelrod.strategies.axelrod_first.``FirstByAnonymous`[[source]](_modules/axelrod/strategies/axelrod_first.html#FirstByAnonymous)[¶](#axelrod.strategies.axelrod_first.FirstByAnonymous "Permalink to this definition")

Submitted to Axelrod’s first tournament by a graduate student whose name was

withheld.

The description written in [[Axelrod1980]](index.html#axelrod1980) is:

> “This rule has a probability of cooperating, P, which is initially 30% and

> is updated every 10 moves. P is adjusted if the other player seems random,

> very cooperative, or very uncooperative. P is also adjusted after move 130

> if the rule has a lower score than the other player. Unfortunately, the

> complex process of adjustment frequently left the probability of cooperation

> in the 30% to 70% range, and therefore the rule appeared random to many

> other players.”

Given the lack of detail this strategy is implemented based on the final

sentence of the description which is to have a cooperation probability that

is uniformly random in the 30 to 70% range.

Names:

* (Name withheld): [[Axelrod1980]](index.html#axelrod1980)

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/axelrod_first.html#FirstByAnonymous.strategy)[¶](#axelrod.strategies.axelrod_first.FirstByAnonymous.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.axelrod_first.``FirstByDavis`(*rounds\_to\_cooperate: int = 10*)[[source]](_modules/axelrod/strategies/axelrod_first.html#FirstByDavis)[¶](#axelrod.strategies.axelrod_first.FirstByDavis "Permalink to this definition")

Submitted to Axelrod’s first tournament by Morton Davis.

The description written in [[Axelrod1980]](index.html#axelrod1980) is:

> “A player starts by cooperating for 10 rounds then plays Grudger,

> defecting if at any point the opponent has defected.”

This strategy came 8th in Axelrod’s original tournament.

Names:

* Davis: [[Axelrod1980]](index.html#axelrod1980)

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/axelrod_first.html#FirstByDavis.strategy)[¶](#axelrod.strategies.axelrod_first.FirstByDavis.strategy "Permalink to this definition")

Begins by playing C, then plays D for the remaining rounds if the

opponent ever plays D.

*class* `axelrod.strategies.axelrod_first.``FirstByDowning`[[source]](_modules/axelrod/strategies/axelrod_first.html#FirstByDowning)[¶](#axelrod.strategies.axelrod_first.FirstByDowning "Permalink to this definition")

Submitted to Axelrod’s first tournament by Downing

The description written in [[Axelrod1980]](index.html#axelrod1980) is:

> “This rule selects its choice to maximize its own longterm expected payoff on

> the assumption that the other rule cooperates with a fixed probability which

> depends only on whether the other player cooperated or defected on the previous

> move. These two probabilities estimates are continuously updated as the game

> progresses. Initially, they are both assumed to be .5, which amounts to the

> pessimistic assumption that the other player is not responsive. This rule is

> based on an outcome maximization interpretation of human performances proposed

> by Downing (1975).”

The Downing (1975) paper is “The Prisoner’s Dilemma Game as a

Problem-Solving Phenomenon” [[Downing1975]](index.html#downing1975) and this is used to implement the

strategy.

There are a number of specific points in this paper, on page 371:

> “[…] In these strategies, O’s [the opponent’s] response on trial N is in

some way dependent or contingent on S’s [the subject’s] response on trial N-

1. All varieties of these lag-one matching strategies can be defined by two

parameters: the conditional probability that O will choose C following C by

S, P(C\_o | C\_s) and the conditional probability that O will choose C

following D by S, P(C\_o, D\_s).”

Throughout the paper the strategy (S) assumes that the opponent (O) is

playing a reactive strategy defined by these two conditional probabilities.

The strategy aims to maximise the long run utility against such a strategy

and the mechanism for this is described in Appendix A (more on this later).

One final point from the main text is, on page 372:

> “For the various lag-one matching strategies of O, the maximizing

strategies of S will be 100% C, or 100% D, or for some strategies all S

strategies will be functionally equivalent.”

This implies that the strategy S will either always cooperate or always

defect (or be indifferent) dependent on the opponent’s defining

probabilities.

To understand the particular mechanism that describes the strategy S, we

refer to Appendix A of the paper on page 389.

The stated goal of the strategy is to maximize (using the notation of the

paper):

> 

> EV\_TOT = #CC(EV\_CC) + #CD(EV\_CD) + #DC(EV\_DC) + #DD(EV\_DD)

This differs from the more modern literature where #CC, #CD, #DC and #DD

would imply that counts of both players playing C and C, or the first

playing C and the second D etc…

In this case the author uses an argument based on the sequence of plays by

the player (S) so #CC denotes the number of times the player plays C twice

in a row.

On the second page of the appendix, figure 4 (page 390)

identifies an expression for EV\_TOT.

A specific term is made to disappear in

the case of T - R = P - S (which is not the case for the standard

(R, P, S, T) = (3, 1, 0, 5)):

> “Where (t - r) = (p - s), EV\_TOT will be a function of alpha, beta, t, r,

p, s and N are known and V which is unknown.

V is the total number of cooperations of the player S (this is noted earlier

in the abstract) and as such the final expression (with only V as unknown)

can be used to decide if V should indicate that S always cooperates or not.

This final expression is used to show that EV\_TOT is linear in the number of

cooperations by the player thus justifying the fact that the player will

always cooperate or defect.

All of the above details are used to give the following interpretation of

the strategy:

1. On any given turn, the strategy will estimate alpha = P(C\_o | C\_s) and

beta = P(C\_o | D\_s).

2. The strategy will calculate the expected utility of always playing C OR

always playing D against the estimated probabilities. This corresponds to:

> 

> 1. In the case of the player always cooperating:

> 

> 

> P\_CC = alpha and P\_CD = 1 - alpha

> 2. In the case of the player always defecting:

> 

> 

> P\_DC = beta and P\_DD = 1 - beta

> 

> 

> 

Using this we have:

> 

> E\_C = alpha R + (1 - alpha) S

> E\_D = beta T + (1 - beta) P

Thus at every turn, the strategy will calculate those two values and

cooperate if E\_C > E\_D and will defect if E\_C < E\_D.

In the case of E\_C = E\_D, the player will alternate from their previous

move. This is based on specific sentence from Axelrod’s original paper:

> “Under certain circumstances, DOWNING will even determine that the best

> strategy is to alternate cooperation and defection.”

One final important point is the early game behaviour of the strategy. It

has been noted that this strategy was implemented in a way that assumed that

alpha and beta were both 1/2:

> “Initially, they are both assumed to be .5, which amounts to the

> pessimistic assumption that the other player is not responsive.”

Note that if alpha = beta = 1 / 2 then:

> 

> E\_C = alpha R + alpha S

> E\_D = alpha T + alpha P

And from the defining properties of the Prisoner’s Dilemma (T > R > P > S)

this gives: E\_D > E\_C.

Thus, the player opens with a defection in the first two rounds. Note that

from the Axelrod publications alone there is nothing to indicate defections

on the first two rounds, although a defection in the opening round is clear.

However there is a presentation available at

<http://www.sci.brooklyn.cuny.edu/~sklar/teaching/f05/alife/notes/azhar-ipd-Oct19th.pdf>

That clearly states that Downing defected in the first two rounds, thus this

is assumed to be the behaviour. Interestingly, in future tournaments this

strategy was revised to not defect on the opening two rounds.

It is assumed that these first two rounds are used to create initial

estimates of

beta = P(C\_o | D\_s) and we will use the opening play of the player to

estimate alpha = P(C\_o | C\_s).

Thus we assume that the opponents first play is a response to a cooperation

“before the match starts”.

So for example, if the plays are:

[(D, C), (D, C)]

Then the opponent’s first cooperation counts as a cooperation in response to

the non existent cooperation of round 0. The total number of cooperations in

response to a cooperation is 1. We need to take in to account that extra

phantom cooperation to estimate the probability alpha=P(C\_o | C\_s) as 1 / 1

= 1.

This is an assumption with no clear indication from the literature.

–

This strategy came 10th in Axelrod’s original tournament.

Names:

* Downing: [[Axelrod1980]](index.html#axelrod1980)

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/axelrod_first.html#FirstByDowning.strategy)[¶](#axelrod.strategies.axelrod_first.FirstByDowning.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.axelrod_first.``FirstByFeld`(*start\_coop\_prob: float = 1.0*, *end\_coop\_prob: float = 0.5*, *rounds\_of\_decay: int = 200*)[[source]](_modules/axelrod/strategies/axelrod_first.html#FirstByFeld)[¶](#axelrod.strategies.axelrod_first.FirstByFeld "Permalink to this definition")

Submitted to Axelrod’s first tournament by Scott Feld.

The description written in [[Axelrod1980]](index.html#axelrod1980) is:

> “This rule starts with tit for tat and gradually lowers its probability of

> cooperation following the other’s cooperation to .5 by the two hundredth

> move. It always defects after a defection by the other.”

This strategy plays Tit For Tat, always defecting if the opponent defects but

cooperating when the opponent cooperates with a gradually decreasing probability

until it is only .5. Note that the description does not clearly indicate how

the cooperation probability should drop. This implements a linear decreasing

function.

This strategy came 11th in Axelrod’s original tournament.

Names:

* Feld: [[Axelrod1980]](index.html#axelrod1980)

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/axelrod_first.html#FirstByFeld.strategy)[¶](#axelrod.strategies.axelrod_first.FirstByFeld.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.axelrod_first.``FirstByGraaskamp`(*alpha: float = 0.05*)[[source]](_modules/axelrod/strategies/axelrod_first.html#FirstByGraaskamp)[¶](#axelrod.strategies.axelrod_first.FirstByGraaskamp "Permalink to this definition")

Submitted to Axelrod’s first tournament by James Graaskamp.

The description written in [[Axelrod1980]](index.html#axelrod1980) is:

> “This rule plays tit for tat for 50 moves, defects on move 51, and then

> plays 5 more moves of tit for tat. A check is then made to see if the player

> seems to be RANDOM, in which case it defects from then on. A check is also

> made to see if the other is TIT FOR TAT, ANALOGY (a program from the

> preliminary tournament), and its own twin, in which case it plays tit for

> tat. Otherwise it randomly defects every 5 to 15 moves, hoping that enough

> trust has been built up so that the other player will not notice these

> defections.:

This is implemented as:

1. Plays Tit For Tat for the first 50 rounds;

2. Defects on round 51;

3. Plays 5 further rounds of Tit For Tat;

4. A check is then made to see if the opponent is playing randomly in which

case it defects for the rest of the game. This is implemented with a chi

squared test.

5. The strategy also checks to see if the opponent is playing Tit For Tat or

a clone of itself. If

so it plays Tit For Tat. If not it cooperates and randomly defects every 5

to 15 moves.

Note that there is no information about ‘Analogy’ available thus Step 5 is

a “best possible” interpretation of the description in the paper.

Furthermore the test for the clone is implemented as checking that both

players have played the same moves for the entire game. This is unlikely to

be the original approach but no further details are available.

This strategy came 9th in Axelrod’s original tournament.

Names:

* Graaskamp: [[Axelrod1980]](index.html#axelrod1980)

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/axelrod_first.html#FirstByGraaskamp.strategy)[¶](#axelrod.strategies.axelrod_first.FirstByGraaskamp.strategy "Permalink to this definition")

This is the actual strategy

*class* `axelrod.strategies.axelrod_first.``FirstByGrofman`[[source]](_modules/axelrod/strategies/axelrod_first.html#FirstByGrofman)[¶](#axelrod.strategies.axelrod_first.FirstByGrofman "Permalink to this definition")

Submitted to Axelrod’s first tournament by Bernard Grofman.

The description written in [[Axelrod1980]](index.html#axelrod1980) is:

> 

> > “If the players did different things on the previous move, this rule

> > cooperates with probability 2/7. Otherwise this rule always cooperates.”

This strategy came 4th in Axelrod’s original tournament.

Names:

* Grofman: [[Axelrod1980]](index.html#axelrod1980)

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/axelrod_first.html#FirstByGrofman.strategy)[¶](#axelrod.strategies.axelrod_first.FirstByGrofman.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.axelrod_first.``FirstByJoss`(*p: float = 0.9*)[[source]](_modules/axelrod/strategies/axelrod_first.html#FirstByJoss)[¶](#axelrod.strategies.axelrod_first.FirstByJoss "Permalink to this definition")

Submitted to Axelrod’s first tournament by Johann Joss.

The description written in [[Axelrod1980]](index.html#axelrod1980) is:

> “This rule cooperates 90% of the time after a cooperation by the other. It

> always defects after a defection by the other.”

This strategy came 12th in Axelrod’s original tournament.

Names:

* Joss: [[Axelrod1980]](index.html#axelrod1980)

* Hard Joss: [[Stewart2012]](index.html#stewart2012)

*class* `axelrod.strategies.axelrod_first.``FirstByNydegger`[[source]](_modules/axelrod/strategies/axelrod_first.html#FirstByNydegger)[¶](#axelrod.strategies.axelrod_first.FirstByNydegger "Permalink to this definition")

Submitted to Axelrod’s first tournament by Rudy Nydegger.

The description written in [[Axelrod1980]](index.html#axelrod1980) is:

> “The program begins with tit for tat for the first three moves, except

> that if it was the only one to cooperate on the first move and the only one

> to defect on the second move, it defects on the third move. After the third

> move, its choice is determined from the 3 preceding outcomes in the

> following manner. Let A be the sum formed by counting the other’s defection

> as 2 points and one’s own as 1 point, and giving weights of 16, 4, and 1 to

> the preceding three moves in chronological order. The choice can be

> described as defecting only when A equals 1, 6, 7, 17, 22, 23, 26, 29, 30,

> 31, 33, 38, 39, 45, 49, 54, 55, 58, or 61. Thus if all three preceding moves

> are mutual defection, A = 63 and the rule cooperates. This rule was

> designed for use in laboratory experiments as a stooge which had a memory

> and appeared to be trustworthy, potentially cooperative, but not gullible

> (Nydegger, 1978).”

The program begins with tit for tat for the first three moves, except

that if it was the only one to cooperate on the first move and the only one

to defect on the second move, it defects on the third move. After the

third move, its choice is determined from the 3 preceding outcomes in the

following manner.

\[A = 16 a\_1 + 4 a\_2 + a\_3\]

Where \(a\_i\) is dependent on the outcome of the previous \(i\) th

round. If both strategies defect, \(a\_i=3\), if the opponent only defects:

\(a\_i=2\) and finally if it is only this strategy that defects then

\(a\_i=1\).

Finally this strategy defects if and only if:

\[A \in \{1, 6, 7, 17, 22, 23, 26, 29, 30, 31, 33, 38, 39, 45, 49, 54, 55, 58, 61\}\]

Thus if all three preceding moves are mutual defection, A = 63 and the rule

cooperates. This rule was designed for use in laboratory experiments as a

stooge which had a memory and appeared to be trustworthy, potentially

cooperative, but not gullible.

This strategy came 3rd in Axelrod’s original tournament.

Names:

* Nydegger: [[Axelrod1980]](index.html#axelrod1980)

*static* `score_history`(*my\_history: List[axelrod.action.Action], opponent\_history: List[axelrod.action.Action], score\_map: Dict[Tuple[axelrod.action.Action, axelrod.action.Action], int]*) → int[[source]](_modules/axelrod/strategies/axelrod_first.html#FirstByNydegger.score_history)[¶](#axelrod.strategies.axelrod_first.FirstByNydegger.score_history "Permalink to this definition")

Implements the Nydegger formula A = 16 a\_1 + 4 a\_2 + a\_3

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/axelrod_first.html#FirstByNydegger.strategy)[¶](#axelrod.strategies.axelrod_first.FirstByNydegger.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.axelrod_first.``FirstByShubik`[[source]](_modules/axelrod/strategies/axelrod_first.html#FirstByShubik)[¶](#axelrod.strategies.axelrod_first.FirstByShubik "Permalink to this definition")

Submitted to Axelrod’s first tournament by Martin Shubik.

The description written in [[Axelrod1980]](index.html#axelrod1980) is:

> “This rule cooperates until the other defects, and then defects once. If

> the other defects again after the rule’s cooperation is resumed, the rule

> defects twice. In general, the length of retaliation is increased by one for

> each departure from mutual cooperation. This rule is described with its

> strategic implications in Shubik (1970). Further treatment of its is given

> in Taylor (1976).

There is some room for interpretation as to how the strategy reacts to a

defection on the turn where it starts to cooperate once more. In Shubik

(1970) the strategy is described as:

> “I will play my move 1 to begin with and will continue to do so, so long

> as my information shows that the other player has chosen his move 1. If my

> information tells me he has used move 2, then I will use move 2 for the

> immediate k subsequent periods, after which I will resume using move 1. If

> he uses his move 2 again after I have resumed using move 1, then I will

> switch to move 2 for the k + 1 immediately subsequent periods … and so

> on, increasing my retaliation by an extra period for each departure from the

> (1, 1) steady state.”

This is interpreted as:

The player cooperates, if when it is cooperating, the opponent defects it

defects for k rounds. After k rounds it starts cooperating again and

increments the value of k if the opponent defects again.

This strategy came 5th in Axelrod’s original tournament.

Names:

* Shubik: [[Axelrod1980]](index.html#axelrod1980)

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/axelrod_first.html#FirstByShubik.strategy)[¶](#axelrod.strategies.axelrod_first.FirstByShubik.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.axelrod_first.``FirstBySteinAndRapoport`(*alpha: float = 0.05*)[[source]](_modules/axelrod/strategies/axelrod_first.html#FirstBySteinAndRapoport)[¶](#axelrod.strategies.axelrod_first.FirstBySteinAndRapoport "Permalink to this definition")

Submitted to Axelrod’s first tournament by William Stein and Amnon Rapoport.

The description written in [[Axelrod1980]](index.html#axelrod1980) is:

> “This rule plays tit for tat except that it cooperates on the first four

> moves, it defects on the last two moves, and every fifteen moves it checks

> to see if the opponent seems to be playing randomly. This check uses a

> chi-squared test of the other’s transition probabilities and also checks for

> alternating moves of CD and DC.

This is implemented as follows:

1. It cooperates for the first 4 moves.

2. It defects on the last 2 moves.

3. Every 15 moves it makes use of a [chi-squared

test](http://en.wikipedia.org/wiki/Chi-squared_test) to check if the

opponent is playing randomly. If so it defects.

This strategy came 6th in Axelrod’s original tournament.

Names:

* SteinAndRapoport: [[Axelrod1980]](index.html#axelrod1980)

`original_class`[¶](#axelrod.strategies.axelrod_first.FirstBySteinAndRapoport.original_class "Permalink to this definition")

alias of [`FirstBySteinAndRapoport`](#axelrod.strategies.axelrod_first.FirstBySteinAndRapoport "axelrod.strategies.axelrod_first.FirstBySteinAndRapoport")

*class* `axelrod.strategies.axelrod_first.``FirstByTidemanAndChieruzzi`[[source]](_modules/axelrod/strategies/axelrod_first.html#FirstByTidemanAndChieruzzi)[¶](#axelrod.strategies.axelrod_first.FirstByTidemanAndChieruzzi "Permalink to this definition")

Submitted to Axelrod’s first tournament by Nicolas Tideman and Paula

Chieruzzi.

The description written in [[Axelrod1980]](index.html#axelrod1980) is:

> “This rule begins with cooperation and tit for tat. However, when the

> other player finishes his second run of defec- tions, an extra punishment is

> instituted, and the number of punishing defections is increased by one with

> each run of the other’s defections. The other player is given a fresh start

> if he is 10 or more points behind, if he has not just started a run of

> defections, if it has been at least 20 moves since a fresh start, if there

> are at least 10 moves remaining, and if the number of defections differs

> from a 50-50 random generator by at least 3.0 standard deviations. A fresh

> start involves two cooperations and then play as if the game had just

> started. The program defects automatically on the last two moves.”

This is interpreted as:

1. Every run of defections played by the opponent increases the number of

defections that this strategy retaliates with by 1.

2. The opponent is given a ‘fresh start’ if:

	* it is 10 points behind this strategy

	* and it has not just started a run of defections

	* and it has been at least 20 rounds since the last ‘fresh start’

	* and there are more than 10 rounds remaining in the match

	* and the total number of defections differs from a 50-50 random sample

	by at least 3.0 standard deviations.

A ‘fresh start’ is a sequence of two cooperations followed by an assumption

that the game has just started (everything is forgotten).

3. The strategy defects on the last two moves.

This strategy came 2nd in Axelrod’s original tournament.

Names:

* TidemanAndChieruzzi: [[Axelrod1980]](index.html#axelrod1980)

`original_class`[¶](#axelrod.strategies.axelrod_first.FirstByTidemanAndChieruzzi.original_class "Permalink to this definition")

alias of [`FirstByTidemanAndChieruzzi`](#axelrod.strategies.axelrod_first.FirstByTidemanAndChieruzzi "axelrod.strategies.axelrod_first.FirstByTidemanAndChieruzzi")

*class* `axelrod.strategies.axelrod_first.``FirstByTullock`[[source]](_modules/axelrod/strategies/axelrod_first.html#FirstByTullock)[¶](#axelrod.strategies.axelrod_first.FirstByTullock "Permalink to this definition")

Submitted to Axelrod’s first tournament by Gordon Tullock.

The description written in [[Axelrod1980]](index.html#axelrod1980) is:

> “This rule cooperates on the first eleven moves. It then cooperates 10%

> less than the other player has cooperated on the preceding ten moves. This

> rule is based on an idea developed in Overcast and Tullock (1971). Professor

> Tullock was invited to specify how the idea could be implemented, and he did

> so out of scientific interest rather than an expectation that it would be a

> likely winner.”

This is interpreted as:

Cooperates for the first 11 rounds then randomly cooperates 10% less often

than the opponent has in the previous 10 rounds.

This strategy came 13th in Axelrod’s original tournament.

Names:

* Tullock: [[Axelrod1980]](index.html#axelrod1980)

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/axelrod_first.html#FirstByTullock.strategy)[¶](#axelrod.strategies.axelrod_first.FirstByTullock.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

Strategies from Axelrod’s second tournament. All strategies in this module are

prefixed by SecondBy to indicate that they were submitted in Axelrod’s Second

tournament by the given author.

*class* `axelrod.strategies.axelrod_second.``SecondByAppold`[[source]](_modules/axelrod/strategies/axelrod_second.html#SecondByAppold)[¶](#axelrod.strategies.axelrod_second.SecondByAppold "Permalink to this definition")

Strategy submitted to Axelrod’s second tournament by Scott Appold (K88R) and

came in 22nd in that tournament.

Cooperates for first four turns.

After four turns, will cooperate immediately following the first time the

opponent cooperates (starting with the opponent’s fourth move). Otherwise

will cooperate with probability equal to:

* If this strategy defected two turns ago, the portion of the time

(historically) that the opponent followed a defection with a cooperation.

* If this strategy cooperated two turns ago, the portion of the time

(historically) that the opponent followed a cooperation with a cooperation.

The opponent’s first move is counted as a response to a cooperation.

Names:

* Appold: [[Axelrod1980b]](index.html#axelrod1980b)

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/axelrod_second.html#SecondByAppold.strategy)[¶](#axelrod.strategies.axelrod_second.SecondByAppold.strategy "Permalink to this definition")

This is a placeholder strategy.

*class* `axelrod.strategies.axelrod_second.``SecondByBlack`[[source]](_modules/axelrod/strategies/axelrod_second.html#SecondByBlack)[¶](#axelrod.strategies.axelrod_second.SecondByBlack "Permalink to this definition")

Strategy submitted to Axelrod’s second tournament by Paul E Black (K83R)

and came in fifteenth in that tournament.

The strategy Cooperates for the first five turns. Then it calculates the

number of opponent defects in the last five moves and Cooperates with

probability prob\_coop`[`number\_defects], where:

prob\_coop[number\_defects] = 1 - (number\_defects^ 2 - 1) / 25

Names:

* Black: [[Axelrod1980b]](index.html#axelrod1980b)

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/axelrod_second.html#SecondByBlack.strategy)[¶](#axelrod.strategies.axelrod_second.SecondByBlack.strategy "Permalink to this definition")

This is a placeholder strategy.

*class* `axelrod.strategies.axelrod_second.``SecondByBorufsen`[[source]](_modules/axelrod/strategies/axelrod_second.html#SecondByBorufsen)[¶](#axelrod.strategies.axelrod_second.SecondByBorufsen "Permalink to this definition")

Strategy submitted to Axelrod’s second tournament by Otto Borufsen

(K32R), and came in third in that tournament.

This player keeps track of the the opponent’s responses to own behavior:

* cd\_count counts: Opponent cooperates as response to player defecting.

* cc\_count counts: Opponent cooperates as response to player cooperating.

The player has a defect mode and a normal mode. In defect mode, the

player will always defect. In normal mode, the player obeys the following

ranked rules:

1. If in the last three turns, both the player/opponent defected, then

cooperate for a single turn.

2. If in the last three turns, the player/opponent acted differently from

each other and they’re alternating, then change next defect to

cooperate. (Doesn’t block third rule.)

3. Otherwise, do tit-for-tat.

Start in normal mode, but every 25 turns starting with the 27th turn,

re-evaluate the mode. Enter defect mode if any of the following

conditions hold:

* Detected random: Opponent cooperated 7-18 times since last mode

evaluation (or start) AND less than 70% of opponent cooperation was in

response to player’s cooperation, i.e.

cc\_count / (cc\_count+cd\_count) < 0.7

* Detect defective: Opponent cooperated fewer than 3 times since last mode

evaluation.

When switching to defect mode, defect immediately. The first two rules for

normal mode require that last three turns were in normal mode. When starting

normal mode from defect mode, defect on first move.

Names:

* Borufsen: [[Axelrod1980b]](index.html#axelrod1980b)

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/axelrod_second.html#SecondByBorufsen.strategy)[¶](#axelrod.strategies.axelrod_second.SecondByBorufsen.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

`try_return`(*to\_return*)[[source]](_modules/axelrod/strategies/axelrod_second.html#SecondByBorufsen.try_return)[¶](#axelrod.strategies.axelrod_second.SecondByBorufsen.try_return "Permalink to this definition")

We put the logic here to check for the flip\_next\_defect bit here,

and proceed like normal otherwise.

*class* `axelrod.strategies.axelrod_second.``SecondByCave`[[source]](_modules/axelrod/strategies/axelrod_second.html#SecondByCave)[¶](#axelrod.strategies.axelrod_second.SecondByCave "Permalink to this definition")

Strategy submitted to Axelrod’s second tournament by Rob Cave (K49R), and

came in fourth in that tournament.

First look for overly-defective or apparently random opponents, and defect

if found. That is any opponent meeting one of:

* turn > 39 and percent defects > 0.39

* turn > 29 and percent defects > 0.65

* turn > 19 and percent defects > 0.79

Otherwise, respond to cooperation with cooperation. And respond to defections

with either a defection (if opponent has defected at least 18 times) or with

a random (50/50) choice. [Cooperate on first.]

Names:

* Cave: [[Axelrod1980b]](index.html#axelrod1980b)

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/axelrod_second.html#SecondByCave.strategy)[¶](#axelrod.strategies.axelrod_second.SecondByCave.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.axelrod_second.``SecondByChampion`[[source]](_modules/axelrod/strategies/axelrod_second.html#SecondByChampion)[¶](#axelrod.strategies.axelrod_second.SecondByChampion "Permalink to this definition")

Strategy submitted to Axelrod’s second tournament by Danny Champion.

This player cooperates on the first 10 moves and plays Tit for Tat for the

next 15 more moves. After 25 moves, the program cooperates unless all the

following are true: the other player defected on the previous move, the

other player cooperated less than 60% and the random number between 0 and 1

is greater that the other player’s cooperation rate.

Names:

* Champion: [[Axelrod1980b]](index.html#axelrod1980b)

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/axelrod_second.html#SecondByChampion.strategy)[¶](#axelrod.strategies.axelrod_second.SecondByChampion.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.axelrod_second.``SecondByColbert`[[source]](_modules/axelrod/strategies/axelrod_second.html#SecondByColbert)[¶](#axelrod.strategies.axelrod_second.SecondByColbert "Permalink to this definition")

Strategy submitted to Axelrod’s second tournament by William Colbert (K51R)

and came in eighteenth in that tournament.

In the first eight turns, this strategy Coopearates on all but the sixth

turn, in which it Defects. After that, the strategy responds to an

opponent Cooperation with a single Cooperation, and responds to a Defection

with a chain of responses: Defect, Defect, Cooperate, Cooperate. During

this chain, the strategy ignores opponent’s moves.

Names:

* Colbert: [[Axelrod1980b]](index.html#axelrod1980b)

*class* `axelrod.strategies.axelrod_second.``SecondByEatherley`[[source]](_modules/axelrod/strategies/axelrod_second.html#SecondByEatherley)[¶](#axelrod.strategies.axelrod_second.SecondByEatherley "Permalink to this definition")

Strategy submitted to Axelrod’s second tournament by Graham Eatherley.

A player that keeps track of how many times in the game the other player

defected. After the other player defects, it defects with a probability

equal to the ratio of the other’s total defections to the total moves to

that point.

Names:

* Eatherley: [[Axelrod1980b]](index.html#axelrod1980b)

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/axelrod_second.html#SecondByEatherley.strategy)[¶](#axelrod.strategies.axelrod_second.SecondByEatherley.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.axelrod_second.``SecondByGetzler`[[source]](_modules/axelrod/strategies/axelrod_second.html#SecondByGetzler)[¶](#axelrod.strategies.axelrod_second.SecondByGetzler "Permalink to this definition")

Strategy submitted to Axelrod’s second tournament by Abraham Getzler (K35R)

and came in eleventh in that tournament.

Strategy Defects with probability flack, where flack is calculated as

the sum over opponent Defections of 0.5 ^ (turns ago Defection happened).

Names:

* Getzler: [[Axelrod1980b]](index.html#axelrod1980b)

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/axelrod_second.html#SecondByGetzler.strategy)[¶](#axelrod.strategies.axelrod_second.SecondByGetzler.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.axelrod_second.``SecondByGladstein`[[source]](_modules/axelrod/strategies/axelrod_second.html#SecondByGladstein)[¶](#axelrod.strategies.axelrod_second.SecondByGladstein "Permalink to this definition")

Submitted to Axelrod’s second tournament by David Gladstein.

This strategy is also known as Tester and is based on the reverse

engineering of the Fortran strategies from Axelrod’s second tournament.

This strategy is a TFT variant that defects on the first round in order to

test the opponent’s response. If the opponent ever defects, the strategy

‘apologizes’ by cooperating and then plays TFT for the rest of the game.

Otherwise, it defects as much as possible subject to the constraint that

the ratio of its defections to moves remains under 0.5, not counting the

first defection.

Names:

* Gladstein: [[Axelrod1980b]](index.html#axelrod1980b)

* Tester: [[Axelrod1980b]](index.html#axelrod1980b)

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/axelrod_second.html#SecondByGladstein.strategy)[¶](#axelrod.strategies.axelrod_second.SecondByGladstein.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.axelrod_second.``SecondByGraaskampKatzen`[[source]](_modules/axelrod/strategies/axelrod_second.html#SecondByGraaskampKatzen)[¶](#axelrod.strategies.axelrod_second.SecondByGraaskampKatzen "Permalink to this definition")

Strategy submitted to Axelrod’s second tournament by Jim Graaskamp and Ken

Katzen (K60R), and came in sixth in that tournament.

Play Tit-for-Tat at first, and track own score. At select checkpoints,

check for a high score. Switch to Default Mode if:

* On move 11, score < 23

* On move 21, score < 53

* On move 31, score < 83

* On move 41, score < 113

* On move 51, score < 143

* On move 101, score < 293

Once in Defect Mode, defect forever.

Names:

* GraaskampKatzen: [[Axelrod1980b]](index.html#axelrod1980b)

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/axelrod_second.html#SecondByGraaskampKatzen.strategy)[¶](#axelrod.strategies.axelrod_second.SecondByGraaskampKatzen.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.axelrod_second.``SecondByGrofman`[[source]](_modules/axelrod/strategies/axelrod_second.html#SecondByGrofman)[¶](#axelrod.strategies.axelrod_second.SecondByGrofman "Permalink to this definition")

Submitted to Axelrod’s second tournament by Bernard Grofman.

This strategy has 3 phases:

1. First it cooperates on the first two rounds

2. For rounds 3-7 inclusive, it plays the same as the opponent’s last move

3. Thereafter, it applies the following logic, looking at its memory of the

last 8\* rounds (ignoring the most recent round).

> 

> * If its own previous move was C and the opponent has defected less than

> 3 times in the last 8\* rounds, cooperate

> * If its own previous move was C and the opponent has defected 3 or

> more times in the last 8\* rounds, defect

> * If its own previous move was D and the opponent has defected only once

> or not at all in the last 8\* rounds, cooperate

> * If its own previous move was D and the opponent has defected more than

> once in the last 8\* rounds, defect

> 

> 

> 

The code looks at the first 7 of the last 8 rounds, ignoring the most

recent round.

Names:

- Grofman’s strategy: [[Axelrod1980b]](index.html#axelrod1980b)

- K86R: [[Axelrod1980b]](index.html#axelrod1980b)

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/axelrod_second.html#SecondByGrofman.strategy)[¶](#axelrod.strategies.axelrod_second.SecondByGrofman.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.axelrod_second.``SecondByHarrington`[[source]](_modules/axelrod/strategies/axelrod_second.html#SecondByHarrington)[¶](#axelrod.strategies.axelrod_second.SecondByHarrington "Permalink to this definition")

Strategy submitted to Axelrod’s second tournament by Paul Harrington (K75R)

and came in eighth in that tournament.

This strategy has three modes: Normal, Fair-weather, and Defect. These

mode names were not present in Harrington’s submission.

In Normal and Fair-weather modes, the strategy begins by:

* Update history

* Try to detect random opponent if turn is multiple of 15 and >=30.

* Check if burned flag should be raised.

* Check for Fair-weather opponent if turn is 38.

Updating history means to increment the correct cell of the move\_history.

move\_history is a matrix where the columns are the opponent’s previous

move and the rows are indexed by the combo of this player’s and the

opponent’s moves two turns ago. [The upper-left cell must be all

Cooperations, but otherwise order doesn’t matter.] After we enter Defect

mode, move\_history won’t be used again.

If the turn is a multiple of 15 and >=30, then attempt to detect random.

If random is detected, enter Defect mode and defect immediately. If the

player was previously in Defect mode, then do not re-enter. The random

detection logic is a modified Pearson’s Chi Squared test, with some

additional checks. [More details in detect\_random docstrings.]

Some of this player’s moves are marked as “generous.” If this player made

a generous move two turns ago and the opponent replied with a Defect, then

raise the burned flag. This will stop certain generous moves later.

The player mostly plays Tit-for-Tat for the first 36 moves, then defects on

the 37th move. If the opponent cooperates on the first 36 moves, and

defects on the 37th move also, then enter Fair-weather mode and cooperate

this turn. Entering Fair-weather mode is extremely rare, since this can

only happen if the opponent cooperates for the first 36 then defects

unprovoked on the 37th. (That is, this player’s first 36 moves are also

Cooperations, so there’s nothing really to trigger an opponent Defection.)

Next in Normal Mode:

1. Check for defect and parity streaks.

2. Check if cooperations are scheduled.

3. Otherwise,

* If turn < 37, Tit-for-Tat.

* If turn = 37, defect, mark this move as generous, and schedule two

more cooperations\*\*.

* If turn > 37, then if burned flag is raised, then Tit-for-Tat.

Otherwise, Tit-for-Tat with probability 1 - prob. And with

probability prob, defect, schedule two cooperations, mark this move

as generous, and increase prob by 5%.

\*\* Scheduling two cooperations means to set more\_coop flag to two. If in

Normal mode and no streaks are detected, then the player will cooperate and

lower this flag, until hitting zero. It’s possible that the flag can be

overwritten. Notable on the 37th turn defect, this is set to two, but the

38th turn Fair-weather check will set this.

If the opponent’s last twenty moves were defections, then defect this turn.

Then check for a parity streak, by flipping the parity bit (there are two

streaks that get tracked which are something like odd and even turns, but

this flip bit logic doesn’t get run every turn), then incrementing the

parity streak that we’re pointing to. If the parity streak that we’re

pointing to is then greater than parity\_limit then reset the streak and

cooperate immediately. parity\_limit is initially set to five, but after

it has been hit eight times, it decreases to three. The parity streak that

we’re pointing to also gets incremented if in normal mode and we defect but

not on turn 38, unless we are defecting as the result of a defect streak.

Note that the parity streaks resets but the defect streak doesn’t.

If more\_coop >= 1, then we cooperate and lower that flag here, in Normal

mode after checking streaks. Still lower this flag if cooperating as the

result of a parity streak or in Fair-weather mode.

Then use the logic based on turn from above.

In Fair-Weather mode after running the code from above, check if opponent

defected last turn. If so, exit Fair-Weather mode, and proceed THIS TURN

with Normal mode. Otherwise cooperate.

In Defect mode, update the exit\_defect\_meter (originally zero) by

incrementing if opponent defected last turn and decreasing by three

otherwise. If exit\_defect\_meter is then 11, then set mode to Normal (for

future turns), cooperate and schedule two more cooperations. [Note that

this move is not marked generous.]

Names:

* Harrington: [[Axelrod1980b]](index.html#axelrod1980b)

`calculate_chi_squared`(*turn*)[[source]](_modules/axelrod/strategies/axelrod_second.html#SecondByHarrington.calculate_chi_squared)[¶](#axelrod.strategies.axelrod_second.SecondByHarrington.calculate_chi_squared "Permalink to this definition")

Pearson’s Chi Squared statistic = sum[ (E\_i-O\_i)^2 / E\_i ], where O\_i

are the observed matrix values, and E\_i is calculated as number (of

defects) in the row times the number in the column over (total number

in the matrix minus 1). Equivalently, we expect we expect (for an

independent distribution) the total number of recorded turns times the

portion in that row times the portion in that column.

In this function, the statistic is non-standard in that it excludes

summands where E\_i <= 1.

`detect_parity_streak`(*last\_move*)[[source]](_modules/axelrod/strategies/axelrod_second.html#SecondByHarrington.detect_parity_streak)[¶](#axelrod.strategies.axelrod_second.SecondByHarrington.detect_parity_streak "Permalink to this definition")

Switch which parity\_streak we’re pointing to and incerement if the

opponent’s last move was a Defection. Otherwise reset the flag. Then

return true if and only if the parity\_streak is at least

parity\_limit.

This is similar to detect\_streak with alternating streaks, except that

these streaks get incremented elsewhere as well.

`detect_random`(*turn*)[[source]](_modules/axelrod/strategies/axelrod_second.html#SecondByHarrington.detect_random)[¶](#axelrod.strategies.axelrod_second.SecondByHarrington.detect_random "Permalink to this definition")

We check if the top-left cell of the matrix (corresponding to all

Cooperations) has over 80% of the turns. In which case, we label

non-random.

Then we check if over 75% or under 25% of the opponent’s turns are

Defections. If so, then we label as non-random.

Otherwise we calculates a modified Pearson’s Chi Squared statistic on

self.history, and returns True (is random) if and only if the statistic

is less than or equal to 3.

`detect_streak`(*last\_move*)[[source]](_modules/axelrod/strategies/axelrod_second.html#SecondByHarrington.detect_streak)[¶](#axelrod.strategies.axelrod_second.SecondByHarrington.detect_streak "Permalink to this definition")

Return true if and only if the opponent’s last twenty moves are defects.

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/axelrod_second.html#SecondByHarrington.strategy)[¶](#axelrod.strategies.axelrod_second.SecondByHarrington.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

`try_return`(*to\_return*, *lower\_flags=True*, *inc\_parity=False*)[[source]](_modules/axelrod/strategies/axelrod_second.html#SecondByHarrington.try_return)[¶](#axelrod.strategies.axelrod_second.SecondByHarrington.try_return "Permalink to this definition")

This will return to\_return, with some end-of-turn logic.

*class* `axelrod.strategies.axelrod_second.``SecondByKluepfel`[[source]](_modules/axelrod/strategies/axelrod_second.html#SecondByKluepfel)[¶](#axelrod.strategies.axelrod_second.SecondByKluepfel "Permalink to this definition")

Strategy submitted to Axelrod’s second tournament by Charles Kluepfel

(K32R).

This player keeps track of the the opponent’s responses to own behavior:

* cd\_count counts: Opponent cooperates as response to player defecting.

* dd\_count counts: Opponent defects as response to player defecting.

* cc\_count counts: Opponent cooperates as response to player cooperating.

* dc\_count counts: Opponent defects as response to player cooperating.

After 26 turns, the player then tries to detect a random player. The

player decides that the opponent is random if

cd\_counts >= (cd\_counts+dd\_counts)/2 - 0.75\*sqrt(cd\_counts+dd\_counts) AND

cc\_counts >= (dc\_counts+cc\_counts)/2 - 0.75\*sqrt(dc\_counts+cc\_counts).

If the player decides that they are playing against a random player, then

they will always defect.

Otherwise respond to recent history using the following set of rules:

* If opponent’s last three choices are the same, then respond in kind.

* If opponent’s last two choices are the same, then respond in kind with

probability 90%.

* Otherwise if opponent’s last action was to cooperate, then cooperate

with probability 70%.

* Otherwise if opponent’s last action was to defect, then defect

with probability 60%.

Names:

* Kluepfel: [[Axelrod1980b]](index.html#axelrod1980b)

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/axelrod_second.html#SecondByKluepfel.strategy)[¶](#axelrod.strategies.axelrod_second.SecondByKluepfel.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.axelrod_second.``SecondByLeyvraz`[[source]](_modules/axelrod/strategies/axelrod_second.html#SecondByLeyvraz)[¶](#axelrod.strategies.axelrod_second.SecondByLeyvraz "Permalink to this definition")

Strategy submitted to Axelrod’s second tournament by Fransois Leyvraz

(K68R) and came in twelfth in that tournament.

The strategy uses the opponent’s last three moves to decide on an action

based on the following ordered rules.

1. If opponent Defected last two turns, then Defect with prob 75%.

2. If opponent Defected three turns ago, then Cooperate.

3. If opponent Defected two turns ago, then Defect.

4. If opponent Defected last turn, then Defect with prob 50%.

5. Otherwise (all Cooperations), then Cooperate.

Names:

* Leyvraz: [[Axelrod1980b]](index.html#axelrod1980b)

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/axelrod_second.html#SecondByLeyvraz.strategy)[¶](#axelrod.strategies.axelrod_second.SecondByLeyvraz.strategy "Permalink to this definition")

This is a placeholder strategy.

*class* `axelrod.strategies.axelrod_second.``SecondByMikkelson`[[source]](_modules/axelrod/strategies/axelrod_second.html#SecondByMikkelson)[¶](#axelrod.strategies.axelrod_second.SecondByMikkelson "Permalink to this definition")

Strategy submitted to Axelrod’s second tournament by Ray Mikkelson (K66R)

and came in twentieth in that tournament.

The strategy keeps track of a variable called credit, which determines if

the strategy will Cooperate, in the sense that if credit is positive,

then the strategy Cooperates. credit is initialized to 7. After the

first turn, credit increments if the opponent Cooperated last turn, and

decreases by two otherwise. credit is capped above by 8 and below by -7.

[credit is assessed as postive or negative, after increasing based on

opponent’s last turn.]

If credit is non-positive within the first ten turns, then the strategy

Defects and credit is set to 4. If credit is non-positive later, then

the strategy Defects if and only if (total # opponent Defections) / (turn#)

is at least 15%. [Turn # starts at 1.]

Names:

* Mikkelson: [[Axelrod1980b]](index.html#axelrod1980b)

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/axelrod_second.html#SecondByMikkelson.strategy)[¶](#axelrod.strategies.axelrod_second.SecondByMikkelson.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.axelrod_second.``SecondByRichardHufford`[[source]](_modules/axelrod/strategies/axelrod_second.html#SecondByRichardHufford)[¶](#axelrod.strategies.axelrod_second.SecondByRichardHufford "Permalink to this definition")

Strategy submitted to Axelrod’s second tournament by Richard Hufford (K47R)

and came in sixteenth in that tournament.

The strategy tracks opponent “agreements”, that is whenever the opponent’s

previous move is the some as this player’s move two turns ago. If the

opponent’s first move is a Defection, this is counted as a disagreement,

and otherwise an agreement. From the agreement counts, two measures are

calculated:

* proportion\_agree: This is the number of agreements (through opponent’s

last turn) + 2 divided by the current turn number.

* last\_four\_num: The number of agreements in the last four turns. If

there have been fewer than four previous turns, then this is number of

agreement + (4 - number of past turns).

We then use these measures to decide how to play, using these rules:

1. If proportion\_agree > 0.9 and last\_four\_num >= 4, then Cooperate.

2. Otherwise if proportion\_agree >= 0.625 and last\_four\_num >= 2, then

Tit-for-Tat.

3. Otherwise, Defect.

However, if the opponent has Cooperated the last streak\_needed turns,

then the strategy deviates from the usual strategy, and instead Defects.

(We call such deviation an “aberration”.) In the turn immediately after an

aberration, the strategy doesn’t override, even if there’s a streak of

Cooperations. Two turns after an aberration, the strategy: Restarts the

Cooperation streak (never looking before this turn); Cooperates; and

changes streak\_needed to:

floor(20.0 \* num\_abb\_def / num\_abb\_coop) + 1

Here num\_abb\_def is 2 + the number of times that the opponent Defected in

the turn after an aberration, and num\_abb\_coop is 2 + the number of times

that the opponent Cooperated in response to an aberration.

Names:

* RichardHufford: [[Axelrod1980b]](index.html#axelrod1980b)

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/axelrod_second.html#SecondByRichardHufford.strategy)[¶](#axelrod.strategies.axelrod_second.SecondByRichardHufford.strategy "Permalink to this definition")

This is a placeholder strategy.

*class* `axelrod.strategies.axelrod_second.``SecondByRowsam`[[source]](_modules/axelrod/strategies/axelrod_second.html#SecondByRowsam)[¶](#axelrod.strategies.axelrod_second.SecondByRowsam "Permalink to this definition")

Strategy submitted to Axelrod’s second tournament by Glen Rowsam (K58R)

and came in 21st in that tournament.

The strategy starts in Normal mode, where it cooperates every turn. Every

six turns it checks the score per turn. [Rather the score of all previous

turns divided by the turn number, which will be one more than the number of

turns scored.] If this measure is less than 2.5 (the strategy is doing

badly) and it increases distrust\_points. distrust\_points is a variable

that starts at 0; if it ever exceeds 6 points, the strategy will enter

Defect mode and defect from then on. It will increase distrust\_points

depending on the precise score per turn according to:

* 5 points if score per turn is less than 1.0

* 3 points if score per turn is less than 1.5, but at least 1.0

* 2 points if score per turn is less than 2.0, but at least 1.5

* 1 points if score per turn is less than 2.5, but at least 2.0

If distrust\_points are increased, then the strategy defects on that turn,

then cooperates and defects on the next two turns. [Unless

distrust\_points exceeds 6 points, then it will enter Defect mode

immediately.]

Every 18 turns in Normal mode, the strategy will decrement distrust\_score

if it’s more than 3. This represents a wearing off effect of distrust.

Names:

* Rowsam: [[Axelrod1980b]](index.html#axelrod1980b)

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/axelrod_second.html#SecondByRowsam.strategy)[¶](#axelrod.strategies.axelrod_second.SecondByRowsam.strategy "Permalink to this definition")

This is a placeholder strategy.

*class* `axelrod.strategies.axelrod_second.``SecondByTester`[[source]](_modules/axelrod/strategies/axelrod_second.html#SecondByTester)[¶](#axelrod.strategies.axelrod_second.SecondByTester "Permalink to this definition")

Submitted to Axelrod’s second tournament by David Gladstein.

This strategy is a TFT variant that attempts to exploit certain strategies. It

defects on the first move. If the opponent ever defects, TESTER ‘apologies’ by

cooperating and then plays TFT for the rest of the game. Otherwise TESTER

alternates cooperation and defection.

This strategy came 46th in Axelrod’s second tournament.

Names:

* Tester: [[Axelrod1980b]](index.html#axelrod1980b)

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/axelrod_second.html#SecondByTester.strategy)[¶](#axelrod.strategies.axelrod_second.SecondByTester.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.axelrod_second.``SecondByTidemanAndChieruzzi`[[source]](_modules/axelrod/strategies/axelrod_second.html#SecondByTidemanAndChieruzzi)[¶](#axelrod.strategies.axelrod_second.SecondByTidemanAndChieruzzi "Permalink to this definition")

Strategy submitted to Axelrod’s second tournament by T. Nicolaus Tideman

and Paula Chieruzzi (K84R) and came in ninth in that tournament.

This strategy Cooperates if this player’s score exceeds the opponent’s

score by at least score\_to\_beat. score\_to\_beat starts at zero and

increases by score\_to\_beat\_inc every time the opponent’s last two moves

are a Cooperation and Defection in that order. score\_to\_beat\_inc itself

increase by 5 every time the opponent’s last two moves are a Cooperation

and Defection in that order.

Additionally, the strategy executes a “fresh start” if the following hold:

* The strategy would Defect by score (difference less than score\_to\_beat)

* The opponent did not Cooperate and Defect (in order) in the last two

turns.

* It’s been at least 10 turns since the last fresh start. Or since the

match started if there hasn’t been a fresh start yet.

A “fresh start” entails two Cooperations and resetting scores,

scores\_to\_beat and scores\_to\_beat\_inc.

Names:

* TidemanAndChieruzzi: [[Axelrod1980b]](index.html#axelrod1980b)

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/axelrod_second.html#SecondByTidemanAndChieruzzi.strategy)[¶](#axelrod.strategies.axelrod_second.SecondByTidemanAndChieruzzi.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.axelrod_second.``SecondByTranquilizer`[[source]](_modules/axelrod/strategies/axelrod_second.html#SecondByTranquilizer)[¶](#axelrod.strategies.axelrod_second.SecondByTranquilizer "Permalink to this definition")

Submitted to Axelrod’s second tournament by Craig Feathers

Description given in Axelrod’s “More Effective Choice in the

Prisoner’s Dilemma” paper: The rule normally cooperates but

is ready to defect if the other player defects too often.

Thus the rule tends to cooperate for the first dozen or two moves

if the other player is cooperating, but then it throws in a

defection. If the other player continues to cooperate, then defections

become more frequent. But as long as Tranquilizer is maintaining an

average payoff of at least 2.25 points per move, it will never defect

twice in succession and it will not defect more than

one-quarter of the time.

This implementation is based on the reverse engineering of the

Fortran strategy K67R from Axelrod’s second tournament.

Reversed engineered by: Owen Campbell, Will Guo and Mansour Hakem.

The strategy starts by cooperating and has 3 states.

At the start of the strategy it updates its states:

* It counts the number of consecutive defections by the opponent.

* If it was in state 2 it moves to state 0 and calculates the

following quantities two\_turns\_after\_good\_defection\_ratio and

two\_turns\_after\_good\_defection\_ratio\_count.

Formula for:

two\_turns\_after\_good\_defection\_ratio:

self.two\_turns\_after\_good\_defection\_ratio = (

((self.two\_turns\_after\_good\_defection\_ratio

\* self.two\_turns\_after\_good\_defection\_ratio\_count)

+ (3 - (3 \* self.dict[opponent.history[-1]]))

+ (2 \* self.dict[self.history[-1]])

- ((self.dict[opponent.history[-1]]

\* self.dict[self.history[-1]])))

/ (self.two\_turns\_after\_good\_defection\_ratio\_count + 1)

)

two\_turns\_after\_good\_defection\_ratio\_count =

two\_turns\_after\_good\_defection\_ratio + 1

* If it was in state 1 it moves to state 2 and calculates the

following quantities one\_turn\_after\_good\_defection\_ratio and

one\_turn\_after\_good\_defection\_ratio\_count.

Formula for:

one\_turn\_after\_good\_defection\_ratio:

self.one\_turn\_after\_good\_defection\_ratio = (

((self.one\_turn\_after\_good\_defection\_ratio

\* self.one\_turn\_after\_good\_defection\_ratio\_count)

+ (3 - (3 \* self.dict[opponent.history[-1]]))

+ (2 \* self.dict[self.history[-1]])

- (self.dict[opponent.history[-1]]

\* self.dict[self.history[-1]]))

/ (self.one\_turn\_after\_good\_defection\_ratio\_count + 1)

)

one\_turn\_after\_good\_defection\_ratio\_count:

one\_turn\_after\_good\_defection\_ratio\_count =

one\_turn\_after\_good\_defection\_ratio + 1

If after this it is in state 1 or 2 then it cooperates.

If it is in state 0 it will potentially perform 1 of the 2

following stochastic tests:

1. If average score per turn is greater than 2.25 then it calculates a

value of probability:

probability = (

(.95 - (((self.one\_turn\_after\_good\_defection\_ratio)

+ (self.two\_turns\_after\_good\_defection\_ratio) - 5) / 15))

+ (1 / (((len(self.history))+1) \*\* 2))

- (self.dict[opponent.history[-1]] / 4)

)

and will cooperate if a random sampled number is less than that value of

probability. If it does not cooperate then the strategy moves to state 1

and defects.

2. If average score per turn is greater than 1.75 but less than 2.25

then it calculates a value of probability:

probability = (

(.25 + ((opponent.cooperations + 1) / ((len(self.history)) + 1)))

- (self.opponent\_consecutive\_defections \* .25)

+ ((current\_score[0]

- current\_score[1]) / 100)

+ (4 / ((len(self.history)) + 1))

)

and will cooperate if a random sampled number is less than that value of

probability. If not, it defects.

If none of the above holds the player simply plays tit for tat.

Tranquilizer came in 27th place in Axelrod’s second torunament.

Names:

* Tranquilizer: [[Axelrod1980]](index.html#axelrod1980)

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/axelrod_second.html#SecondByTranquilizer.strategy)[¶](#axelrod.strategies.axelrod_second.SecondByTranquilizer.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

`update_state`(*opponent*)[[source]](_modules/axelrod/strategies/axelrod_second.html#SecondByTranquilizer.update_state)[¶](#axelrod.strategies.axelrod_second.SecondByTranquilizer.update_state "Permalink to this definition")

Calculates the ratio values for the one\_turn\_after\_good\_defection\_ratio,

two\_turns\_after\_good\_defection\_ratio and the probability values,

and sets the value of num\_turns\_after\_good\_defection.

*class* `axelrod.strategies.axelrod_second.``SecondByWeiner`[[source]](_modules/axelrod/strategies/axelrod_second.html#SecondByWeiner)[¶](#axelrod.strategies.axelrod_second.SecondByWeiner "Permalink to this definition")

Strategy submitted to Axelrod’s second tournament by Herb Weiner (K41R),

and came in seventh in that tournament.

Play Tit-for-Tat with a chance for forgiveness and a defective override.

The chance for forgiveness happens only if forgive\_flag is raised

(flag discussed below). If raised and turn is greater than grudge,

then override Tit-for-Tat with Cooperation. grudge is a variable that

starts at 0 and increments 20 with each forgiven Defect (a Defect that is

overriden through the forgiveness logic). forgive\_flag is lower whether

logic is overriden or not.

The variable defect\_padding increments with each opponent Defect, but

resets to zero with each opponent Cooperate (or forgive\_flag lowering) so

that it roughly counts Defects between Cooperates. Whenever the opponent

Cooperates, if defect\_padding (before reseting) is odd, then we raise

forgive\_flag for next turn.

Finally a defective override is assessed after forgiveness. If five or

more of the opponent’s last twelve actions are Defects, then Defect. This

will overrule a forgiveness, but doesn’t undo the lowering of

forgiveness\_flag. Note that “last twelve actions” doesn’t count the most

recent action. Actually the original code updates history after checking

for defect override.

Names:

* Weiner: [[Axelrod1980b]](index.html#axelrod1980b)

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/axelrod_second.html#SecondByWeiner.strategy)[¶](#axelrod.strategies.axelrod_second.SecondByWeiner.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

`try_return`(*to\_return*)[[source]](_modules/axelrod/strategies/axelrod_second.html#SecondByWeiner.try_return)[¶](#axelrod.strategies.axelrod_second.SecondByWeiner.try_return "Permalink to this definition")

We put the logic here to check for the defective override.

*class* `axelrod.strategies.axelrod_second.``SecondByWhite`[[source]](_modules/axelrod/strategies/axelrod_second.html#SecondByWhite)[¶](#axelrod.strategies.axelrod_second.SecondByWhite "Permalink to this definition")

Strategy submitted to Axelrod’s second tournament by Edward C White (K72R)

and came in thirteenth in that tournament.

* Cooperate in the first ten turns.

* If the opponent Cooperated last turn then Cooperate.

* Otherwise Defect if and only if:

floor(log(turn)) \* opponent Defections >= turn

Names:

* White: [[Axelrod1980b]](index.html#axelrod1980b)

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/axelrod_second.html#SecondByWhite.strategy)[¶](#axelrod.strategies.axelrod_second.SecondByWhite.strategy "Permalink to this definition")

This is a placeholder strategy.

*class* `axelrod.strategies.axelrod_second.``SecondByWmAdams`[[source]](_modules/axelrod/strategies/axelrod_second.html#SecondByWmAdams)[¶](#axelrod.strategies.axelrod_second.SecondByWmAdams "Permalink to this definition")

Strategy submitted to Axelrod’s second tournament by William Adams (K44R),

and came in fifth in that tournament.

Count the number of opponent defections after their first move, call

c\_defect. Defect if c\_defect equals 4, 7, or 9. If c\_defect > 9,

then defect immediately after opponent defects with probability =

(0.5)^(c\_defect-1). Otherwise cooperate.

Names:

* WmAdams: [[Axelrod1980b]](index.html#axelrod1980b)

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/axelrod_second.html#SecondByWmAdams.strategy)[¶](#axelrod.strategies.axelrod_second.SecondByWmAdams.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.axelrod_second.``SecondByYamachi`[[source]](_modules/axelrod/strategies/axelrod_second.html#SecondByYamachi)[¶](#axelrod.strategies.axelrod_second.SecondByYamachi "Permalink to this definition")

Strategy submitted to Axelrod’s second tournament by Brian Yamachi (K64R)

and came in seventeenth in that tournament.

The strategy keeps track of play history through a variable called

count\_them\_us\_them, which is a dict indexed by (X, Y, Z), where X is an

opponent’s move and Y and Z are the following moves by this player and the

opponent, respectively. Each turn, we look at our opponent’s move two

turns ago, call X, and our move last turn, call Y. If (X, Y, C) has

occurred more often (or as often) as (X, Y, D), then Cooperate. Otherwise

Defect. [Note that this reflects likelihood of Cooperations or Defections

in opponent’s previous move; we don’t update count\_them\_us\_them with

previous move until next turn.]

Starting with the 41st turn, there’s a possibility to override this

behavior. If portion\_defect is between 45% and 55% (exclusive), then

Defect, where portion\_defect equals number of opponent defects plus 0.5

divided by the turn number (indexed by 1). When overriding this way, still

record count\_them\_us\_them as though the strategy didn’t override.

Names:

* Yamachi: [[Axelrod1980b]](index.html#axelrod1980b)

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/axelrod_second.html#SecondByYamachi.strategy)[¶](#axelrod.strategies.axelrod_second.SecondByYamachi.strategy "Permalink to this definition")

This is a placeholder strategy.

`try_return`(*to\_return*, *opp\_def*)[[source]](_modules/axelrod/strategies/axelrod_second.html#SecondByYamachi.try_return)[¶](#axelrod.strategies.axelrod_second.SecondByYamachi.try_return "Permalink to this definition")

Return to\_return, unless the turn is greater than 40 AND

portion\_defect is between 45% and 55%.

In this case, still record the history as to\_return so that the

modified behavior doesn’t affect the calculation of count\_us\_them\_us.

*class* `axelrod.strategies.backstabber.``BackStabber`[[source]](_modules/axelrod/strategies/backstabber.html#BackStabber)[¶](#axelrod.strategies.backstabber.BackStabber "Permalink to this definition")

Forgives the first 3 defections but on the fourth

will defect forever. Defects on the last 2 rounds unconditionally.

Names:

* Backstabber: Original name by Thomas Campbell

`original_class`[¶](#axelrod.strategies.backstabber.BackStabber.original_class "Permalink to this definition")

alias of [`BackStabber`](#axelrod.strategies.backstabber.BackStabber "axelrod.strategies.backstabber.BackStabber")

*class* `axelrod.strategies.backstabber.``DoubleCrosser`[[source]](_modules/axelrod/strategies/backstabber.html#DoubleCrosser)[¶](#axelrod.strategies.backstabber.DoubleCrosser "Permalink to this definition")

Forgives the first 3 defections but on the fourth

will defect forever. Defects on the last 2 rounds unconditionally.

If 8 <= current round <= 180,

if the opponent did not defect in the first 7 rounds,

the player will only defect after the opponent has defected twice in-a-row.

Names:

* Double Crosser: Original name by Thomas Campbell

`original_class`[¶](#axelrod.strategies.backstabber.DoubleCrosser.original_class "Permalink to this definition")

alias of [`DoubleCrosser`](#axelrod.strategies.backstabber.DoubleCrosser "axelrod.strategies.backstabber.DoubleCrosser")

*class* `axelrod.strategies.better_and_better.``BetterAndBetter`[[source]](_modules/axelrod/strategies/better_and_better.html#BetterAndBetter)[¶](#axelrod.strategies.better_and_better.BetterAndBetter "Permalink to this definition")

Defects with probability of ‘(1000 - current turn) / 1000’.

Therefore it is less and less likely to defect as the round goes on.

Names:

* Better and Better: [[Prison1998]](index.html#prison1998)

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/better_and_better.html#BetterAndBetter.strategy)[¶](#axelrod.strategies.better_and_better.BetterAndBetter.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.bush_mosteller.``BushMosteller`(*c\_prob: float = 0.5*, *d\_prob: float = 0.5*, *aspiration\_level\_divider: float = 3.0*, *learning\_rate: float = 0.5*)[[source]](_modules/axelrod/strategies/bush_mosteller.html#BushMosteller)[¶](#axelrod.strategies.bush_mosteller.BushMosteller "Permalink to this definition")

A player that is based on Bush Mosteller reinforced learning algorithm, it

decides what it will

play only depending on its own previous payoffs.

The probability of playing C or D will be updated using a stimulus which

represents a win or a loss of value based on its previous play’s payoff in

the specified probability. The more a play will be rewarded through rounds,

the more the player will be tempted to use it.

Names:

* Bush Mosteller: [[Luis2008]](index.html#luis2008)

`stimulus_update`(*opponent: axelrod.player.Player*)[[source]](_modules/axelrod/strategies/bush_mosteller.html#BushMosteller.stimulus_update)[¶](#axelrod.strategies.bush_mosteller.BushMosteller.stimulus_update "Permalink to this definition")

Updates the stimulus attribute based on the opponent’s history. Used by

the strategy.

Parameters

opponent : axelrod.Player

The current opponent

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/bush_mosteller.html#BushMosteller.strategy)[¶](#axelrod.strategies.bush_mosteller.BushMosteller.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.calculator.``Calculator`[[source]](_modules/axelrod/strategies/calculator.html#Calculator)[¶](#axelrod.strategies.calculator.Calculator "Permalink to this definition")

Plays like (Hard) Joss for the first 20 rounds. If periodic behavior is

detected, defect forever. Otherwise play TFT.

Names:

* Calculator: [[Prison1998]](index.html#prison1998)

`set_seed`(*seed: int = None*)[[source]](_modules/axelrod/strategies/calculator.html#Calculator.set_seed)[¶](#axelrod.strategies.calculator.Calculator.set_seed "Permalink to this definition")

Set a random seed for the player’s random number generator.

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/calculator.html#Calculator.strategy)[¶](#axelrod.strategies.calculator.Calculator.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.cooperator.``Cooperator`[[source]](_modules/axelrod/strategies/cooperator.html#Cooperator)[¶](#axelrod.strategies.cooperator.Cooperator "Permalink to this definition")

A player who only ever cooperates.

Names:

* Cooperator: [[Axelrod1984]](index.html#axelrod1984)

* ALLC: [[Press2012]](index.html#press2012)

* Always cooperate: [[Mittal2009]](index.html#mittal2009)

*static* `strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/cooperator.html#Cooperator.strategy)[¶](#axelrod.strategies.cooperator.Cooperator.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.cooperator.``TrickyCooperator`[[source]](_modules/axelrod/strategies/cooperator.html#TrickyCooperator)[¶](#axelrod.strategies.cooperator.TrickyCooperator "Permalink to this definition")

A cooperator that is trying to be tricky.

Names:

* Tricky Cooperator: Original name by Karol Langner

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/cooperator.html#TrickyCooperator.strategy)[¶](#axelrod.strategies.cooperator.TrickyCooperator.strategy "Permalink to this definition")

Almost always cooperates, but will try to trick the opponent by

defecting.

Defect once in a while in order to get a better payout.

After 3 rounds, if opponent has not defected to a max history depth of

10, defect.

*class* `axelrod.strategies.cycler.``AntiCycler`[[source]](_modules/axelrod/strategies/cycler.html#AntiCycler)[¶](#axelrod.strategies.cycler.AntiCycler "Permalink to this definition")

A player that follows a sequence of plays that contains no cycles:

CDD CD CCD CCCD CCCCD …

Names:

* Anti Cycler: Original name by Marc Harper

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/cycler.html#AntiCycler.strategy)[¶](#axelrod.strategies.cycler.AntiCycler.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.cycler.``Cycler`(*cycle: str = 'CCD'*)[[source]](_modules/axelrod/strategies/cycler.html#Cycler)[¶](#axelrod.strategies.cycler.Cycler "Permalink to this definition")

A player that repeats a given sequence indefinitely.

Names:

* Cycler: Original name by Marc Harper

`set_cycle`(*cycle: str*)[[source]](_modules/axelrod/strategies/cycler.html#Cycler.set_cycle)[¶](#axelrod.strategies.cycler.Cycler.set_cycle "Permalink to this definition")

Set or change the cycle.

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/cycler.html#Cycler.strategy)[¶](#axelrod.strategies.cycler.Cycler.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.cycler.``CyclerCCCCCD`[[source]](_modules/axelrod/strategies/cycler.html#CyclerCCCCCD)[¶](#axelrod.strategies.cycler.CyclerCCCCCD "Permalink to this definition")

Cycles C, C, C, C, C, D

Names:

* Cycler CCCD: Original name by Marc Harper

*class* `axelrod.strategies.cycler.``CyclerCCCD`[[source]](_modules/axelrod/strategies/cycler.html#CyclerCCCD)[¶](#axelrod.strategies.cycler.CyclerCCCD "Permalink to this definition")

Cycles C, C, C, D

Names:

* Cycler CCCD: Original name by Marc Harper

*class* `axelrod.strategies.cycler.``CyclerCCCDCD`[[source]](_modules/axelrod/strategies/cycler.html#CyclerCCCDCD)[¶](#axelrod.strategies.cycler.CyclerCCCDCD "Permalink to this definition")

Cycles C, C, C, D, C, D

Names:

* Cycler CCCDCD: Original name by Marc Harper

*class* `axelrod.strategies.cycler.``CyclerCCD`[[source]](_modules/axelrod/strategies/cycler.html#CyclerCCD)[¶](#axelrod.strategies.cycler.CyclerCCD "Permalink to this definition")

Cycles C, C, D

Names:

* Cycler CCD: Original name by Marc Harper

* Periodic player CCD: [[Mittal2009]](index.html#mittal2009)

*class* `axelrod.strategies.cycler.``CyclerDC`[[source]](_modules/axelrod/strategies/cycler.html#CyclerDC)[¶](#axelrod.strategies.cycler.CyclerDC "Permalink to this definition")

Cycles D, C

Names:

* Cycler DC: Original name by Marc Harper

*class* `axelrod.strategies.cycler.``CyclerDDC`[[source]](_modules/axelrod/strategies/cycler.html#CyclerDDC)[¶](#axelrod.strategies.cycler.CyclerDDC "Permalink to this definition")

Cycles D, D, C

Names:

* Cycler DDC: Original name by Marc Harper

* Periodic player DDC: [[Mittal2009]](index.html#mittal2009)

*class* `axelrod.strategies.cycler.``EvolvableCycler`(*cycle: str = None*, *cycle\_length: int = None*, *mutation\_probability: float = 0.2*, *mutation\_potency: int = 1*, *seed: int = None*)[[source]](_modules/axelrod/strategies/cycler.html#EvolvableCycler)[¶](#axelrod.strategies.cycler.EvolvableCycler "Permalink to this definition")

Evolvable version of Cycler.

`crossover`(*other*) → axelrod.evolvable\_player.EvolvablePlayer[[source]](_modules/axelrod/strategies/cycler.html#EvolvableCycler.crossover)[¶](#axelrod.strategies.cycler.EvolvableCycler.crossover "Permalink to this definition")

Creates and returns a new Player instance with a single crossover point.

`mutate`() → axelrod.evolvable\_player.EvolvablePlayer[[source]](_modules/axelrod/strategies/cycler.html#EvolvableCycler.mutate)[¶](#axelrod.strategies.cycler.EvolvableCycler.mutate "Permalink to this definition")

Basic mutation which may change any random actions in the sequence.

The player class in this module does not obey standard rules of the IPD (as

indicated by their classifier). We do not recommend putting a lot of time in to

optimising it.

*class* `axelrod.strategies.darwin.``Darwin`[[source]](_modules/axelrod/strategies/darwin.html#Darwin)[¶](#axelrod.strategies.darwin.Darwin "Permalink to this definition")

A strategy which accumulates a record (the ‘genome’) of what the most

favourable response in the previous round should have been, and naively

assumes that this will remain the correct response at the same round of

future trials.

This ‘genome’ is preserved between opponents, rounds and repetitions of

the tournament. It becomes a characteristic of the type and so a single

version of this is shared by all instances for each loading of the class.

As this results in information being preserved between tournaments, this

is classified as a cheating strategy!

If no record yet exists, the opponent’s response from the previous round

is returned.

Names:

* Darwin: Original name by Paul Slavin

`mutate`(*outcome: tuple*, *trial: int*) → None[[source]](_modules/axelrod/strategies/darwin.html#Darwin.mutate)[¶](#axelrod.strategies.darwin.Darwin.mutate "Permalink to this definition")

Select response according to outcome.

`reset`()[[source]](_modules/axelrod/strategies/darwin.html#Darwin.reset)[¶](#axelrod.strategies.darwin.Darwin.reset "Permalink to this definition")

Reset instance properties.

*static* `reset_genome`() → None[[source]](_modules/axelrod/strategies/darwin.html#Darwin.reset_genome)[¶](#axelrod.strategies.darwin.Darwin.reset_genome "Permalink to this definition")

For use in testing methods.

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/darwin.html#Darwin.strategy)[¶](#axelrod.strategies.darwin.Darwin.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.dbs.``DBS`(*discount\_factor=0.75*, *promotion\_threshold=3*, *violation\_threshold=4*, *reject\_threshold=3*, *tree\_depth=5*)[[source]](_modules/axelrod/strategies/dbs.html#DBS)[¶](#axelrod.strategies.dbs.DBS "Permalink to this definition")

A strategy that learns the opponent’s strategy and uses symbolic noise

detection for detecting whether anomalies in player’s behavior are

deliberate or accidental. From the learned opponent’s strategy, a tree

search is used to choose the best move.

Default values for the parameters are the suggested values in the article.

When noise increases you can try to diminish violation\_threshold and

rejection\_threshold.

Names

* Derived Belief Strategy: [[Au2006]](index.html#au2006)

`compute_prob_rule`(*outcome*, *alpha=1*)[[source]](_modules/axelrod/strategies/dbs.html#DBS.compute_prob_rule)[¶](#axelrod.strategies.dbs.DBS.compute_prob_rule "Permalink to this definition")

Uses the game history to compute the probability of the opponent

playing C, in the outcome situation (example: outcome = (C, C)).

When alpha = 1, the results is approximately equal to the frequency of

the occurrence of outcome C. alpha is a discount factor that gives more

weight to recent events than earlier ones.

Parameters

outcome: tuple of two actions.Action

alpha: int, optional. Discount factor. Default is 1.

`should_demote`(*r\_minus*, *violation\_threshold=4*)[[source]](_modules/axelrod/strategies/dbs.html#DBS.should_demote)[¶](#axelrod.strategies.dbs.DBS.should_demote "Permalink to this definition")

Checks if the number of successive violations of a deterministic

rule (in the opponent’s behavior) exceeds the user-defined

violation\_threshold.

`should_promote`(*r\_plus*, *promotion\_threshold=3*)[[source]](_modules/axelrod/strategies/dbs.html#DBS.should_promote)[¶](#axelrod.strategies.dbs.DBS.should_promote "Permalink to this definition")

This function determines if the move r\_plus is a deterministic

behavior of the opponent, and then returns True, or if r\_plus

is due to a random behavior (or noise) which would require a

probabilistic rule, in which case it returns False.

To do so it looks into the game history: if the k last times

when the opponent was in the same situation than in r\_plus it

played the same thing then then r\_plus is considered as a

deterministic rule (where K is the user-defined promotion\_threshold).

Parameters

r\_plus: tuple of (tuple of actions.Action, actions.Action)

example: ((C, C), D)

r\_plus represents one outcome of the history, and the

following move played by the opponent.

promotion\_threshold: int, optional

Number of successive observations needed to promote an

opponent behavior as a deterministic rule. Default is 3.

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/dbs.html#DBS.strategy)[¶](#axelrod.strategies.dbs.DBS.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

`update_history_by_cond`(*opponent\_history*)[[source]](_modules/axelrod/strategies/dbs.html#DBS.update_history_by_cond)[¶](#axelrod.strategies.dbs.DBS.update_history_by_cond "Permalink to this definition")

Updates self.history\_by\_cond between each turns of the game.

*class* `axelrod.strategies.dbs.``DeterministicNode`(*action1*, *action2*, *depth*)[[source]](_modules/axelrod/strategies/dbs.html#DeterministicNode)[¶](#axelrod.strategies.dbs.DeterministicNode "Permalink to this definition")

Nodes (C, C), (C, D), (D, C), or (D, D) with deterministic choice

for siblings.

`get_siblings`(*policy*)[[source]](_modules/axelrod/strategies/dbs.html#DeterministicNode.get_siblings)[¶](#axelrod.strategies.dbs.DeterministicNode.get_siblings "Permalink to this definition")

Returns the siblings node of the current DeterministicNode. Builds 2

siblings (C, X) and (D, X) that are StochasticNodes. Those siblings are

of the same depth as the current node. Their probabilities pC are

defined by the policy argument.

`is_stochastic`()[[source]](_modules/axelrod/strategies/dbs.html#DeterministicNode.is_stochastic)[¶](#axelrod.strategies.dbs.DeterministicNode.is_stochastic "Permalink to this definition")

Returns True if self is a StochasticNode.

*class* `axelrod.strategies.dbs.``Node`[[source]](_modules/axelrod/strategies/dbs.html#Node)[¶](#axelrod.strategies.dbs.Node "Permalink to this definition")

Nodes used to build a tree for the tree-search procedure. The tree has

Deterministic and Stochastic nodes, as the opponent’s strategy is learned

as a probability distribution.

*class* `axelrod.strategies.dbs.``StochasticNode`(*own\_action*, *pC*, *depth*)[[source]](_modules/axelrod/strategies/dbs.html#StochasticNode)[¶](#axelrod.strategies.dbs.StochasticNode "Permalink to this definition")

Node that have a probability pC to get to each sibling. A StochasticNode can

be written (C, X) or (D, X), with X = C with a probability pC, else X = D.

`get_siblings`()[[source]](_modules/axelrod/strategies/dbs.html#StochasticNode.get_siblings)[¶](#axelrod.strategies.dbs.StochasticNode.get_siblings "Permalink to this definition")

Returns the siblings node of the current StochasticNode. There are two

siblings which are DeterministicNodes, their depth is equal to current

node depth’s + 1.

`is_stochastic`()[[source]](_modules/axelrod/strategies/dbs.html#StochasticNode.is_stochastic)[¶](#axelrod.strategies.dbs.StochasticNode.is_stochastic "Permalink to this definition")

Returns True if self is a StochasticNode.

`axelrod.strategies.dbs.``create_policy`(*pCC*, *pCD*, *pDC*, *pDD*)[[source]](_modules/axelrod/strategies/dbs.html#create_policy)[¶](#axelrod.strategies.dbs.create_policy "Permalink to this definition")

Creates a dict that represents a Policy. As defined in the reference, a

Policy is a set of (prev\_move, p) where p is the probability to cooperate

after prev\_move, where prev\_move can be (C, C), (C, D), (D, C) or (D, D).

Parameters

pCC, pCD, pDC, pDD : float

Must be between 0 and 1.

`axelrod.strategies.dbs.``minimax_tree_search`(*begin\_node*, *policy*, *max\_depth*)[[source]](_modules/axelrod/strategies/dbs.html#minimax_tree_search)[¶](#axelrod.strategies.dbs.minimax_tree_search "Permalink to this definition")

Tree search function (minimax search procedure) for the tree (built by

recursion) corresponding to the opponent’s policy, and solves it.

Returns a tuple of two floats that are the utility of playing C, and the

utility of playing D.

`axelrod.strategies.dbs.``move_gen`(*outcome*, *policy*, *depth\_search\_tree=5*)[[source]](_modules/axelrod/strategies/dbs.html#move_gen)[¶](#axelrod.strategies.dbs.move_gen "Permalink to this definition")

Returns the best move considering opponent’s policy and last move,

using tree-search procedure.

*class* `axelrod.strategies.defector.``Defector`[[source]](_modules/axelrod/strategies/defector.html#Defector)[¶](#axelrod.strategies.defector.Defector "Permalink to this definition")

A player who only ever defects.

Names:

* Defector: [[Axelrod1984]](index.html#axelrod1984)

* ALLD: [[Press2012]](index.html#press2012)

* Always defect: [[Mittal2009]](index.html#mittal2009)

*static* `strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/defector.html#Defector.strategy)[¶](#axelrod.strategies.defector.Defector.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.defector.``TrickyDefector`[[source]](_modules/axelrod/strategies/defector.html#TrickyDefector)[¶](#axelrod.strategies.defector.TrickyDefector "Permalink to this definition")

A defector that is trying to be tricky.

Names:

* Tricky Defector: Original name by Karol Langner

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/defector.html#TrickyDefector.strategy)[¶](#axelrod.strategies.defector.TrickyDefector.strategy "Permalink to this definition")

Almost always defects, but will try to trick the opponent into

cooperating.

Defect if opponent has cooperated at least once in the past and has

defected for the last 3 turns in a row.

*class* `axelrod.strategies.doubler.``Doubler`[[source]](_modules/axelrod/strategies/doubler.html#Doubler)[¶](#axelrod.strategies.doubler.Doubler "Permalink to this definition")

Cooperates except when the opponent has defected and

the opponent’s cooperation count is less than twice their defection count.

Names:

* Doubler: [[Prison1998]](index.html#prison1998)

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/doubler.html#Doubler.strategy)[¶](#axelrod.strategies.doubler.Doubler.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.finite_state_machines.``EvolvableFSMPlayer`(*transitions: tuple = None*, *initial\_state: int = None*, *initial\_action: axelrod.action.Action = None*, *num\_states: int = None*, *mutation\_probability: float = 0.1*, *seed: int = None*)[[source]](_modules/axelrod/strategies/finite_state_machines.html#EvolvableFSMPlayer)[¶](#axelrod.strategies.finite_state_machines.EvolvableFSMPlayer "Permalink to this definition")

Abstract base class for evolvable finite state machine players.

`create_vector_bounds`()[[source]](_modules/axelrod/strategies/finite_state_machines.html#EvolvableFSMPlayer.create_vector_bounds)[¶](#axelrod.strategies.finite_state_machines.EvolvableFSMPlayer.create_vector_bounds "Permalink to this definition")

Creates the bounds for the decision variables.

`crossover`(*other*)[[source]](_modules/axelrod/strategies/finite_state_machines.html#EvolvableFSMPlayer.crossover)[¶](#axelrod.strategies.finite_state_machines.EvolvableFSMPlayer.crossover "Permalink to this definition")

Optional method to allow Player to produce variants in combination with another player. Returns a new

Player.

`mutate`()[[source]](_modules/axelrod/strategies/finite_state_machines.html#EvolvableFSMPlayer.mutate)[¶](#axelrod.strategies.finite_state_machines.EvolvableFSMPlayer.mutate "Permalink to this definition")

Optional method to allow Player to produce a variant (not in place).

*classmethod* `normalize_transitions`(*transitions: Sequence[Sequence[T\_co]]*) → Tuple[Tuple[Any, ...], ...][[source]](_modules/axelrod/strategies/finite_state_machines.html#EvolvableFSMPlayer.normalize_transitions)[¶](#axelrod.strategies.finite_state_machines.EvolvableFSMPlayer.normalize_transitions "Permalink to this definition")

Translate a list of lists to a tuple of tuples.

`receive_vector`(*vector*)[[source]](_modules/axelrod/strategies/finite_state_machines.html#EvolvableFSMPlayer.receive_vector)[¶](#axelrod.strategies.finite_state_machines.EvolvableFSMPlayer.receive_vector "Permalink to this definition")

Read a serialized vector into the set of FSM parameters (less initial

state). Then assign those FSM parameters to this class instance.

The vector has three parts. The first is used to define the next state

(for each of the player’s states - for each opponents action).

The second part is the player’s next moves (for each state - for

each opponent’s actions).

Finally, a probability to determine the player’s first move.

*class* `axelrod.strategies.finite_state_machines.``EvolvedFSM16`[[source]](_modules/axelrod/strategies/finite_state_machines.html#EvolvedFSM16)[¶](#axelrod.strategies.finite_state_machines.EvolvedFSM16 "Permalink to this definition")

A 16 state FSM player trained with an evolutionary algorithm.

Names:

> 

> * Evolved FSM 16: Original name by Marc Harper

> 

> 

> 

*class* `axelrod.strategies.finite_state_machines.``EvolvedFSM16Noise05`[[source]](_modules/axelrod/strategies/finite_state_machines.html#EvolvedFSM16Noise05)[¶](#axelrod.strategies.finite_state_machines.EvolvedFSM16Noise05 "Permalink to this definition")

A 16 state FSM player trained with an evolutionary algorithm with

noisy matches (noise=0.05).

Names:

> 

> * Evolved FSM 16 Noise 05: Original name by Marc Harper

> 

> 

> 

*class* `axelrod.strategies.finite_state_machines.``EvolvedFSM4`[[source]](_modules/axelrod/strategies/finite_state_machines.html#EvolvedFSM4)[¶](#axelrod.strategies.finite_state_machines.EvolvedFSM4 "Permalink to this definition")

A 4 state FSM player trained with an evolutionary algorithm.

Names:

> 

> * Evolved FSM 4: Original name by Marc Harper

> 

> 

> 

*class* `axelrod.strategies.finite_state_machines.``EvolvedFSM6`[[source]](_modules/axelrod/strategies/finite_state_machines.html#EvolvedFSM6)[¶](#axelrod.strategies.finite_state_machines.EvolvedFSM6 "Permalink to this definition")

An 6 state FSM player trained with an evolutionary algorithm.

Evolved using axelrod-dojo version 0.0.8 and axelrod version 4.10.0, trained to maximize score against

the short\_run\_time\_strategies with 10 machine states for 500 generations, population size of 40,

mutation rate at 0.1, bottleneck at 10, 200 turns, and 0 noise. The resulting strategy had only 6

states in its accessible component.

Names:

> 

> * Evolved FSM 6: Original name by Frederick Vincent & Dashiell Fryer

> 

> 

> 

*class* `axelrod.strategies.finite_state_machines.``FSMPlayer`(*transitions: Tuple[Tuple[int, axelrod.action.Action, int, axelrod.action.Action], ...] = ((1, C, 1, C), (1, D, 1, D)), initial\_state: int = 1, initial\_action: axelrod.action.Action = C*)[[source]](_modules/axelrod/strategies/finite_state_machines.html#FSMPlayer)[¶](#axelrod.strategies.finite_state_machines.FSMPlayer "Permalink to this definition")

Abstract base class for finite state machine players.

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/finite_state_machines.html#FSMPlayer.strategy)[¶](#axelrod.strategies.finite_state_machines.FSMPlayer.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.finite_state_machines.``Fortress3`[[source]](_modules/axelrod/strategies/finite_state_machines.html#Fortress3)[¶](#axelrod.strategies.finite_state_machines.Fortress3 "Permalink to this definition")

Finite state machine player specified in <http://DOI.org/10.1109/CEC.2006.1688322>.

Note that the description in <http://www.graham-kendall.com/papers/lhk2011.pdf>

is not correct.

Names:

* Fortress 3: [[Ashlock2006b]](index.html#ashlock2006b)

*class* `axelrod.strategies.finite_state_machines.``Fortress4`[[source]](_modules/axelrod/strategies/finite_state_machines.html#Fortress4)[¶](#axelrod.strategies.finite_state_machines.Fortress4 "Permalink to this definition")

Finite state machine player specified in

<http://DOI.org/10.1109/CEC.2006.1688322>.

Note that the description in

<http://www.graham-kendall.com/papers/lhk2011.pdf> is not correct.

Names:

* Fortress 4: [[Ashlock2006b]](index.html#ashlock2006b)

*class* `axelrod.strategies.finite_state_machines.``Predator`[[source]](_modules/axelrod/strategies/finite_state_machines.html#Predator)[¶](#axelrod.strategies.finite_state_machines.Predator "Permalink to this definition")

Finite state machine player specified in

<http://DOI.org/10.1109/CEC.2006.1688322>.

Names:

* Predator: [[Ashlock2006b]](index.html#ashlock2006b)

*class* `axelrod.strategies.finite_state_machines.``Pun1`[[source]](_modules/axelrod/strategies/finite_state_machines.html#Pun1)[¶](#axelrod.strategies.finite_state_machines.Pun1 "Permalink to this definition")

FSM player described in [[Ashlock2006]](index.html#ashlock2006).

Names:

* Pun1: [[Ashlock2006]](index.html#ashlock2006)

*class* `axelrod.strategies.finite_state_machines.``Raider`[[source]](_modules/axelrod/strategies/finite_state_machines.html#Raider)[¶](#axelrod.strategies.finite_state_machines.Raider "Permalink to this definition")

FSM player described in <http://DOI.org/10.1109/FOCI.2014.7007818>.

Names

* Raider: [[Ashlock2014]](index.html#ashlock2014)

*class* `axelrod.strategies.finite_state_machines.``Ripoff`[[source]](_modules/axelrod/strategies/finite_state_machines.html#Ripoff)[¶](#axelrod.strategies.finite_state_machines.Ripoff "Permalink to this definition")

FSM player described in <http://DOI.org/10.1109/TEVC.2008.920675>.

Names

* Ripoff: [[Ashlock2008]](index.html#ashlock2008)

*class* `axelrod.strategies.finite_state_machines.``SimpleFSM`(*transitions: tuple*, *initial\_state: int*)[[source]](_modules/axelrod/strategies/finite_state_machines.html#SimpleFSM)[¶](#axelrod.strategies.finite_state_machines.SimpleFSM "Permalink to this definition")

Simple implementation of a finite state machine that transitions

between states based on the last round of play.

<https://en.wikipedia.org/wiki/Finite-state_machine>

`move`(*opponent\_action: axelrod.action.Action*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/finite_state_machines.html#SimpleFSM.move)[¶](#axelrod.strategies.finite_state_machines.SimpleFSM.move "Permalink to this definition")

Computes the response move and changes state.

`num_states`()[[source]](_modules/axelrod/strategies/finite_state_machines.html#SimpleFSM.num_states)[¶](#axelrod.strategies.finite_state_machines.SimpleFSM.num_states "Permalink to this definition")

Return the number of states of the machine.

*class* `axelrod.strategies.finite_state_machines.``SolutionB1`[[source]](_modules/axelrod/strategies/finite_state_machines.html#SolutionB1)[¶](#axelrod.strategies.finite_state_machines.SolutionB1 "Permalink to this definition")

FSM player described in <http://DOI.org/10.1109/TCIAIG.2014.2326012>.

Names

* Solution B1: [[Ashlock2015]](index.html#ashlock2015)

*class* `axelrod.strategies.finite_state_machines.``SolutionB5`[[source]](_modules/axelrod/strategies/finite_state_machines.html#SolutionB5)[¶](#axelrod.strategies.finite_state_machines.SolutionB5 "Permalink to this definition")

FSM player described in <http://DOI.org/10.1109/TCIAIG.2014.2326012>.

Names

* Solution B5: [[Ashlock2015]](index.html#ashlock2015)

*class* `axelrod.strategies.finite_state_machines.``TF1`[[source]](_modules/axelrod/strategies/finite_state_machines.html#TF1)[¶](#axelrod.strategies.finite_state_machines.TF1 "Permalink to this definition")

A FSM player trained to maximize Moran fixation probabilities.

Names:

> 

> * TF1: Original name by Marc Harper

> 

> 

> 

*class* `axelrod.strategies.finite_state_machines.``TF2`[[source]](_modules/axelrod/strategies/finite_state_machines.html#TF2)[¶](#axelrod.strategies.finite_state_machines.TF2 "Permalink to this definition")

A FSM player trained to maximize Moran fixation probabilities.

Names:

> 

> * TF2: Original name by Marc Harper

> 

> 

> 

*class* `axelrod.strategies.finite_state_machines.``TF3`[[source]](_modules/axelrod/strategies/finite_state_machines.html#TF3)[¶](#axelrod.strategies.finite_state_machines.TF3 "Permalink to this definition")

A FSM player trained to maximize Moran fixation probabilities.

Names:

> 

> * TF3: Original name by Marc Harper

> 

> 

> 

*class* `axelrod.strategies.finite_state_machines.``Thumper`[[source]](_modules/axelrod/strategies/finite_state_machines.html#Thumper)[¶](#axelrod.strategies.finite_state_machines.Thumper "Permalink to this definition")

FSM player described in <http://DOI.org/10.1109/TEVC.2008.920675>.

Names

* Thumper: [[Ashlock2008]](index.html#ashlock2008)

*class* `axelrod.strategies.finite_state_machines.``UsuallyCooperates`[[source]](_modules/axelrod/strategies/finite_state_machines.html#UsuallyCooperates)[¶](#axelrod.strategies.finite_state_machines.UsuallyCooperates "Permalink to this definition")

This strategy cooperates except after a C following a D.

Names:

* Usually Cooperates (UC): [[Ashlock2009]](index.html#ashlock2009)

*class* `axelrod.strategies.finite_state_machines.``UsuallyDefects`[[source]](_modules/axelrod/strategies/finite_state_machines.html#UsuallyDefects)[¶](#axelrod.strategies.finite_state_machines.UsuallyDefects "Permalink to this definition")

This strategy defects except after a D following a C.

Names:

* Usually Defects (UD): [[Ashlock2009]](index.html#ashlock2009)

*class* `axelrod.strategies.forgiver.``Forgiver`[[source]](_modules/axelrod/strategies/forgiver.html#Forgiver)[¶](#axelrod.strategies.forgiver.Forgiver "Permalink to this definition")

A player starts by cooperating however will defect if at any point

the opponent has defected more than 10 percent of the time

Names:

* Forgiver: Original name by Thomas Campbell

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/forgiver.html#Forgiver.strategy)[¶](#axelrod.strategies.forgiver.Forgiver.strategy "Permalink to this definition")

Begins by playing C, then plays D if the opponent has defected more

than 10 percent of the time.

*class* `axelrod.strategies.forgiver.``ForgivingTitForTat`[[source]](_modules/axelrod/strategies/forgiver.html#ForgivingTitForTat)[¶](#axelrod.strategies.forgiver.ForgivingTitForTat "Permalink to this definition")

A player starts by cooperating however will defect if at any point, the

opponent has defected more than 10 percent of the time, and their most

recent decision was defect.

Names:

* Forgiving Tit For Tat: Original name by Thomas Campbell

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/forgiver.html#ForgivingTitForTat.strategy)[¶](#axelrod.strategies.forgiver.ForgivingTitForTat.strategy "Permalink to this definition")

Begins by playing C, then plays D if the opponent has defected more than

10 percent of the time and their most recent decision was defect.

Stochastic variants of Lookup table based-strategies, trained with particle

swarm algorithms.

For the original see:

<https://gist.github.com/GDKO/60c3d0fd423598f3c4e4>

*class* `axelrod.strategies.gambler.``EvolvableGambler`(*lookup\_dict: dict = None*, *initial\_actions: tuple = None*, *pattern: Any = None*, *parameters: axelrod.strategies.lookerup.Plays = None*, *mutation\_probability: float = None*, *seed: int = None*)[[source]](_modules/axelrod/strategies/gambler.html#EvolvableGambler)[¶](#axelrod.strategies.gambler.EvolvableGambler "Permalink to this definition")

`create_vector_bounds`()[[source]](_modules/axelrod/strategies/gambler.html#EvolvableGambler.create_vector_bounds)[¶](#axelrod.strategies.gambler.EvolvableGambler.create_vector_bounds "Permalink to this definition")

Creates the bounds for the decision variables. Ignores extra parameters.

`receive_vector`(*vector*)[[source]](_modules/axelrod/strategies/gambler.html#EvolvableGambler.receive_vector)[¶](#axelrod.strategies.gambler.EvolvableGambler.receive_vector "Permalink to this definition")

Receives a vector and updates the player’s pattern. Ignores extra parameters.

*class* `axelrod.strategies.gambler.``Gambler`(*lookup\_dict: dict = None*, *initial\_actions: tuple = None*, *pattern: Any = None*, *parameters: axelrod.strategies.lookerup.Plays = None*)[[source]](_modules/axelrod/strategies/gambler.html#Gambler)[¶](#axelrod.strategies.gambler.Gambler "Permalink to this definition")

A stochastic version of LookerUp which will select randomly an action in

some cases.

Names:

* Gambler: Original name by Georgios Koutsovoulos

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/gambler.html#Gambler.strategy)[¶](#axelrod.strategies.gambler.Gambler.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.gambler.``PSOGambler1_1_1`[[source]](_modules/axelrod/strategies/gambler.html#PSOGambler1_1_1)[¶](#axelrod.strategies.gambler.PSOGambler1_1_1 "Permalink to this definition")

A 1x1x1 PSOGambler trained with pyswarm.

Names:

* PSO Gambler 1\_1\_1: Original name by Marc Harper

*class* `axelrod.strategies.gambler.``PSOGambler2_2_2`[[source]](_modules/axelrod/strategies/gambler.html#PSOGambler2_2_2)[¶](#axelrod.strategies.gambler.PSOGambler2_2_2 "Permalink to this definition")

A 2x2x2 PSOGambler trained with a particle swarm algorithm (implemented in

pyswarm). Original version by Georgios Koutsovoulos.

Names:

* PSO Gambler 2\_2\_2: Original name by Marc Harper

*class* `axelrod.strategies.gambler.``PSOGambler2_2_2_Noise05`[[source]](_modules/axelrod/strategies/gambler.html#PSOGambler2_2_2_Noise05)[¶](#axelrod.strategies.gambler.PSOGambler2_2_2_Noise05 "Permalink to this definition")

A 2x2x2 PSOGambler trained with pyswarm with noise=0.05.

Names:

* PSO Gambler 2\_2\_2 Noise 05: Original name by Marc Harper

*class* `axelrod.strategies.gambler.``PSOGamblerMem1`[[source]](_modules/axelrod/strategies/gambler.html#PSOGamblerMem1)[¶](#axelrod.strategies.gambler.PSOGamblerMem1 "Permalink to this definition")

A 1x1x0 PSOGambler trained with pyswarm. This is the ‘optimal’ memory one

strategy trained against the set of short run time strategies in the

Axelrod library.

Names:

* PSO Gambler Mem1: Original name by Marc Harper

*class* `axelrod.strategies.gambler.``ZDMem2`[[source]](_modules/axelrod/strategies/gambler.html#ZDMem2)[¶](#axelrod.strategies.gambler.ZDMem2 "Permalink to this definition")

A memory two generalization of a zero determinant player.

Names:

* ZDMem2: Original name by Marc Harper

* Unnamed [[LiS2014]](index.html#lis2014)

*class* `axelrod.strategies.gobymajority.``GoByMajority`(*memory\_depth: Union[int*, *float] = inf*, *soft: bool = True*)[[source]](_modules/axelrod/strategies/gobymajority.html#GoByMajority)[¶](#axelrod.strategies.gobymajority.GoByMajority "Permalink to this definition")

Submitted to Axelrod’s second tournament by Gail Grisell. It came 23rd

and was written in 10 lines of BASIC.

A player examines the history of the opponent: if the opponent has more

defections than cooperations then the player defects.

In case of equal

number of defections and cooperations this player will Cooperate. Passing

the soft=False keyword argument when initialising will create a

HardGoByMajority which Defects in case of equality.

An optional memory attribute will limit the number of turns remembered (by

default this is 0)

Names:

* Go By Majority: [[Axelrod1984]](index.html#axelrod1984)

* Grisell: [[Axelrod1980b]](index.html#axelrod1980b)

* Soft Majority: [[Mittal2009]](index.html#mittal2009)

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/gobymajority.html#GoByMajority.strategy)[¶](#axelrod.strategies.gobymajority.GoByMajority.strategy "Permalink to this definition")

This is affected by the history of the opponent.

As long as the opponent cooperates at least as often as they defect then

the player will cooperate. If at any point the opponent has more

defections than cooperations in memory the player defects.

*class* `axelrod.strategies.gobymajority.``GoByMajority10`[[source]](_modules/axelrod/strategies/gobymajority.html#GoByMajority10)[¶](#axelrod.strategies.gobymajority.GoByMajority10 "Permalink to this definition")

GoByMajority player with a memory of 10.

Names:

* Go By Majority 10: Original name by Karol Langner

*class* `axelrod.strategies.gobymajority.``GoByMajority20`[[source]](_modules/axelrod/strategies/gobymajority.html#GoByMajority20)[¶](#axelrod.strategies.gobymajority.GoByMajority20 "Permalink to this definition")

GoByMajority player with a memory of 20.

Names:

* Go By Majority 20: Original name by Karol Langner

*class* `axelrod.strategies.gobymajority.``GoByMajority40`[[source]](_modules/axelrod/strategies/gobymajority.html#GoByMajority40)[¶](#axelrod.strategies.gobymajority.GoByMajority40 "Permalink to this definition")

GoByMajority player with a memory of 40.

Names:

* Go By Majority 40: Original name by Karol Langner

*class* `axelrod.strategies.gobymajority.``GoByMajority5`[[source]](_modules/axelrod/strategies/gobymajority.html#GoByMajority5)[¶](#axelrod.strategies.gobymajority.GoByMajority5 "Permalink to this definition")

GoByMajority player with a memory of 5.

Names:

* Go By Majority 5: Original name by Karol Langner

*class* `axelrod.strategies.gobymajority.``HardGoByMajority`(*memory\_depth: Union[int*, *float] = inf*)[[source]](_modules/axelrod/strategies/gobymajority.html#HardGoByMajority)[¶](#axelrod.strategies.gobymajority.HardGoByMajority "Permalink to this definition")

A player examines the history of the opponent: if the opponent has more

defections than cooperations then the player defects. In case of equal

number of defections and cooperations this player will Defect.

An optional memory attribute will limit the number of turns remembered (by

default this is 0)

Names:

* Hard Majority: [[Mittal2009]](index.html#mittal2009)

*class* `axelrod.strategies.gobymajority.``HardGoByMajority10`[[source]](_modules/axelrod/strategies/gobymajority.html#HardGoByMajority10)[¶](#axelrod.strategies.gobymajority.HardGoByMajority10 "Permalink to this definition")

HardGoByMajority player with a memory of 10.

Names:

* Hard Go By Majority 10: Original name by Karol Langner

*class* `axelrod.strategies.gobymajority.``HardGoByMajority20`[[source]](_modules/axelrod/strategies/gobymajority.html#HardGoByMajority20)[¶](#axelrod.strategies.gobymajority.HardGoByMajority20 "Permalink to this definition")

HardGoByMajority player with a memory of 20.

Names:

* Hard Go By Majority 20: Original name by Karol Langner

*class* `axelrod.strategies.gobymajority.``HardGoByMajority40`[[source]](_modules/axelrod/strategies/gobymajority.html#HardGoByMajority40)[¶](#axelrod.strategies.gobymajority.HardGoByMajority40 "Permalink to this definition")

HardGoByMajority player with a memory of 40.

Names:

* Hard Go By Majority 40: Original name by Karol Langner

*class* `axelrod.strategies.gobymajority.``HardGoByMajority5`[[source]](_modules/axelrod/strategies/gobymajority.html#HardGoByMajority5)[¶](#axelrod.strategies.gobymajority.HardGoByMajority5 "Permalink to this definition")

HardGoByMajority player with a memory of 5.

Names:

* Hard Go By Majority 5: Original name by Karol Langner

*class* `axelrod.strategies.gradualkiller.``GradualKiller`[[source]](_modules/axelrod/strategies/gradualkiller.html#GradualKiller)[¶](#axelrod.strategies.gradualkiller.GradualKiller "Permalink to this definition")

It begins by defecting in the first five moves, then cooperates two times.

It then defects all the time if the opponent has defected in move 6 and 7,

else cooperates all the time.

Initially designed to stop Gradual from defeating TitForTat in a 3 Player

tournament.

Names

* Gradual Killer: [[Prison1998]](index.html#prison1998)

`original_class`[¶](#axelrod.strategies.gradualkiller.GradualKiller.original_class "Permalink to this definition")

alias of [`GradualKiller`](#axelrod.strategies.gradualkiller.GradualKiller "axelrod.strategies.gradualkiller.GradualKiller")

*class* `axelrod.strategies.grudger.``Aggravater`[[source]](_modules/axelrod/strategies/grudger.html#Aggravater)[¶](#axelrod.strategies.grudger.Aggravater "Permalink to this definition")

Grudger, except that it defects on the first 3 turns

Names

* Aggravater: Original name by Thomas Campbell

*static* `strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/grudger.html#Aggravater.strategy)[¶](#axelrod.strategies.grudger.Aggravater.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.grudger.``Capri`[[source]](_modules/axelrod/strategies/grudger.html#Capri)[¶](#axelrod.strategies.grudger.Capri "Permalink to this definition")

CAPRI is a memory-3 strategy proposed in [[Murase2020]](index.html#murase2020). Its behavior is

defined by the following five rules applied to the last 3 moves of the

player and the opponent:

* C: Cooperate at mutual cooperation. This rule prescribes c at (ccc, ccc).

* A: Accept punishment when you mistakenly defected from mutual cooperation.

This rule prescribes c at (ccd, ccc), (cdc, ccd), (dcc, cdc), and (ccc,

dcc).

* P: Punish your co-player by defecting once when he defected from mutual

cooperation. This rule prescribes d at (ccc, ccd), and then c at (ccd,

cdc), (cdc, dcc), and (dcc, ccc).

* R: Recover cooperation when you or your co-player cooperated at mutual

defection. This rule prescribes c at (ddd, ddc), (ddc, dcc), (dcc, ccc),

(ddc, ddd), (dcc, ddc), (ccc, dcc), (ddc, ddc), and (dcc, dcc).

* I: In all the other cases, defect.

The original implementation used in [[Murase2020]](index.html#murase2020) is available at

<https://github.com/yohm/sim_exhaustive_m3_PDgame>

Names:

* CAPRI: Original Name by Y. Murase et al. [[Murase2020]](index.html#murase2020)

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/grudger.html#Capri.strategy)[¶](#axelrod.strategies.grudger.Capri.strategy "Permalink to this definition")

This is a placeholder strategy.

*class* `axelrod.strategies.grudger.``EasyGo`[[source]](_modules/axelrod/strategies/grudger.html#EasyGo)[¶](#axelrod.strategies.grudger.EasyGo "Permalink to this definition")

A player starts by defecting however will cooperate if at any point the

opponent has defected.

Names:

* Easy Go: [[Prison1998]](index.html#prison1998)

* Reverse Grudger (RGRIM): [[Li2011]](index.html#li2011)

* Fool Me Forever: [[Harper2017]](index.html#harper2017)

*static* `strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/grudger.html#EasyGo.strategy)[¶](#axelrod.strategies.grudger.EasyGo.strategy "Permalink to this definition")

Begins by playing D, then plays C for the remaining rounds if the

opponent ever plays D.

*class* `axelrod.strategies.grudger.``ForgetfulGrudger`[[source]](_modules/axelrod/strategies/grudger.html#ForgetfulGrudger)[¶](#axelrod.strategies.grudger.ForgetfulGrudger "Permalink to this definition")

A player starts by cooperating however will defect if at any point the

opponent has defected, but forgets after mem\_length matches.

Names:

* Forgetful Grudger: Original name by Geraint Palmer

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/grudger.html#ForgetfulGrudger.strategy)[¶](#axelrod.strategies.grudger.ForgetfulGrudger.strategy "Permalink to this definition")

Begins by playing C, then plays D for mem\_length rounds if the

opponent ever plays D.

*class* `axelrod.strategies.grudger.``GeneralSoftGrudger`(*n: int = 1*, *d: int = 4*, *c: int = 2*)[[source]](_modules/axelrod/strategies/grudger.html#GeneralSoftGrudger)[¶](#axelrod.strategies.grudger.GeneralSoftGrudger "Permalink to this definition")

A generalization of the SoftGrudger strategy. SoftGrudger punishes by

playing: D, D, D, D, C, C. after a defection by the opponent.

GeneralSoftGrudger only punishes after its opponent defects a specified

amount of times consecutively. The punishment is in the form of a series of

defections followed by a ‘penance’ of a series of consecutive cooperations.

Names:

* General Soft Grudger: Original Name by J. Taylor Smith

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/grudger.html#GeneralSoftGrudger.strategy)[¶](#axelrod.strategies.grudger.GeneralSoftGrudger.strategy "Permalink to this definition")

Punishes after its opponent defects ‘n’ times consecutively.

The punishment is in the form of ‘d’ defections followed by a penance of

‘c’ consecutive cooperations.

*class* `axelrod.strategies.grudger.``Grudger`[[source]](_modules/axelrod/strategies/grudger.html#Grudger)[¶](#axelrod.strategies.grudger.Grudger "Permalink to this definition")

A player starts by cooperating however will defect if at any point the

opponent has defected.

This strategy came 7th in Axelrod’s original tournament.

Names:

* Friedman’s strategy: [[Axelrod1980]](index.html#axelrod1980)

* Grudger: [[Li2011]](index.html#li2011)

* Grim: [[Berg2015]](index.html#berg2015)

* Grim Trigger: [[Banks1990]](index.html#banks1990)

* Spite: [[Beaufils1997]](index.html#beaufils1997)

* Spiteful: [[Mathieu2015]](index.html#mathieu2015)

* Vengeful: [[Ashlock2009]](index.html#ashlock2009)

*static* `strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/grudger.html#Grudger.strategy)[¶](#axelrod.strategies.grudger.Grudger.strategy "Permalink to this definition")

Begins by playing C, then plays D for the remaining rounds if the

opponent ever plays D.

*class* `axelrod.strategies.grudger.``GrudgerAlternator`[[source]](_modules/axelrod/strategies/grudger.html#GrudgerAlternator)[¶](#axelrod.strategies.grudger.GrudgerAlternator "Permalink to this definition")

A player starts by cooperating until the first opponents defection,

then alternates D-C.

Names:

* c\_then\_per\_dc: [[Prison1998]](index.html#prison1998)

* Grudger Alternator: Original name by Geraint Palmer

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/grudger.html#GrudgerAlternator.strategy)[¶](#axelrod.strategies.grudger.GrudgerAlternator.strategy "Permalink to this definition")

Begins by playing C, then plays Alternator for the remaining rounds

if the opponent ever plays D.

*class* `axelrod.strategies.grudger.``OppositeGrudger`[[source]](_modules/axelrod/strategies/grudger.html#OppositeGrudger)[¶](#axelrod.strategies.grudger.OppositeGrudger "Permalink to this definition")

A player starts by defecting however will cooperate if at any point the

opponent has cooperated.

Names:

* Opposite Grudger: Original name by Geraint Palmer

*static* `strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/grudger.html#OppositeGrudger.strategy)[¶](#axelrod.strategies.grudger.OppositeGrudger.strategy "Permalink to this definition")

Begins by playing D, then plays C for the remaining rounds if the

opponent ever plays C.

*class* `axelrod.strategies.grudger.``SoftGrudger`[[source]](_modules/axelrod/strategies/grudger.html#SoftGrudger)[¶](#axelrod.strategies.grudger.SoftGrudger "Permalink to this definition")

A modification of the Grudger strategy. Instead of punishing by always

defecting: punishes by playing: D, D, D, D, C, C. (Will continue to

cooperate afterwards).

* Soft Grudger (SGRIM): [[Li2011]](index.html#li2011)

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/grudger.html#SoftGrudger.strategy)[¶](#axelrod.strategies.grudger.SoftGrudger.strategy "Permalink to this definition")

Begins by playing C, then plays D, D, D, D, C, C against a defection

*class* `axelrod.strategies.grudger.``SpitefulCC`[[source]](_modules/axelrod/strategies/grudger.html#SpitefulCC)[¶](#axelrod.strategies.grudger.SpitefulCC "Permalink to this definition")

Behaves like Grudger after cooperating for 2 turns

Names:

* spiteful\_cc: [[Mathieu2015]](index.html#mathieu2015)

*static* `strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/grudger.html#SpitefulCC.strategy)[¶](#axelrod.strategies.grudger.SpitefulCC.strategy "Permalink to this definition")

Cooperates until the opponent defects. Then defects forever.

Always cooperates twice at the start.

*class* `axelrod.strategies.grumpy.``Grumpy`(*starting\_state: str = 'Nice'*, *grumpy\_threshold: int = 10*, *nice\_threshold: int = -10*)[[source]](_modules/axelrod/strategies/grumpy.html#Grumpy)[¶](#axelrod.strategies.grumpy.Grumpy "Permalink to this definition")

A player that defects after a certain level of grumpiness.

Grumpiness increases when the opponent defects and decreases

when the opponent co-operates.

Names:

* Grumpy: Original name by Jason Young

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/grumpy.html#Grumpy.strategy)[¶](#axelrod.strategies.grumpy.Grumpy.strategy "Permalink to this definition")

A player that gets grumpier the more the opposition defects,

and nicer the more they cooperate.

Starts off Nice, but becomes grumpy once the grumpiness threshold is

hit. Won’t become nice once that grumpy threshold is hit, but must

reach a much lower threshold before it becomes nice again.

*class* `axelrod.strategies.handshake.``Handshake`(*initial\_plays: List[axelrod.action.Action] = None*)[[source]](_modules/axelrod/strategies/handshake.html#Handshake)[¶](#axelrod.strategies.handshake.Handshake "Permalink to this definition")

Starts with C, D. If the opponent plays the same way, cooperate forever,

else defect forever.

Names:

* Handshake: [[Robson1990]](index.html#robson1990)

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/handshake.html#Handshake.strategy)[¶](#axelrod.strategies.handshake.Handshake.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.hmm.``EvolvableHMMPlayer`(*transitions\_C=None*, *transitions\_D=None*, *emission\_probabilities=None*, *initial\_state=0*, *initial\_action=C*, *num\_states=None*, *mutation\_probability=None*, *seed: int = None*)[[source]](_modules/axelrod/strategies/hmm.html#EvolvableHMMPlayer)[¶](#axelrod.strategies.hmm.EvolvableHMMPlayer "Permalink to this definition")

Evolvable version of HMMPlayer.

`create_vector_bounds`()[[source]](_modules/axelrod/strategies/hmm.html#EvolvableHMMPlayer.create_vector_bounds)[¶](#axelrod.strategies.hmm.EvolvableHMMPlayer.create_vector_bounds "Permalink to this definition")

Creates the bounds for the decision variables.

`crossover`(*other*)[[source]](_modules/axelrod/strategies/hmm.html#EvolvableHMMPlayer.crossover)[¶](#axelrod.strategies.hmm.EvolvableHMMPlayer.crossover "Permalink to this definition")

Optional method to allow Player to produce variants in combination with another player. Returns a new

Player.

`mutate`()[[source]](_modules/axelrod/strategies/hmm.html#EvolvableHMMPlayer.mutate)[¶](#axelrod.strategies.hmm.EvolvableHMMPlayer.mutate "Permalink to this definition")

Optional method to allow Player to produce a variant (not in place).

`receive_vector`(*vector*)[[source]](_modules/axelrod/strategies/hmm.html#EvolvableHMMPlayer.receive_vector)[¶](#axelrod.strategies.hmm.EvolvableHMMPlayer.receive_vector "Permalink to this definition")

Read a serialized vector into the set of HMM parameters (less initial

state). Then assign those HMM parameters to this class instance.

Assert that the vector has the right number of elements for an HMMParams

class with self.num\_states.

Assume the first num\_states^2 entries are the transitions\_C matrix. The

next num\_states^2 entries are the transitions\_D matrix. Then the next

num\_states entries are the emission\_probabilities vector. Finally the last

entry is the initial\_action.

*class* `axelrod.strategies.hmm.``EvolvedHMM5`[[source]](_modules/axelrod/strategies/hmm.html#EvolvedHMM5)[¶](#axelrod.strategies.hmm.EvolvedHMM5 "Permalink to this definition")

An HMM-based player with five hidden states trained with an evolutionary

algorithm.

Names:

> 

> * Evolved HMM 5: Original name by Marc Harper

> 

> 

> 

*class* `axelrod.strategies.hmm.``HMMPlayer`(*transitions\_C=None*, *transitions\_D=None*, *emission\_probabilities=None*, *initial\_state=0*, *initial\_action=C*)[[source]](_modules/axelrod/strategies/hmm.html#HMMPlayer)[¶](#axelrod.strategies.hmm.HMMPlayer "Permalink to this definition")

Abstract base class for Hidden Markov Model players.

Names

> 

> * HMM Player: Original name by Marc Harper

> 

> 

> 

`is_stochastic`() → bool[[source]](_modules/axelrod/strategies/hmm.html#HMMPlayer.is_stochastic)[¶](#axelrod.strategies.hmm.HMMPlayer.is_stochastic "Permalink to this definition")

Determines if the player is stochastic.

`set_seed`(*seed=None*)[[source]](_modules/axelrod/strategies/hmm.html#HMMPlayer.set_seed)[¶](#axelrod.strategies.hmm.HMMPlayer.set_seed "Permalink to this definition")

Set a random seed for the player’s random number generator.

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/hmm.html#HMMPlayer.strategy)[¶](#axelrod.strategies.hmm.HMMPlayer.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.hmm.``SimpleHMM`(*transitions\_C*, *transitions\_D*, *emission\_probabilities*, *initial\_state*)[[source]](_modules/axelrod/strategies/hmm.html#SimpleHMM)[¶](#axelrod.strategies.hmm.SimpleHMM "Permalink to this definition")

Implementation of a basic Hidden Markov Model. We assume that the

transition matrix is conditioned on the opponent’s last action, so there

are two transition matrices. Emission distributions are stored as Bernoulli

probabilities for each state. This is essentially a stochastic FSM.

<https://en.wikipedia.org/wiki/Hidden_Markov_model>

`is_well_formed`() → bool[[source]](_modules/axelrod/strategies/hmm.html#SimpleHMM.is_well_formed)[¶](#axelrod.strategies.hmm.SimpleHMM.is_well_formed "Permalink to this definition")

Determines if the HMM parameters are well-formed:

* Both matrices are stochastic

* Emissions probabilities are in [0, 1]

* The initial state is valid.

`move`(*opponent\_action: axelrod.action.Action*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/hmm.html#SimpleHMM.move)[¶](#axelrod.strategies.hmm.SimpleHMM.move "Permalink to this definition")

Changes state and computes the response action.

Parameters

opponent\_action: Axelrod.Action

The opponent’s last action.

`axelrod.strategies.hmm.``is_stochastic_matrix`(*m*, *ep=1e-08*) → bool[[source]](_modules/axelrod/strategies/hmm.html#is_stochastic_matrix)[¶](#axelrod.strategies.hmm.is_stochastic_matrix "Permalink to this definition")

Checks that the matrix m (a list of lists) is a stochastic matrix.

`axelrod.strategies.hmm.``mutate_row`(*row*, *mutation\_probability*, *rng*)[[source]](_modules/axelrod/strategies/hmm.html#mutate_row)[¶](#axelrod.strategies.hmm.mutate_row "Permalink to this definition")

, crossover\_lists\_of\_lists

Given a row of probabilities, randomly change each entry with probability

mutation\_probability (a value between 0 and 1). If changing, then change

by a value randomly (uniformly) chosen from [-0.25, 0.25] bounded by 0 and

100%.

*class* `axelrod.strategies.hunter.``AlternatorHunter`[[source]](_modules/axelrod/strategies/hunter.html#AlternatorHunter)[¶](#axelrod.strategies.hunter.AlternatorHunter "Permalink to this definition")

A player who hunts for alternators.

Names:

* Alternator Hunter: Original name by Karol Langner

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/hunter.html#AlternatorHunter.strategy)[¶](#axelrod.strategies.hunter.AlternatorHunter.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.hunter.``CooperatorHunter`[[source]](_modules/axelrod/strategies/hunter.html#CooperatorHunter)[¶](#axelrod.strategies.hunter.CooperatorHunter "Permalink to this definition")

A player who hunts for cooperators.

Names:

* Cooperator Hunter: Original name by Karol Langner

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/hunter.html#CooperatorHunter.strategy)[¶](#axelrod.strategies.hunter.CooperatorHunter.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.hunter.``CycleHunter`[[source]](_modules/axelrod/strategies/hunter.html#CycleHunter)[¶](#axelrod.strategies.hunter.CycleHunter "Permalink to this definition")

Hunts strategies that play cyclically, like any of the Cyclers,

Alternator, etc.

Names:

* Cycle Hunter: Original name by Marc Harper

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/hunter.html#CycleHunter.strategy)[¶](#axelrod.strategies.hunter.CycleHunter.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.hunter.``DefectorHunter`[[source]](_modules/axelrod/strategies/hunter.html#DefectorHunter)[¶](#axelrod.strategies.hunter.DefectorHunter "Permalink to this definition")

A player who hunts for defectors.

Names:

* Defector Hunter: Original name by Karol Langner

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/hunter.html#DefectorHunter.strategy)[¶](#axelrod.strategies.hunter.DefectorHunter.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.hunter.``EventualCycleHunter`[[source]](_modules/axelrod/strategies/hunter.html#EventualCycleHunter)[¶](#axelrod.strategies.hunter.EventualCycleHunter "Permalink to this definition")

Hunts strategies that eventually play cyclically.

Names:

* Eventual Cycle Hunter: Original name by Marc Harper

`strategy`(*opponent: axelrod.player.Player*) → None[[source]](_modules/axelrod/strategies/hunter.html#EventualCycleHunter.strategy)[¶](#axelrod.strategies.hunter.EventualCycleHunter.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.hunter.``MathConstantHunter`[[source]](_modules/axelrod/strategies/hunter.html#MathConstantHunter)[¶](#axelrod.strategies.hunter.MathConstantHunter "Permalink to this definition")

A player who hunts for mathematical constant players.

Names:

Math Constant Hunter: Original name by Karol Langner

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/hunter.html#MathConstantHunter.strategy)[¶](#axelrod.strategies.hunter.MathConstantHunter.strategy "Permalink to this definition")

Check whether the number of cooperations in the first and second halves

of the history are close. The variance of the uniform distribution (1/4)

is a reasonable delta but use something lower for certainty and avoiding

false positives. This approach will also detect a lot of random players.

*class* `axelrod.strategies.hunter.``RandomHunter`[[source]](_modules/axelrod/strategies/hunter.html#RandomHunter)[¶](#axelrod.strategies.hunter.RandomHunter "Permalink to this definition")

A player who hunts for random players.

Names:

* Random Hunter: Original name by Karol Langner

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/hunter.html#RandomHunter.strategy)[¶](#axelrod.strategies.hunter.RandomHunter.strategy "Permalink to this definition")

A random player is unpredictable, which means the conditional frequency

of cooperation after cooperation, and defection after defections, should

be close to 50%… although how close is debatable.

*class* `axelrod.strategies.inverse.``Inverse`[[source]](_modules/axelrod/strategies/inverse.html#Inverse)[¶](#axelrod.strategies.inverse.Inverse "Permalink to this definition")

A player who defects with a probability that diminishes relative to how

long ago the opponent defected.

Names:

* Inverse: Original Name by Karol Langner

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/inverse.html#Inverse.strategy)[¶](#axelrod.strategies.inverse.Inverse.strategy "Permalink to this definition")

Looks at opponent history to see if they have defected.

If so, player defection is inversely proportional to when this occurred.

*class* `axelrod.strategies.lookerup.``EvolvableLookerUp`(*lookup\_dict: dict = None*, *initial\_actions: tuple = None*, *pattern: Any = None*, *parameters: axelrod.strategies.lookerup.Plays = None*, *mutation\_probability: float = None*, *seed: int = None*)[[source]](_modules/axelrod/strategies/lookerup.html#EvolvableLookerUp)[¶](#axelrod.strategies.lookerup.EvolvableLookerUp "Permalink to this definition")

`crossover`(*other*)[[source]](_modules/axelrod/strategies/lookerup.html#EvolvableLookerUp.crossover)[¶](#axelrod.strategies.lookerup.EvolvableLookerUp.crossover "Permalink to this definition")

Optional method to allow Player to produce variants in combination with another player. Returns a new

Player.

`mutate`()[[source]](_modules/axelrod/strategies/lookerup.html#EvolvableLookerUp.mutate)[¶](#axelrod.strategies.lookerup.EvolvableLookerUp.mutate "Permalink to this definition")

Optional method to allow Player to produce a variant (not in place).

*class* `axelrod.strategies.lookerup.``EvolvedLookerUp1_1_1`[[source]](_modules/axelrod/strategies/lookerup.html#EvolvedLookerUp1_1_1)[¶](#axelrod.strategies.lookerup.EvolvedLookerUp1_1_1 "Permalink to this definition")

A 1 1 1 Lookerup trained with an evolutionary algorithm.

Names:

* Evolved Lookerup 1 1 1: Original name by Marc Harper

*class* `axelrod.strategies.lookerup.``EvolvedLookerUp2_2_2`[[source]](_modules/axelrod/strategies/lookerup.html#EvolvedLookerUp2_2_2)[¶](#axelrod.strategies.lookerup.EvolvedLookerUp2_2_2 "Permalink to this definition")

A 2 2 2 Lookerup trained with an evolutionary algorithm.

Names:

* Evolved Lookerup 2 2 2: Original name by Marc Harper

*class* `axelrod.strategies.lookerup.``LookerUp`(*lookup\_dict: dict = None*, *initial\_actions: tuple = None*, *pattern: Any = None*, *parameters: axelrod.strategies.lookerup.Plays = None*)[[source]](_modules/axelrod/strategies/lookerup.html#LookerUp)[¶](#axelrod.strategies.lookerup.LookerUp "Permalink to this definition")

This strategy uses a LookupTable to decide its next action. If there is not

enough history to use the table, it calls from a list of

self.initial\_actions.

if self\_depth=2, op\_depth=3, op\_openings\_depth=5, LookerUp finds the last 2

plays of self, the last 3 plays of opponent and the opening 5 plays of

opponent. It then looks those up on the LookupTable and returns the

appropriate action. If 5 rounds have not been played (the minimum required

for op\_openings\_depth), it calls from self.initial\_actions.

LookerUp can be instantiated with a dictionary. The dictionary uses

tuple(tuple, tuple, tuple) or Plays as keys. for example.

* self\_plays: depth=2

* op\_plays: depth=1

* op\_openings: depth=0:

```

{Plays((C, C), (C), ()): C,

 Plays((C, C), (D), ()): D,

 Plays((C, D), (C), ()): D,  <- example below

 Plays((C, D), (D), ()): D,

 Plays((D, C), (C), ()): C,

 Plays((D, C), (D), ()): D,

 Plays((D, D), (C), ()): C,

 Plays((D, D), (D), ()): D}

```

From the above table, if the player last played C, D and the opponent last

played C (here the initial opponent play is ignored) then this round,

the player would play D.

The dictionary must contain all possible permutations of C’s and D’s.

LookerUp can also be instantiated with pattern=str/tuple of actions, and:

```

parameters=Plays(

    self\_plays=player\_depth: int,

    op\_plays=op\_depth: int,

    op\_openings=op\_openings\_depth: int)

```

It will create keys of len=2 \*\* (sum(parameters)) and map the pattern to

the keys.

initial\_actions is a tuple such as (C, C, D). A table needs initial actions

equal to max(self\_plays depth, opponent\_plays depth, opponent\_initial\_plays

depth). If provided initial\_actions is too long, the extra will be ignored.

If provided initial\_actions is too short, the shortfall will be made up

with C’s.

Some well-known strategies can be expressed as special cases; for example

Cooperator is given by the dict (All history is ignored and always play C):

```

{Plays((), (), ()) : C}

```

Tit-For-Tat is given by (The only history that is important is the

opponent’s last play.):

```

{Plays((), (D,), ()): D,

 Plays((), (C,), ()): C}

```

LookerUp’s LookupTable defaults to Tit-For-Tat. The initial\_actions

defaults to playing C.

Names:

* Lookerup: Original name by Martin Jones

`lookup_table_display`(*sort\_by: tuple = ('op\_openings'*, *'self\_plays'*, *'op\_plays')*) → str[[source]](_modules/axelrod/strategies/lookerup.html#LookerUp.lookup_table_display)[¶](#axelrod.strategies.lookerup.LookerUp.lookup_table_display "Permalink to this definition")

Returns a string for printing lookup\_table info in specified order.

| Parameters: | **sort\_by** – only\_elements=’self\_plays’, ‘op\_plays’, ‘op\_openings’ |

`strategy`(*opponent: axelrod.player.Player*) → Reaction[[source]](_modules/axelrod/strategies/lookerup.html#LookerUp.strategy)[¶](#axelrod.strategies.lookerup.LookerUp.strategy "Permalink to this definition")

This is a placeholder strategy.

*class* `axelrod.strategies.lookerup.``LookupTable`(*lookup\_dict: dict*)[[source]](_modules/axelrod/strategies/lookerup.html#LookupTable)[¶](#axelrod.strategies.lookerup.LookupTable "Permalink to this definition")

LookerUp and its children use this object to determine their next actions.

It is an object that creates a table of all possible plays to a specified

depth and the action to be returned for each combination of plays.

The “get” method returns the appropriate response.

For the table containing:

```

....

Plays(self\_plays=(C, C), op\_plays=(C, D), op\_openings=(D, C): D

Plays(self\_plays=(C, C), op\_plays=(C, D), op\_openings=(D, D): C

...

```

with:

player.history[-2:]=[C, C] and

opponent.history[-2:]=[C, D] and

opponent.history[:2]=[D, D],

calling LookupTable.get(plays=(C, C), op\_plays=(C, D), op\_openings=(D, D))

will return C.

Instantiate the table with a lookup\_dict. This is

{(self\_plays\_tuple, op\_plays\_tuple, op\_openings\_tuple): action, …}.

It must contain every possible

permutation with C’s and D’s of the above tuple. so:

```

good\_dict = {((C,), (C,), ()): C,

             ((C,), (D,), ()): C,

             ((D,), (C,), ()): D,

             ((D,), (D,), ()): C}

bad\_dict = {((C,), (C,), ()): C,

            ((C,), (D,), ()): C,

            ((D,), (C,), ()): D}

```

LookupTable.from\_pattern() creates an ordered list of keys for you and maps

the pattern to the keys.:

```

LookupTable.from\_pattern(pattern=(C, D, D, C),

    player\_depth=0, op\_depth=1, op\_openings\_depth=1

)

```

creates the dictionary:

```

{Plays(self\_plays=(), op\_plays=(C), op\_openings=(C)): C,

 Plays(self\_plays=(), op\_plays=(C), op\_openings=(D)): D,

 Plays(self\_plays=(), op\_plays=(D), op\_openings=(C)): D,

 Plays(self\_plays=(), op\_plays=(D), op\_openings=(D)): C,}

```

and then returns a LookupTable with that dictionary.

`display`(*sort\_by: tuple = ('op\_openings'*, *'self\_plays'*, *'op\_plays')*) → str[[source]](_modules/axelrod/strategies/lookerup.html#LookupTable.display)[¶](#axelrod.strategies.lookerup.LookupTable.display "Permalink to this definition")

Returns a string for printing lookup\_table info in specified order.

| Parameters: | **sort\_by** – only\_elements=’self\_plays’, ‘op\_plays’, ‘op\_openings’ |

*class* `axelrod.strategies.lookerup.``Plays`(*self\_plays*, *op\_plays*, *op\_openings*)[¶](#axelrod.strategies.lookerup.Plays "Permalink to this definition")

`op_openings`[¶](#axelrod.strategies.lookerup.Plays.op_openings "Permalink to this definition")

Alias for field number 2

`op_plays`[¶](#axelrod.strategies.lookerup.Plays.op_plays "Permalink to this definition")

Alias for field number 1

`self_plays`[¶](#axelrod.strategies.lookerup.Plays.self_plays "Permalink to this definition")

Alias for field number 0

*class* `axelrod.strategies.lookerup.``Winner12`[[source]](_modules/axelrod/strategies/lookerup.html#Winner12)[¶](#axelrod.strategies.lookerup.Winner12 "Permalink to this definition")

A lookup table based strategy.

Names:

* Winner12: [[Mathieu2015]](index.html#mathieu2015)

*class* `axelrod.strategies.lookerup.``Winner21`[[source]](_modules/axelrod/strategies/lookerup.html#Winner21)[¶](#axelrod.strategies.lookerup.Winner21 "Permalink to this definition")

A lookup table based strategy.

Names:

* Winner21: [[Mathieu2015]](index.html#mathieu2015)

`axelrod.strategies.lookerup.``create_lookup_table_keys`(*player\_depth: int*, *op\_depth: int*, *op\_openings\_depth: int*) → list[[source]](_modules/axelrod/strategies/lookerup.html#create_lookup_table_keys)[¶](#axelrod.strategies.lookerup.create_lookup_table_keys "Permalink to this definition")

Returns a list of Plays that has all possible permutations of C’s and

D’s for each specified depth. the list is in order,

C < D sorted by ((player\_tuple), (op\_tuple), (op\_openings\_tuple)).

create\_lookup\_keys(2, 1, 0) returns:

```

[Plays(self\_plays=(C, C), op\_plays=(C,), op\_openings=()),

 Plays(self\_plays=(C, C), op\_plays=(D,), op\_openings=()),

 Plays(self\_plays=(C, D), op\_plays=(C,), op\_openings=()),

 Plays(self\_plays=(C, D), op\_plays=(D,), op\_openings=()),

 Plays(self\_plays=(D, C), op\_plays=(C,), op\_openings=()),

 Plays(self\_plays=(D, C), op\_plays=(D,), op\_openings=()),

 Plays(self\_plays=(D, D), op\_plays=(C,), op\_openings=()),

 Plays(self\_plays=(D, D), op\_plays=(D,), op\_openings=())]

```

`axelrod.strategies.lookerup.``get_last_n_plays`(*player: axelrod.player.Player*, *depth: int*) → tuple[[source]](_modules/axelrod/strategies/lookerup.html#get_last_n_plays)[¶](#axelrod.strategies.lookerup.get_last_n_plays "Permalink to this definition")

Returns the last N plays of player as a tuple.

`axelrod.strategies.lookerup.``make_keys_into_plays`(*lookup\_table: dict*) → dict[[source]](_modules/axelrod/strategies/lookerup.html#make_keys_into_plays)[¶](#axelrod.strategies.lookerup.make_keys_into_plays "Permalink to this definition")

Returns a dict where all keys are Plays.

*class* `axelrod.strategies.mathematicalconstants.``CotoDeRatio`[[source]](_modules/axelrod/strategies/mathematicalconstants.html#CotoDeRatio)[¶](#axelrod.strategies.mathematicalconstants.CotoDeRatio "Permalink to this definition")

The player will always aim to bring the ratio of co-operations to

defections closer to the ratio as given in a sub class

Names:

* Co to Do Ratio: Original Name by Timothy Standen

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/mathematicalconstants.html#CotoDeRatio.strategy)[¶](#axelrod.strategies.mathematicalconstants.CotoDeRatio.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.mathematicalconstants.``Golden`[[source]](_modules/axelrod/strategies/mathematicalconstants.html#Golden)[¶](#axelrod.strategies.mathematicalconstants.Golden "Permalink to this definition")

The player will always aim to bring the ratio of co-operations to

defections closer to the golden mean

Names:

* Golden: Original Name by Timothy Standen

*class* `axelrod.strategies.mathematicalconstants.``Pi`[[source]](_modules/axelrod/strategies/mathematicalconstants.html#Pi)[¶](#axelrod.strategies.mathematicalconstants.Pi "Permalink to this definition")

The player will always aim to bring the ratio of co-operations to

defections closer to the pi

Names:

* Pi: Original Name by Timothy Standen

*class* `axelrod.strategies.mathematicalconstants.``e`[[source]](_modules/axelrod/strategies/mathematicalconstants.html#e)[¶](#axelrod.strategies.mathematicalconstants.e "Permalink to this definition")

The player will always aim to bring the ratio of co-operations to

defections closer to the e

Names:

* e: Original Name by Timothy Standen

Memory Two strategies.

*class* `axelrod.strategies.memorytwo.``AON2`[[source]](_modules/axelrod/strategies/memorytwo.html#AON2)[¶](#axelrod.strategies.memorytwo.AON2 "Permalink to this definition")

AON2 a memory two strategy introduced in [[Hilbe2017]](index.html#hilbe2017). It belongs to the

AONk (all-or-none) family of strategies. These strategies were designed to

satisfy the three following properties:

1. Mutually Cooperative. A strategy is mutually cooperative if there are

histories for which the strategy prescribes to cooperate, and if it continues

to cooperate after rounds with mutual cooperation (provided the last k actions

of the focal player were actually consistent).

2. Error correcting. A strategy is error correcting after at most k rounds if,

after any history, it generally takes a group of players at most k + 1 rounds

to re-establish mutual cooperation.

3. Retaliating. A strategy is retaliating for at least k rounds if, after

rounds in which the focal player cooperated while the coplayer defected,

the strategy responds by defecting the following k rounds.

In [[Hilbe2017]](index.html#hilbe2017) the following vectors are reported as “equivalent” to AON2

with their respective self-cooperation rate (note that these are not the same):

1. [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], self-cooperation

rate: 0.952

2. [1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], self-cooperation

rate: 0.951

3. [1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], self-cooperation

rate: 0.951

4. [1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1], self-cooperation

rate: 0.952

AON2 is implemented using vector 1 due its self-cooperation rate.

In essence it is a strategy that starts off by cooperating and will cooperate

again only after the states (CC, CC), (CD, CD), (DC, DC), (DD, DD).

Names:

* AON2: [[Hilbe2017]](index.html#hilbe2017)

*class* `axelrod.strategies.memorytwo.``DelayedAON1`[[source]](_modules/axelrod/strategies/memorytwo.html#DelayedAON1)[¶](#axelrod.strategies.memorytwo.DelayedAON1 "Permalink to this definition")

Delayed AON1 a memory two strategy also introduced in [[Hilbe2017]](index.html#hilbe2017) and belongs

to the AONk family. Note that AON1 is equivalent to Win Stay Lose Shift.

In [[Hilbe2017]](index.html#hilbe2017) the following vectors are reported as “equivalent” to Delayed

AON1 with their respective self-cooperation rate (note that these are not the

same):

1. [1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 1], self-cooperation

rate: 0.952

2. [1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1], self-cooperation

rate: 0.970

3. [1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1], self-cooperation

rate: 0.971

Delayed AON1 is implemented using vector 3 due its self-cooperation rate.

In essence it is a strategy that starts off by cooperating and will cooperate

again only after the states (CC, CC), (CD, CD), (CD, DD), (DD, CD),

(DC, DC) and (DD, DD).

Names:

* Delayed AON1: [[Hilbe2017]](index.html#hilbe2017)

*class* `axelrod.strategies.memorytwo.``MEM2`[[source]](_modules/axelrod/strategies/memorytwo.html#MEM2)[¶](#axelrod.strategies.memorytwo.MEM2 "Permalink to this definition")

A memory-two player that switches between TFT, TFTT, and ALLD.

Note that the reference claims that this is a memory two strategy but in

fact it is infinite memory. This is because the player plays as ALLD if

ALLD has ever been selected twice, which can only be known if the entire

history of play is accessible.

Names:

* MEM2: [[Li2014]](index.html#li2014)

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/memorytwo.html#MEM2.strategy)[¶](#axelrod.strategies.memorytwo.MEM2.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.memorytwo.``MemoryTwoPlayer`(*sixteen\_vector: Optional[Tuple[float*, *...]] = None*, *initial: Optional[Tuple[axelrod.action.Action*, *axelrod.action.Action]] = None*)[[source]](_modules/axelrod/strategies/memorytwo.html#MemoryTwoPlayer)[¶](#axelrod.strategies.memorytwo.MemoryTwoPlayer "Permalink to this definition")

Uses a sixteen-vector for strategies based on the 16 conditional probabilities

P(X | I,J,K,L) where X, I, J, K, L in [C, D] and I, J are the players last

two moves and K, L are the opponents last two moves. These conditional

probabilities are the following:

1. P(C|CC, CC)

2. P(C|CC, CD)

3. P(C|CC, DC)

4. P(C|CC, DD)

5. P(C|CD, CC)

6. P(C|CD, CD)

7. P(C|CD, DC)

8. P(C|CD, DD)

9. P(C|DC, CC)

10. P(C|DC, CD)

11. P(C|DC, DC)

12. P(C|DC, DD)

13. P(C|DD, CC)

14. P(C|DD, CD)

15. P(C|DD, DC)

16. P(C|DD, DD)

Cooperator is set as the default player if sixteen\_vector is not given.

Names

* Memory Two: [[Hilbe2017]](index.html#hilbe2017)

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/memorytwo.html#MemoryTwoPlayer.strategy)[¶](#axelrod.strategies.memorytwo.MemoryTwoPlayer.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

Memory One strategies. Note that there are Memory One strategies in other

files, including titfortat.py and zero\_determinant.py

*class* `axelrod.strategies.memoryone.``ALLCorALLD`[[source]](_modules/axelrod/strategies/memoryone.html#ALLCorALLD)[¶](#axelrod.strategies.memoryone.ALLCorALLD "Permalink to this definition")

This strategy is at the parameter extreme of the ZD strategies (phi = 0).

It simply repeats its last move, and so mimics ALLC or ALLD after round one.

If the tournament is noisy, there will be long runs of C and D.

For now starting choice is random of 0.6, but that was an arbitrary choice

at implementation time.

Names:

* ALLC or ALLD: Original name by Marc Harper

* Repeat: [[Akin2015]](index.html#akin2015)

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/memoryone.html#ALLCorALLD.strategy)[¶](#axelrod.strategies.memoryone.ALLCorALLD.strategy "Permalink to this definition")

This is a placeholder strategy.

*class* `axelrod.strategies.memoryone.``FirmButFair`[[source]](_modules/axelrod/strategies/memoryone.html#FirmButFair)[¶](#axelrod.strategies.memoryone.FirmButFair "Permalink to this definition")

A strategy that cooperates on the first move, and cooperates except after

receiving a sucker payoff.

Names:

* Firm But Fair: [[Frean1994]](index.html#frean1994)

*class* `axelrod.strategies.memoryone.``GTFT`(*p: float = None*)[[source]](_modules/axelrod/strategies/memoryone.html#GTFT)[¶](#axelrod.strategies.memoryone.GTFT "Permalink to this definition")

Generous Tit For Tat Strategy.

Names:

* Generous Tit For Tat: [[Nowak1993]](index.html#nowak1993)

* Naive peace maker: [[Gaudesi2016]](index.html#gaudesi2016)

* Soft Joss: [[Gaudesi2016]](index.html#gaudesi2016)

*class* `axelrod.strategies.memoryone.``MemoryOnePlayer`(*four\_vector: Tuple[float*, *float*, *float*, *float] = None*, *initial: axelrod.action.Action = C*)[[source]](_modules/axelrod/strategies/memoryone.html#MemoryOnePlayer)[¶](#axelrod.strategies.memoryone.MemoryOnePlayer "Permalink to this definition")

Uses a four-vector for strategies based on the last round of play,

(P(C|CC), P(C|CD), P(C|DC), P(C|DD)). Win-Stay Lose-Shift is set as

the default player if four\_vector is not given.

Intended to be used as an abstract base class or to at least be supplied

with a initializing four\_vector.

Names

* Memory One: [[Nowak1990]](index.html#nowak1990)

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/memoryone.html#MemoryOnePlayer.strategy)[¶](#axelrod.strategies.memoryone.MemoryOnePlayer.strategy "Permalink to this definition")

This is a placeholder strategy.

*class* `axelrod.strategies.memoryone.``ReactivePlayer`(*probabilities: Tuple[float, float]*)[[source]](_modules/axelrod/strategies/memoryone.html#ReactivePlayer)[¶](#axelrod.strategies.memoryone.ReactivePlayer "Permalink to this definition")

A generic reactive player. Defined by 2 probabilities conditional on the

opponent’s last move: P(C|C), P(C|D).

Names:

* Reactive: [[Nowak1989]](index.html#nowak1989)

*class* `axelrod.strategies.memoryone.``SoftJoss`(*q: float = 0.9*)[[source]](_modules/axelrod/strategies/memoryone.html#SoftJoss)[¶](#axelrod.strategies.memoryone.SoftJoss "Permalink to this definition")

Defects with probability 0.9 when the opponent defects, otherwise

emulates Tit-For-Tat.

Names:

* Soft Joss: [[Prison1998]](index.html#prison1998)

*class* `axelrod.strategies.memoryone.``StochasticCooperator`[[source]](_modules/axelrod/strategies/memoryone.html#StochasticCooperator)[¶](#axelrod.strategies.memoryone.StochasticCooperator "Permalink to this definition")

Stochastic Cooperator.

Names:

* Stochastic Cooperator: [[Adami2013]](index.html#adami2013)

*class* `axelrod.strategies.memoryone.``StochasticWSLS`(*ep: float = 0.05*)[[source]](_modules/axelrod/strategies/memoryone.html#StochasticWSLS)[¶](#axelrod.strategies.memoryone.StochasticWSLS "Permalink to this definition")

Stochastic WSLS, similar to Generous TFT. Note that this is not the same as

Stochastic WSLS described in [[Amaral2016]](index.html#amaral2016), that strategy is a modification

of WSLS that learns from the performance of other strategies.

Names:

* Stochastic WSLS: Original name by Marc Harper

*class* `axelrod.strategies.memoryone.``WinShiftLoseStay`(*initial: axelrod.action.Action = D*)[[source]](_modules/axelrod/strategies/memoryone.html#WinShiftLoseStay)[¶](#axelrod.strategies.memoryone.WinShiftLoseStay "Permalink to this definition")

Win-Shift Lose-Stay, also called Reverse Pavlov.

Names:

* WSLS: [[Li2011]](index.html#li2011)

*class* `axelrod.strategies.memoryone.``WinStayLoseShift`[[source]](_modules/axelrod/strategies/memoryone.html#WinStayLoseShift)[¶](#axelrod.strategies.memoryone.WinStayLoseShift "Permalink to this definition")

Win-Stay Lose-Shift, also called Pavlov.

Names:

* Win Stay Lose Shift: [[Nowak1993]](index.html#nowak1993)

* WSLS: [[Stewart2012]](index.html#stewart2012)

* Pavlov: [[Kraines1989]](index.html#kraines1989)

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/memoryone.html#WinStayLoseShift.strategy)[¶](#axelrod.strategies.memoryone.WinStayLoseShift.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.meta.``MemoryDecay`(*p\_memory\_delete: float = 0.1*, *p\_memory\_alter: float = 0.03*, *loss\_value: float = -2*, *gain\_value: float = 1*, *memory: list = None*, *start\_strategy: axelrod.player.Player = <class 'axelrod.strategies.titfortat.TitForTat'>*, *start\_strategy\_duration: int = 15*)[[source]](_modules/axelrod/strategies/meta.html#MemoryDecay)[¶](#axelrod.strategies.meta.MemoryDecay "Permalink to this definition")

A player utilizes the (default) Tit for Tat strategy for the first (default) 15 turns,

at the same time memorizing the opponent’s decisions. After the 15 turns have

passed, the player calculates a ‘net cooperation score’ (NCS) for their opponent,

weighing decisions to Cooperate as (default) 1, and to Defect as (default)

-2. If the opponent’s NCS is below 0, the player defects; otherwise,

they cooperate.

The player’s memories of the opponent’s decisions have a random chance to be

altered (i.e., a C decision becomes D or vice versa; default probability

is 0.03) or deleted (default probability is 0.1).

It is possible to pass a different axelrod player class to change the initial

player behavior.

Name: Memory Decay

`gain_loss_translate`()[[source]](_modules/axelrod/strategies/meta.html#MemoryDecay.gain_loss_translate)[¶](#axelrod.strategies.meta.MemoryDecay.gain_loss_translate "Permalink to this definition")

Translates the actions (D and C) to numeric values (loss\_value and

gain\_value).

`memory_alter`()[[source]](_modules/axelrod/strategies/meta.html#MemoryDecay.memory_alter)[¶](#axelrod.strategies.meta.MemoryDecay.memory_alter "Permalink to this definition")

Alters memory entry, i.e. puts C if there’s a D and vice versa.

`memory_delete`()[[source]](_modules/axelrod/strategies/meta.html#MemoryDecay.memory_delete)[¶](#axelrod.strategies.meta.MemoryDecay.memory_delete "Permalink to this definition")

Deletes memory entry.

`meta_strategy`(*results*, *opponent*)[[source]](_modules/axelrod/strategies/meta.html#MemoryDecay.meta_strategy)[¶](#axelrod.strategies.meta.MemoryDecay.meta_strategy "Permalink to this definition")

Determine the meta result based on results of all players.

Override this function in child classes.

*class* `axelrod.strategies.meta.``MetaHunter`[[source]](_modules/axelrod/strategies/meta.html#MetaHunter)[¶](#axelrod.strategies.meta.MetaHunter "Permalink to this definition")

A player who uses a selection of hunters.

Names

* Meta Hunter: Original name by Karol Langner

*static* `meta_strategy`(*results*, *opponent*)[[source]](_modules/axelrod/strategies/meta.html#MetaHunter.meta_strategy)[¶](#axelrod.strategies.meta.MetaHunter.meta_strategy "Permalink to this definition")

Determine the meta result based on results of all players.

Override this function in child classes.

*class* `axelrod.strategies.meta.``MetaHunterAggressive`(*team=None*)[[source]](_modules/axelrod/strategies/meta.html#MetaHunterAggressive)[¶](#axelrod.strategies.meta.MetaHunterAggressive "Permalink to this definition")

A player who uses a selection of hunters.

Names

* Meta Hunter Aggressive: Original name by Marc Harper

*static* `meta_strategy`(*results*, *opponent*)[[source]](_modules/axelrod/strategies/meta.html#MetaHunterAggressive.meta_strategy)[¶](#axelrod.strategies.meta.MetaHunterAggressive.meta_strategy "Permalink to this definition")

Determine the meta result based on results of all players.

Override this function in child classes.

*class* `axelrod.strategies.meta.``MetaMajority`(*team=None*)[[source]](_modules/axelrod/strategies/meta.html#MetaMajority)[¶](#axelrod.strategies.meta.MetaMajority "Permalink to this definition")

A player who goes by the majority vote of all other non-meta players.

Names:

* Meta Majority: Original name by Karol Langner

*static* `meta_strategy`(*results*, *opponent*)[[source]](_modules/axelrod/strategies/meta.html#MetaMajority.meta_strategy)[¶](#axelrod.strategies.meta.MetaMajority.meta_strategy "Permalink to this definition")

Determine the meta result based on results of all players.

Override this function in child classes.

*class* `axelrod.strategies.meta.``MetaMajorityFiniteMemory`[[source]](_modules/axelrod/strategies/meta.html#MetaMajorityFiniteMemory)[¶](#axelrod.strategies.meta.MetaMajorityFiniteMemory "Permalink to this definition")

MetaMajority with the team of Finite Memory Players

Names

* Meta Majority Finite Memory: Original name by Marc Harper

*class* `axelrod.strategies.meta.``MetaMajorityLongMemory`[[source]](_modules/axelrod/strategies/meta.html#MetaMajorityLongMemory)[¶](#axelrod.strategies.meta.MetaMajorityLongMemory "Permalink to this definition")

MetaMajority with the team of Long (infinite) Memory Players

Names

* Meta Majority Long Memory: Original name by Marc Harper

*class* `axelrod.strategies.meta.``MetaMajorityMemoryOne`[[source]](_modules/axelrod/strategies/meta.html#MetaMajorityMemoryOne)[¶](#axelrod.strategies.meta.MetaMajorityMemoryOne "Permalink to this definition")

MetaMajority with the team of Memory One players

Names

* Meta Majority Memory One: Original name by Marc Harper

*class* `axelrod.strategies.meta.``MetaMinority`(*team=None*)[[source]](_modules/axelrod/strategies/meta.html#MetaMinority)[¶](#axelrod.strategies.meta.MetaMinority "Permalink to this definition")

A player who goes by the minority vote of all other non-meta players.

Names:

* Meta Minority: Original name by Karol Langner

*static* `meta_strategy`(*results*, *opponent*)[[source]](_modules/axelrod/strategies/meta.html#MetaMinority.meta_strategy)[¶](#axelrod.strategies.meta.MetaMinority.meta_strategy "Permalink to this definition")

Determine the meta result based on results of all players.

Override this function in child classes.

*class* `axelrod.strategies.meta.``MetaMixer`(*team=None*, *distribution=None*)[[source]](_modules/axelrod/strategies/meta.html#MetaMixer)[¶](#axelrod.strategies.meta.MetaMixer "Permalink to this definition")

A player who randomly switches between a team of players.

If no distribution is passed then the player will uniformly choose between

sub players.

In essence this is creating a Mixed strategy.

Parameters

team : list of strategy classes, optional

Team of strategies that are to be randomly played

If none is passed will select the ordinary strategies.

distribution : list representing a probability distribution, optional

This gives the distribution from which to select the players.

If none is passed will select uniformly.

Names

* Meta Mixer: Original name by Vince Knight

`index_strategy`(*opponent*)[[source]](_modules/axelrod/strategies/meta.html#MetaMixer.index_strategy)[¶](#axelrod.strategies.meta.MetaMixer.index_strategy "Permalink to this definition")

When the team effectively has a single player, only use that strategy.

`meta_strategy`(*results*, *opponent*)[[source]](_modules/axelrod/strategies/meta.html#MetaMixer.meta_strategy)[¶](#axelrod.strategies.meta.MetaMixer.meta_strategy "Permalink to this definition")

Using the \_random.choice function to sample with weights.

*class* `axelrod.strategies.meta.``MetaPlayer`(*team=None*)[[source]](_modules/axelrod/strategies/meta.html#MetaPlayer)[¶](#axelrod.strategies.meta.MetaPlayer "Permalink to this definition")

A generic player that has its own team of players.

Names:

* Meta Player: Original name by Karol Langner

`meta_strategy`(*results*, *opponent*)[[source]](_modules/axelrod/strategies/meta.html#MetaPlayer.meta_strategy)[¶](#axelrod.strategies.meta.MetaPlayer.meta_strategy "Permalink to this definition")

Determine the meta result based on results of all players.

Override this function in child classes.

`set_seed`(*seed=None*)[[source]](_modules/axelrod/strategies/meta.html#MetaPlayer.set_seed)[¶](#axelrod.strategies.meta.MetaPlayer.set_seed "Permalink to this definition")

Set a random seed for the player’s random number generator.

`strategy`(*opponent*)[[source]](_modules/axelrod/strategies/meta.html#MetaPlayer.strategy)[¶](#axelrod.strategies.meta.MetaPlayer.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.meta.``MetaWinner`(*team=None*)[[source]](_modules/axelrod/strategies/meta.html#MetaWinner)[¶](#axelrod.strategies.meta.MetaWinner "Permalink to this definition")

A player who goes by the strategy of the current winner.

Names:

* Meta Winner: Original name by Karol Langner

`meta_strategy`(*results*, *opponent*)[[source]](_modules/axelrod/strategies/meta.html#MetaWinner.meta_strategy)[¶](#axelrod.strategies.meta.MetaWinner.meta_strategy "Permalink to this definition")

Determine the meta result based on results of all players.

Override this function in child classes.

*class* `axelrod.strategies.meta.``MetaWinnerDeterministic`[[source]](_modules/axelrod/strategies/meta.html#MetaWinnerDeterministic)[¶](#axelrod.strategies.meta.MetaWinnerDeterministic "Permalink to this definition")

Meta Winner with the team of Deterministic Players.

Names

* Meta Winner Deterministic: Original name by Marc Harper

*class* `axelrod.strategies.meta.``MetaWinnerEnsemble`(*team=None*)[[source]](_modules/axelrod/strategies/meta.html#MetaWinnerEnsemble)[¶](#axelrod.strategies.meta.MetaWinnerEnsemble "Permalink to this definition")

A variant of MetaWinner that chooses one of the top scoring strategies

at random against each opponent. Note this strategy is always stochastic

regardless of the team, if team larger than 1, and the players are distinct.

Names:

* Meta Winner Ensemble: Original name by Marc Harper

`meta_strategy`(*results*, *opponent*)[[source]](_modules/axelrod/strategies/meta.html#MetaWinnerEnsemble.meta_strategy)[¶](#axelrod.strategies.meta.MetaWinnerEnsemble.meta_strategy "Permalink to this definition")

Determine the meta result based on results of all players.

Override this function in child classes.

*class* `axelrod.strategies.meta.``MetaWinnerFiniteMemory`[[source]](_modules/axelrod/strategies/meta.html#MetaWinnerFiniteMemory)[¶](#axelrod.strategies.meta.MetaWinnerFiniteMemory "Permalink to this definition")

MetaWinner with the team of Finite Memory Players

Names

* Meta Winner Finite Memory: Original name by Marc Harper

*class* `axelrod.strategies.meta.``MetaWinnerLongMemory`[[source]](_modules/axelrod/strategies/meta.html#MetaWinnerLongMemory)[¶](#axelrod.strategies.meta.MetaWinnerLongMemory "Permalink to this definition")

MetaWinner with the team of Long (infinite) Memory Players

Names

* Meta Winner Long Memory: Original name by Marc Harper

*class* `axelrod.strategies.meta.``MetaWinnerMemoryOne`[[source]](_modules/axelrod/strategies/meta.html#MetaWinnerMemoryOne)[¶](#axelrod.strategies.meta.MetaWinnerMemoryOne "Permalink to this definition")

MetaWinner with the team of Memory One players

Names

* Meta Winner Memory Memory One: Original name by Marc Harper

*class* `axelrod.strategies.meta.``MetaWinnerStochastic`[[source]](_modules/axelrod/strategies/meta.html#MetaWinnerStochastic)[¶](#axelrod.strategies.meta.MetaWinnerStochastic "Permalink to this definition")

Meta Winner with the team of Stochastic Players.

Names

* Meta Winner Stochastic: Original name by Marc Harper

*class* `axelrod.strategies.meta.``NMWEDeterministic`[[source]](_modules/axelrod/strategies/meta.html#NMWEDeterministic)[¶](#axelrod.strategies.meta.NMWEDeterministic "Permalink to this definition")

Nice Meta Winner Ensemble with the team of Deterministic Players.

Names

* Nice Meta Winner Ensemble Deterministic: Original name by Marc Harper

*class* `axelrod.strategies.meta.``NMWEFiniteMemory`[[source]](_modules/axelrod/strategies/meta.html#NMWEFiniteMemory)[¶](#axelrod.strategies.meta.NMWEFiniteMemory "Permalink to this definition")

Nice Meta Winner Ensemble with the team of Finite Memory Players.

Names

* Nice Meta Winner Ensemble Finite Memory: Original name by Marc Harper

*class* `axelrod.strategies.meta.``NMWELongMemory`[[source]](_modules/axelrod/strategies/meta.html#NMWELongMemory)[¶](#axelrod.strategies.meta.NMWELongMemory "Permalink to this definition")

Nice Meta Winner Ensemble with the team of Long Memory Players.

Names

* Nice Meta Winner Ensemble Long Memory: Original name by Marc Harper

*class* `axelrod.strategies.meta.``NMWEMemoryOne`[[source]](_modules/axelrod/strategies/meta.html#NMWEMemoryOne)[¶](#axelrod.strategies.meta.NMWEMemoryOne "Permalink to this definition")

Nice Meta Winner Ensemble with the team of Memory One Players.

Names

* Nice Meta Winner Ensemble Memory One: Original name by Marc Harper

*class* `axelrod.strategies.meta.``NMWEStochastic`[[source]](_modules/axelrod/strategies/meta.html#NMWEStochastic)[¶](#axelrod.strategies.meta.NMWEStochastic "Permalink to this definition")

Nice Meta Winner Ensemble with the team of Stochastic Players.

Names

* Nice Meta Winner Ensemble Stochastic: Original name by Marc Harper

*class* `axelrod.strategies.meta.``NiceMetaWinner`(*team=None*)[¶](#axelrod.strategies.meta.NiceMetaWinner "Permalink to this definition")

A player who goes by the strategy of the current winner.

Names:

* Meta Winner: Original name by Karol Langner

`original_class`[¶](#axelrod.strategies.meta.NiceMetaWinner.original_class "Permalink to this definition")

alias of [`MetaWinner`](#axelrod.strategies.meta.MetaWinner "axelrod.strategies.meta.MetaWinner")

*class* `axelrod.strategies.meta.``NiceMetaWinnerEnsemble`(*team=None*)[¶](#axelrod.strategies.meta.NiceMetaWinnerEnsemble "Permalink to this definition")

A variant of MetaWinner that chooses one of the top scoring strategies

at random against each opponent. Note this strategy is always stochastic

regardless of the team, if team larger than 1, and the players are distinct.

Names:

* Meta Winner Ensemble: Original name by Marc Harper

`original_class`[¶](#axelrod.strategies.meta.NiceMetaWinnerEnsemble.original_class "Permalink to this definition")

alias of [`MetaWinnerEnsemble`](#axelrod.strategies.meta.MetaWinnerEnsemble "axelrod.strategies.meta.MetaWinnerEnsemble")

*class* `axelrod.strategies.mutual.``Desperate`[[source]](_modules/axelrod/strategies/mutual.html#Desperate)[¶](#axelrod.strategies.mutual.Desperate "Permalink to this definition")

A player that only cooperates after mutual defection.

Names:

* Desperate: [[Berg2015]](index.html#berg2015)

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/mutual.html#Desperate.strategy)[¶](#axelrod.strategies.mutual.Desperate.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.mutual.``Hopeless`[[source]](_modules/axelrod/strategies/mutual.html#Hopeless)[¶](#axelrod.strategies.mutual.Hopeless "Permalink to this definition")

A player that only defects after mutual cooperation.

Names:

* Hopeless: [[Berg2015]](index.html#berg2015)

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/mutual.html#Hopeless.strategy)[¶](#axelrod.strategies.mutual.Hopeless.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.mutual.``Willing`[[source]](_modules/axelrod/strategies/mutual.html#Willing)[¶](#axelrod.strategies.mutual.Willing "Permalink to this definition")

A player that only defects after mutual defection.

Names:

* Willing: [[Berg2015]](index.html#berg2015)

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/mutual.html#Willing.strategy)[¶](#axelrod.strategies.mutual.Willing.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.negation.``Negation`[[source]](_modules/axelrod/strategies/negation.html#Negation)[¶](#axelrod.strategies.negation.Negation "Permalink to this definition")

A player starts by cooperating or defecting randomly if it’s their first move,

then simply doing the opposite of the opponents last move thereafter.

Names:

* Negation: [[PD2017]](index.html#pd2017)

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/negation.html#Negation.strategy)[¶](#axelrod.strategies.negation.Negation.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.oncebitten.``FoolMeOnce`[[source]](_modules/axelrod/strategies/oncebitten.html#FoolMeOnce)[¶](#axelrod.strategies.oncebitten.FoolMeOnce "Permalink to this definition")

Forgives one D then retaliates forever on a second D.

Names:

* Fool me once: Original name by Marc Harper

*static* `strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/oncebitten.html#FoolMeOnce.strategy)[¶](#axelrod.strategies.oncebitten.FoolMeOnce.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.oncebitten.``ForgetfulFoolMeOnce`(*forget\_probability: float = 0.05*)[[source]](_modules/axelrod/strategies/oncebitten.html#ForgetfulFoolMeOnce)[¶](#axelrod.strategies.oncebitten.ForgetfulFoolMeOnce "Permalink to this definition")

Forgives one D then retaliates forever on a second D. Sometimes randomly

forgets the defection count, and so keeps a secondary count separate from

the standard count in Player.

Names:

* Forgetful Fool Me Once: Original name by Marc Harper

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/oncebitten.html#ForgetfulFoolMeOnce.strategy)[¶](#axelrod.strategies.oncebitten.ForgetfulFoolMeOnce.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.oncebitten.``OnceBitten`[[source]](_modules/axelrod/strategies/oncebitten.html#OnceBitten)[¶](#axelrod.strategies.oncebitten.OnceBitten "Permalink to this definition")

Cooperates once when the opponent defects, but if they defect twice in a row

defaults to forgetful grudger for 10 turns defecting.

Names:

* Once Bitten: Original name by Holly Marissa

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/oncebitten.html#OnceBitten.strategy)[¶](#axelrod.strategies.oncebitten.OnceBitten.strategy "Permalink to this definition")

Begins by playing C, then plays D for mem\_length rounds if the opponent

ever plays D twice in a row.

*class* `axelrod.strategies.prober.``CollectiveStrategy`[[source]](_modules/axelrod/strategies/prober.html#CollectiveStrategy)[¶](#axelrod.strategies.prober.CollectiveStrategy "Permalink to this definition")

Defined in [[Li2009]](index.html#li2009). ‘It always cooperates in the first move and defects

in the second move. If the opponent also cooperates in the first move and

defects in the second move, CS will cooperate until the opponent defects.

Otherwise, CS will always defect.’

Names:

* Collective Strategy: [[Li2009]](index.html#li2009)

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/prober.html#CollectiveStrategy.strategy)[¶](#axelrod.strategies.prober.CollectiveStrategy.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.prober.``Detective`(*initial\_actions: List[axelrod.action.Action] = None*)[[source]](_modules/axelrod/strategies/prober.html#Detective)[¶](#axelrod.strategies.prober.Detective "Permalink to this definition")

Starts with C, D, C, C, or with the given sequence of actions.

If the opponent defects at least once in the first fixed rounds,

play as TFT forever, else defect forever.

Names:

* Detective: [[NC2019]](index.html#nc2019)

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/prober.html#Detective.strategy)[¶](#axelrod.strategies.prober.Detective.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.prober.``HardProber`[[source]](_modules/axelrod/strategies/prober.html#HardProber)[¶](#axelrod.strategies.prober.HardProber "Permalink to this definition")

Plays D, D, C, C initially. Defects forever if opponent cooperated in moves

2 and 3. Otherwise plays TFT.

Names:

* Hard Prober: [[Prison1998]](index.html#prison1998)

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/prober.html#HardProber.strategy)[¶](#axelrod.strategies.prober.HardProber.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.prober.``NaiveProber`(*p: float = 0.1*)[[source]](_modules/axelrod/strategies/prober.html#NaiveProber)[¶](#axelrod.strategies.prober.NaiveProber "Permalink to this definition")

Like tit-for-tat, but it occasionally defects with a small probability.

Names:

* Naive Prober: [[Li2011]](index.html#li2011)

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/prober.html#NaiveProber.strategy)[¶](#axelrod.strategies.prober.NaiveProber.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.prober.``Prober`[[source]](_modules/axelrod/strategies/prober.html#Prober)[¶](#axelrod.strategies.prober.Prober "Permalink to this definition")

Plays D, C, C initially. Defects forever if opponent cooperated in moves 2

and 3. Otherwise plays TFT.

Names:

* Prober: [[Li2011]](index.html#li2011)

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/prober.html#Prober.strategy)[¶](#axelrod.strategies.prober.Prober.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.prober.``Prober2`[[source]](_modules/axelrod/strategies/prober.html#Prober2)[¶](#axelrod.strategies.prober.Prober2 "Permalink to this definition")

Plays D, C, C initially. Cooperates forever if opponent played D then C

in moves 2 and 3. Otherwise plays TFT.

Names:

* Prober 2: [[Prison1998]](index.html#prison1998)

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/prober.html#Prober2.strategy)[¶](#axelrod.strategies.prober.Prober2.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.prober.``Prober3`[[source]](_modules/axelrod/strategies/prober.html#Prober3)[¶](#axelrod.strategies.prober.Prober3 "Permalink to this definition")

Plays D, C initially. Defects forever if opponent played C in moves 2.

Otherwise plays TFT.

Names:

* Prober 3: [[Prison1998]](index.html#prison1998)

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/prober.html#Prober3.strategy)[¶](#axelrod.strategies.prober.Prober3.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.prober.``Prober4`[[source]](_modules/axelrod/strategies/prober.html#Prober4)[¶](#axelrod.strategies.prober.Prober4 "Permalink to this definition")

Plays C, C, D, C, D, D, D, C, C, D, C, D, C, C, D, C, D, D, C, D initially.

Counts retaliating and provocative defections of the opponent.

If the absolute difference between the counts is smaller or equal to 2,

defects forever.

Otherwise plays C for the next 5 turns and TFT for the rest of the game.

Names:

* Prober 4: [[Prison1998]](index.html#prison1998)

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/prober.html#Prober4.strategy)[¶](#axelrod.strategies.prober.Prober4.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.prober.``RemorsefulProber`(*p: float = 0.1*)[[source]](_modules/axelrod/strategies/prober.html#RemorsefulProber)[¶](#axelrod.strategies.prober.RemorsefulProber "Permalink to this definition")

Like Naive Prober, but it remembers if the opponent responds to a random

defection with a defection by being remorseful and cooperating.

For reference see: [[Li2011]](index.html#li2011). A more complete description is given in “The

Selfish Gene” (<https://books.google.co.uk/books?id=ekonDAAAQBAJ>):

“Remorseful Prober remembers whether it has just spontaneously defected, and

whether the result was prompt retaliation. If so, it ‘remorsefully’ allows

its opponent ‘one free hit’ without retaliating.”

Names:

* Remorseful Prober: [[Li2011]](index.html#li2011)

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/prober.html#RemorsefulProber.strategy)[¶](#axelrod.strategies.prober.RemorsefulProber.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.punisher.``InversePunisher`[[source]](_modules/axelrod/strategies/punisher.html#InversePunisher)[¶](#axelrod.strategies.punisher.InversePunisher "Permalink to this definition")

An inverted version of Punisher. The player starts by cooperating however

will defect if at any point the opponent has defected, and forgets after

mem\_length matches, with 1 <= mem\_length <= 20. This time mem\_length is

proportional to the amount of time the opponent has played C.

Names:

* Inverse Punisher: Original name by Geraint Palmer

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/punisher.html#InversePunisher.strategy)[¶](#axelrod.strategies.punisher.InversePunisher.strategy "Permalink to this definition")

Begins by playing C, then plays D for an amount of rounds proportional

to the opponents historical ‘%’ of playing C if the opponent ever plays

D.

*class* `axelrod.strategies.punisher.``LevelPunisher`[[source]](_modules/axelrod/strategies/punisher.html#LevelPunisher)[¶](#axelrod.strategies.punisher.LevelPunisher "Permalink to this definition")

A player starts by cooperating however, after 10 rounds

will defect if at any point the number of defections

by an opponent is greater than 20%.

Names:

* Level Punisher: [[Eckhart2015]](index.html#eckhart2015)

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/punisher.html#LevelPunisher.strategy)[¶](#axelrod.strategies.punisher.LevelPunisher.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.punisher.``Punisher`[[source]](_modules/axelrod/strategies/punisher.html#Punisher)[¶](#axelrod.strategies.punisher.Punisher "Permalink to this definition")

A player starts by cooperating however will defect if at any point the

opponent has defected, but forgets after meme\_length matches, with

1<=mem\_length<=20 proportional to the amount of time the opponent has

played D, punishing that player for playing D too often.

Names:

* Punisher: Original name by Geraint Palmer

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/punisher.html#Punisher.strategy)[¶](#axelrod.strategies.punisher.Punisher.strategy "Permalink to this definition")

Begins by playing C, then plays D for an amount of rounds proportional

to the opponents historical ‘%’ of playing D if the opponent ever

plays D

*class* `axelrod.strategies.punisher.``TrickyLevelPunisher`[[source]](_modules/axelrod/strategies/punisher.html#TrickyLevelPunisher)[¶](#axelrod.strategies.punisher.TrickyLevelPunisher "Permalink to this definition")

A player starts by cooperating however, after 10, 50 and 100 rounds

will defect if at any point the percentage of defections

by an opponent is greater than 20%, 10% and 5% respectively.

Names:

* Tricky Level Punisher: [[Eckhart2015]](index.html#eckhart2015)

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/punisher.html#TrickyLevelPunisher.strategy)[¶](#axelrod.strategies.punisher.TrickyLevelPunisher.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.qlearner.``ArrogantQLearner`[[source]](_modules/axelrod/strategies/qlearner.html#ArrogantQLearner)[¶](#axelrod.strategies.qlearner.ArrogantQLearner "Permalink to this definition")

A player who learns the best strategies through the q-learning

algorithm.

This Q learner jumps to quick conclusions and cares about the future.

Names:

* Arrogant Q Learner: Original name by Geraint Palmer

*class* `axelrod.strategies.qlearner.``CautiousQLearner`[[source]](_modules/axelrod/strategies/qlearner.html#CautiousQLearner)[¶](#axelrod.strategies.qlearner.CautiousQLearner "Permalink to this definition")

A player who learns the best strategies through the q-learning algorithm.

This Q learner is slower to come to conclusions and wants to look ahead

more.

Names:

* Cautious Q Learner: Original name by Geraint Palmer

*class* `axelrod.strategies.qlearner.``HesitantQLearner`[[source]](_modules/axelrod/strategies/qlearner.html#HesitantQLearner)[¶](#axelrod.strategies.qlearner.HesitantQLearner "Permalink to this definition")

A player who learns the best strategies through the q-learning algorithm.

This Q learner is slower to come to conclusions and does not look ahead much.

Names:

* Hesitant Q Learner: Original name by Geraint Palmer

*class* `axelrod.strategies.qlearner.``RiskyQLearner`[[source]](_modules/axelrod/strategies/qlearner.html#RiskyQLearner)[¶](#axelrod.strategies.qlearner.RiskyQLearner "Permalink to this definition")

A player who learns the best strategies through the q-learning

algorithm.

This Q learner is quick to come to conclusions and doesn’t care about the

future.

Names:

* Risky Q Learner: Original name by Geraint Palmer

`find_reward`(*opponent: axelrod.player.Player*) → Dict[axelrod.action.Action, Dict[axelrod.action.Action, Union[int, float]]][[source]](_modules/axelrod/strategies/qlearner.html#RiskyQLearner.find_reward)[¶](#axelrod.strategies.qlearner.RiskyQLearner.find_reward "Permalink to this definition")

Finds the reward gained on the last iteration

`find_state`(*opponent: axelrod.player.Player*) → str[[source]](_modules/axelrod/strategies/qlearner.html#RiskyQLearner.find_state)[¶](#axelrod.strategies.qlearner.RiskyQLearner.find_state "Permalink to this definition")

Finds the my\_state (the opponents last n moves +

its previous proportion of playing C) as a hashable state

`perform_q_learning`(*prev\_state: str*, *state: str*, *action: axelrod.action.Action*, *reward*)[[source]](_modules/axelrod/strategies/qlearner.html#RiskyQLearner.perform_q_learning)[¶](#axelrod.strategies.qlearner.RiskyQLearner.perform_q_learning "Permalink to this definition")

Performs the qlearning algorithm

`select_action`(*state: str*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/qlearner.html#RiskyQLearner.select_action)[¶](#axelrod.strategies.qlearner.RiskyQLearner.select_action "Permalink to this definition")

Selects the action based on the epsilon-soft policy

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/qlearner.html#RiskyQLearner.strategy)[¶](#axelrod.strategies.qlearner.RiskyQLearner.strategy "Permalink to this definition")

Runs a qlearn algorithm while the tournament is running.

*class* `axelrod.strategies.rand.``Random`(*p: float = 0.5*)[[source]](_modules/axelrod/strategies/rand.html#Random)[¶](#axelrod.strategies.rand.Random "Permalink to this definition")

A player who randomly chooses between cooperating and defecting.

This strategy came 15th in Axelrod’s original tournament.

Names:

* Random: [[Axelrod1980]](index.html#axelrod1980)

* Lunatic: [[Tzafestas2000]](index.html#tzafestas2000)

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/rand.html#Random.strategy)[¶](#axelrod.strategies.rand.Random.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.resurrection.``DoubleResurrection`[[source]](_modules/axelrod/strategies/resurrection.html#DoubleResurrection)[¶](#axelrod.strategies.resurrection.DoubleResurrection "Permalink to this definition")

A player starts by cooperating and defects if the number of rounds

played by the player is greater than five and the last five rounds

are cooperations.

If the last five rounds were defections, the player cooperates.

Names:

* DoubleResurrection: [[Eckhart2015]](index.html#eckhart2015)

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/resurrection.html#DoubleResurrection.strategy)[¶](#axelrod.strategies.resurrection.DoubleResurrection.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.resurrection.``Resurrection`[[source]](_modules/axelrod/strategies/resurrection.html#Resurrection)[¶](#axelrod.strategies.resurrection.Resurrection "Permalink to this definition")

A player starts by cooperating and defects if the number of rounds

played by the player is greater than five and the last five rounds

are defections.

Otherwise, the strategy plays like Tit-for-tat.

Names:

* Resurrection: [[Eckhart2015]](index.html#eckhart2015)

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/resurrection.html#Resurrection.strategy)[¶](#axelrod.strategies.resurrection.Resurrection.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.retaliate.``LimitedRetaliate`(*retaliation\_threshold: float = 0.1*, *retaliation\_limit: int = 20*)[[source]](_modules/axelrod/strategies/retaliate.html#LimitedRetaliate)[¶](#axelrod.strategies.retaliate.LimitedRetaliate "Permalink to this definition")

A player that co-operates unless the opponent defects and wins.

It will then retaliate by defecting. It stops when either, it has beaten

the opponent 10 times more often that it has lost or it reaches the

retaliation limit (20 defections).

Names:

* Limited Retaliate: Original name by Owen Campbell

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/retaliate.html#LimitedRetaliate.strategy)[¶](#axelrod.strategies.retaliate.LimitedRetaliate.strategy "Permalink to this definition")

If the opponent has played D to my C more often than x% of the time

that I’ve done the same to him, retaliate by playing D but stop doing

so once I’ve hit the retaliation limit.

*class* `axelrod.strategies.retaliate.``LimitedRetaliate2`(*retaliation\_threshold: float = 0.08*, *retaliation\_limit: int = 15*)[[source]](_modules/axelrod/strategies/retaliate.html#LimitedRetaliate2)[¶](#axelrod.strategies.retaliate.LimitedRetaliate2 "Permalink to this definition")

LimitedRetaliate player with a threshold of 8 percent and a

retaliation limit of 15.

Names:

* Limited Retaliate 2: Original name by Owen Campbell

*class* `axelrod.strategies.retaliate.``LimitedRetaliate3`(*retaliation\_threshold: float = 0.05*, *retaliation\_limit: int = 20*)[[source]](_modules/axelrod/strategies/retaliate.html#LimitedRetaliate3)[¶](#axelrod.strategies.retaliate.LimitedRetaliate3 "Permalink to this definition")

LimitedRetaliate player with a threshold of 5 percent and a

retaliation limit of 20.

Names:

* Limited Retaliate 3: Original name by Owen Campbell

*class* `axelrod.strategies.retaliate.``Retaliate`(*retaliation\_threshold: float = 0.1*)[[source]](_modules/axelrod/strategies/retaliate.html#Retaliate)[¶](#axelrod.strategies.retaliate.Retaliate "Permalink to this definition")

A player starts by cooperating but will retaliate once the opponent

has won more than 10 percent times the number of defections the player has.

Names:

* Retaliate: Original name by Owen Campbell

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/retaliate.html#Retaliate.strategy)[¶](#axelrod.strategies.retaliate.Retaliate.strategy "Permalink to this definition")

If the opponent has played D to my C more often than x% of the time

that I’ve done the same to him, play D. Otherwise, play C.

*class* `axelrod.strategies.retaliate.``Retaliate2`(*retaliation\_threshold: float = 0.08*)[[source]](_modules/axelrod/strategies/retaliate.html#Retaliate2)[¶](#axelrod.strategies.retaliate.Retaliate2 "Permalink to this definition")

Retaliate player with a threshold of 8 percent.

Names:

* Retaliate 2: Original name by Owen Campbell

*class* `axelrod.strategies.retaliate.``Retaliate3`(*retaliation\_threshold: float = 0.05*)[[source]](_modules/axelrod/strategies/retaliate.html#Retaliate3)[¶](#axelrod.strategies.retaliate.Retaliate3 "Permalink to this definition")

Retaliate player with a threshold of 5 percent.

Names:

* Retaliate 3: Original name by Owen Campbell

Revised Downing implemented from the Fortran source code for the second of

Axelrod’s tournaments.

*class* `axelrod.strategies.revised_downing.``RevisedDowning`[[source]](_modules/axelrod/strategies/revised_downing.html#RevisedDowning)[¶](#axelrod.strategies.revised_downing.RevisedDowning "Permalink to this definition")

Strategy submitted to Axelrod’s second tournament by Leslie Downing.

(K59R).

Revised Downing attempts to determine if players are cooperative or not.

If so, it cooperates with them.

This strategy is a revision of the strategy submitted by Downing to

Axelrod’s first tournament.

Names:

- Revised Downing: [[Axelrod1980]](index.html#axelrod1980)

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/revised_downing.html#RevisedDowning.strategy)[¶](#axelrod.strategies.revised_downing.RevisedDowning.strategy "Permalink to this definition")

This is a placeholder strategy.

*class* `axelrod.strategies.sequence_player.``SequencePlayer`(*generator\_function: function*, *generator\_args: Tuple = ()*)[[source]](_modules/axelrod/strategies/sequence_player.html#SequencePlayer)[¶](#axelrod.strategies.sequence_player.SequencePlayer "Permalink to this definition")

Abstract base class for players that use a generated sequence to

determine their plays.

Names:

* Sequence Player: Original name by Marc Harper

*static* `meta_strategy`(*value: int*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/sequence_player.html#SequencePlayer.meta_strategy)[¶](#axelrod.strategies.sequence_player.SequencePlayer.meta_strategy "Permalink to this definition")

Determines how to map the sequence value to cooperate or defect.

By default, treat values like python truth values. Override in child

classes for alternate behaviors.

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/sequence_player.html#SequencePlayer.strategy)[¶](#axelrod.strategies.sequence_player.SequencePlayer.strategy "Permalink to this definition")

Iterate through the sequence and apply the meta strategy.

*class* `axelrod.strategies.sequence_player.``ThueMorse`[[source]](_modules/axelrod/strategies/sequence_player.html#ThueMorse)[¶](#axelrod.strategies.sequence_player.ThueMorse "Permalink to this definition")

A player who cooperates or defects according to the Thue-Morse sequence.

The first few terms of the Thue-Morse sequence are:

0 1 1 0 1 0 0 1 1 0 0 1 0 1 1 0 …

Thue-Morse sequence: <http://mathworld.wolfram.com/Thue-MorseSequence.html>

Names:

* Thue Morse: Original name by Geraint Palmer

*class* `axelrod.strategies.sequence_player.``ThueMorseInverse`[[source]](_modules/axelrod/strategies/sequence_player.html#ThueMorseInverse)[¶](#axelrod.strategies.sequence_player.ThueMorseInverse "Permalink to this definition")

A player who plays the inverse of the Thue-Morse sequence.

Names:

* Inverse Thue Morse: Original name by Geraint Palmer

*static* `meta_strategy`(*value: int*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/sequence_player.html#ThueMorseInverse.meta_strategy)[¶](#axelrod.strategies.sequence_player.ThueMorseInverse.meta_strategy "Permalink to this definition")

Determines how to map the sequence value to cooperate or defect.

By default, treat values like python truth values. Override in child

classes for alternate behaviors.

*class* `axelrod.strategies.shortmem.``ShortMem`[[source]](_modules/axelrod/strategies/shortmem.html#ShortMem)[¶](#axelrod.strategies.shortmem.ShortMem "Permalink to this definition")

A player starts by always cooperating for the first 10 moves.

From the tenth round on, the player analyzes the last ten actions, and

compare the number of defects and cooperates of the opponent, based in

percentage. If cooperation occurs 30% more than defection, it will

cooperate.

If defection occurs 30% more than cooperation, the program will defect.

Otherwise, the program follows the TitForTat algorithm.

Names:

* ShortMem: [[Andre2013]](index.html#andre2013)

*static* `strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/shortmem.html#ShortMem.strategy)[¶](#axelrod.strategies.shortmem.ShortMem.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.selfsteem.``SelfSteem`[[source]](_modules/axelrod/strategies/selfsteem.html#SelfSteem)[¶](#axelrod.strategies.selfsteem.SelfSteem "Permalink to this definition")

This strategy is based on the feeling with the same name.

It is modeled on the sine curve(f = sin( 2\* pi \* n / 10 )), which varies

with the current iteration.

If f > 0.95, ‘ego’ of the algorithm is inflated; always defects.

If 0.95 > abs(f) > 0.3, rational behavior; follows TitForTat algortithm.

If 0.3 > f > -0.3; random behavior.

If f < -0.95, algorithm is at rock bottom; always cooperates.

Futhermore, the algorithm implements a retaliation policy, if the opponent

defects; the sin curve is shifted. But due to lack of further information,

this implementation does not include a sin phase change.

Names:

* SelfSteem: [[Andre2013]](index.html#andre2013)

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/selfsteem.html#SelfSteem.strategy)[¶](#axelrod.strategies.selfsteem.SelfSteem.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.stalker.``Stalker`[[source]](_modules/axelrod/strategies/stalker.html#Stalker)[¶](#axelrod.strategies.stalker.Stalker "Permalink to this definition")

This is a strategy which is only influenced by the score.

Its behavior is based on three values:

the very\_bad\_score (all rounds in defection)

very\_good\_score (all rounds in cooperation)

wish\_score (average between bad and very\_good score)

It starts with cooperation.

* If current\_average\_score > very\_good\_score, it defects

* If current\_average\_score lies in (wish\_score, very\_good\_score) it

cooperates

* If current\_average\_score > 2, it cooperates

* If current\_average\_score lies in (1, 2)

* The remaining case, current\_average\_score < 1, it behaves randomly.

* It defects in the last round

Names:

* Stalker: [[Andre2013]](index.html#andre2013)

`original_class`[¶](#axelrod.strategies.stalker.Stalker.original_class "Permalink to this definition")

alias of [`Stalker`](#axelrod.strategies.stalker.Stalker "axelrod.strategies.stalker.Stalker")

*class* `axelrod.strategies.titfortat.``AdaptiveTitForTat`(*rate: float = 0.5*)[[source]](_modules/axelrod/strategies/titfortat.html#AdaptiveTitForTat)[¶](#axelrod.strategies.titfortat.AdaptiveTitForTat "Permalink to this definition")

ATFT - Adaptive Tit For Tat (Basic Model)

Algorithm

if (opponent played C in the last cycle) then

world = world + r\*(1-world)

else

world = world + r\*(0-world)

If (world >= 0.5) play C, else play D

Attributes

world : float [0.0, 1.0], set to 0.5

continuous variable representing the world’s image

1.0 - total cooperation

0.0 - total defection

other values - something in between of the above

updated every round, starting value shouldn’t matter as long as

it’s >= 0.5

Parameters

rate : float [0.0, 1.0], default=0.5

adaptation rate - r in Algorithm above

smaller value means more gradual and robust

to perturbations behaviour

Names:

* Adaptive Tit For Tat: [[Tzafestas2000]](index.html#tzafestas2000)

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/titfortat.html#AdaptiveTitForTat.strategy)[¶](#axelrod.strategies.titfortat.AdaptiveTitForTat.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.titfortat.``Alexei`[[source]](_modules/axelrod/strategies/titfortat.html#Alexei)[¶](#axelrod.strategies.titfortat.Alexei "Permalink to this definition")

Plays similar to Tit-for-Tat, but always defect on last turn.

Names:

* Alexei: [[LessWrong2011]](index.html#lesswrong2011)

`original_class`[¶](#axelrod.strategies.titfortat.Alexei.original_class "Permalink to this definition")

alias of [`Alexei`](#axelrod.strategies.titfortat.Alexei "axelrod.strategies.titfortat.Alexei")

*class* `axelrod.strategies.titfortat.``AntiTitForTat`[[source]](_modules/axelrod/strategies/titfortat.html#AntiTitForTat)[¶](#axelrod.strategies.titfortat.AntiTitForTat "Permalink to this definition")

A strategy that plays the opposite of the opponents previous move.

This is similar to Bully, except that the first move is cooperation.

Names:

* Anti Tit For Tat: [[Hilbe2013]](index.html#hilbe2013)

* Psycho (PSYC): [[Ashlock2009]](index.html#ashlock2009)

*static* `strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/titfortat.html#AntiTitForTat.strategy)[¶](#axelrod.strategies.titfortat.AntiTitForTat.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.titfortat.``Bully`[[source]](_modules/axelrod/strategies/titfortat.html#Bully)[¶](#axelrod.strategies.titfortat.Bully "Permalink to this definition")

A player that behaves opposite to Tit For Tat, including first move.

Starts by defecting and then does the opposite of opponent’s previous move.

This is the complete opposite of Tit For Tat, also called Bully in the

literature.

Names:

* Reverse Tit For Tat: [[Nachbar1992]](index.html#nachbar1992)

*static* `strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/titfortat.html#Bully.strategy)[¶](#axelrod.strategies.titfortat.Bully.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.titfortat.``BurnBothEnds`[[source]](_modules/axelrod/strategies/titfortat.html#BurnBothEnds)[¶](#axelrod.strategies.titfortat.BurnBothEnds "Permalink to this definition")

Plays like TitForTat except it cooperates after opponent cooperation with probability 9/10.

Names:

> 

> * BurnBothEnds (BBE): Marinoff [[Marinoff1992]](index.html#marinoff1992)

> 

> 

> 

`strategy`(*opponent*)[[source]](_modules/axelrod/strategies/titfortat.html#BurnBothEnds.strategy)[¶](#axelrod.strategies.titfortat.BurnBothEnds.strategy "Permalink to this definition")

This is a placeholder strategy.

*class* `axelrod.strategies.titfortat.``ContriteTitForTat`[[source]](_modules/axelrod/strategies/titfortat.html#ContriteTitForTat)[¶](#axelrod.strategies.titfortat.ContriteTitForTat "Permalink to this definition")

A player that corresponds to Tit For Tat if there is no noise. In the case

of a noisy match: if the opponent defects as a result of a noisy defection

then ContriteTitForTat will become ‘contrite’ until it successfully

cooperates.

Names:

* Contrite Tit For Tat: [[Axelrod1995]](index.html#axelrod1995)

`original_class`[¶](#axelrod.strategies.titfortat.ContriteTitForTat.original_class "Permalink to this definition")

alias of [`ContriteTitForTat`](#axelrod.strategies.titfortat.ContriteTitForTat "axelrod.strategies.titfortat.ContriteTitForTat")

*class* `axelrod.strategies.titfortat.``DynamicTwoTitsForTat`[[source]](_modules/axelrod/strategies/titfortat.html#DynamicTwoTitsForTat)[¶](#axelrod.strategies.titfortat.DynamicTwoTitsForTat "Permalink to this definition")

A player starts by cooperating and then punishes its opponent’s

defections with defections, but with a dynamic bias towards cooperating

based on the opponent’s ratio of cooperations to total moves

(so their current probability of cooperating regardless of the

opponent’s move (aka: forgiveness)).

Names:

> 

> * Dynamic Two Tits For Tat: Original name by Grant Garrett-Grossman.

> 

> 

> 

`strategy`(*opponent*)[[source]](_modules/axelrod/strategies/titfortat.html#DynamicTwoTitsForTat.strategy)[¶](#axelrod.strategies.titfortat.DynamicTwoTitsForTat.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.titfortat.``EugineNier`[[source]](_modules/axelrod/strategies/titfortat.html#EugineNier)[¶](#axelrod.strategies.titfortat.EugineNier "Permalink to this definition")

Plays similar to Tit-for-Tat, but with two conditions:

1) Always Defect on Last Move

2) If other player defects five times, switch to all defects.

Names:

* Eugine Nier: [[LessWrong2011]](index.html#lesswrong2011)

`original_class`[¶](#axelrod.strategies.titfortat.EugineNier.original_class "Permalink to this definition")

alias of [`EugineNier`](#axelrod.strategies.titfortat.EugineNier "axelrod.strategies.titfortat.EugineNier")

*class* `axelrod.strategies.titfortat.``Gradual`[[source]](_modules/axelrod/strategies/titfortat.html#Gradual)[¶](#axelrod.strategies.titfortat.Gradual "Permalink to this definition")

Similar to OriginalGradual, this is a player that punishes defections with a

growing number of defections but after punishing for punishment\_limit

number of times enters a calming state and cooperates no matter what the

opponent does for two rounds.

This version of Gradual is an update of OriginalGradual and the difference

is that the punishment\_limit is incremented whenever the opponent defects

(regardless of the state of the player).

Note that this version of Gradual appears in [[CRISTAL-SMAC2018]](index.html#cristal-smac2018) however

this version of

Gradual does not give the results reported in [[Beaufils1997]](index.html#beaufils1997) which is the

paper that first introduced the strategy. For a longer discussion of this

see: <https://github.com/Axelrod-Python/Axelrod/issues/1294>.

This version is based on <https://github.com/cristal-smac/ipd/blob/master/src/strategies.py#L224>

Names:

* Gradual: [[CRISTAL-SMAC2018]](index.html#cristal-smac2018)

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/titfortat.html#Gradual.strategy)[¶](#axelrod.strategies.titfortat.Gradual.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.titfortat.``HardTitFor2Tats`[[source]](_modules/axelrod/strategies/titfortat.html#HardTitFor2Tats)[¶](#axelrod.strategies.titfortat.HardTitFor2Tats "Permalink to this definition")

A variant of Tit For Two Tats that uses a longer history for

retaliation.

Names:

* Hard Tit For Two Tats: [[Stewart2012]](index.html#stewart2012)

*static* `strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/titfortat.html#HardTitFor2Tats.strategy)[¶](#axelrod.strategies.titfortat.HardTitFor2Tats.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.titfortat.``HardTitForTat`[[source]](_modules/axelrod/strategies/titfortat.html#HardTitForTat)[¶](#axelrod.strategies.titfortat.HardTitForTat "Permalink to this definition")

A variant of Tit For Tat that uses a longer history for retaliation.

Names:

* Hard Tit For Tat: [[PD2017]](index.html#pd2017)

*static* `strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/titfortat.html#HardTitForTat.strategy)[¶](#axelrod.strategies.titfortat.HardTitForTat.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.titfortat.``Michaelos`[[source]](_modules/axelrod/strategies/titfortat.html#Michaelos)[¶](#axelrod.strategies.titfortat.Michaelos "Permalink to this definition")

Plays similar to Tit-for-Tat with two exceptions:

1) Defect on last turn.

2) After own defection and opponent’s cooperation, 50 percent of the time,

cooperate. The other 50 percent of the time, always defect for the rest of

the game.

Names:

* Michaelos: [[LessWrong2011]](index.html#lesswrong2011)

`original_class`[¶](#axelrod.strategies.titfortat.Michaelos.original_class "Permalink to this definition")

alias of [`Michaelos`](#axelrod.strategies.titfortat.Michaelos "axelrod.strategies.titfortat.Michaelos")

*class* `axelrod.strategies.titfortat.``NTitsForMTats`(*N: int = 3*, *M: int = 2*)[[source]](_modules/axelrod/strategies/titfortat.html#NTitsForMTats)[¶](#axelrod.strategies.titfortat.NTitsForMTats "Permalink to this definition")

A parameterizable Tit-for-Tat,

The arguments are:

1) M: the number of defection before retaliation

2) N: the number of retaliations

Names:

* N Tit(s) For M Tat(s): Original name by Marc Harper

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/titfortat.html#NTitsForMTats.strategy)[¶](#axelrod.strategies.titfortat.NTitsForMTats.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.titfortat.``OmegaTFT`(*deadlock\_threshold: int = 3*, *randomness\_threshold: int = 8*)[[source]](_modules/axelrod/strategies/titfortat.html#OmegaTFT)[¶](#axelrod.strategies.titfortat.OmegaTFT "Permalink to this definition")

OmegaTFT modifies Tit For Tat in two ways:

- checks for deadlock loops of alternating rounds of (C, D) and (D, C),

and attempting to break them

- uses a more sophisticated retaliation mechanism that is noise tolerant

Names:

* OmegaTFT: [[Slany2007]](index.html#slany2007)

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/titfortat.html#OmegaTFT.strategy)[¶](#axelrod.strategies.titfortat.OmegaTFT.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.titfortat.``OriginalGradual`[[source]](_modules/axelrod/strategies/titfortat.html#OriginalGradual)[¶](#axelrod.strategies.titfortat.OriginalGradual "Permalink to this definition")

A player that punishes defections with a growing number of defections

but after punishing for punishment\_limit number of times enters a calming

state and cooperates no matter what the opponent does for two rounds.

The punishment\_limit is incremented whenever the opponent defects and the

strategy is not in either calming or punishing state.

Note that Gradual appears in [[CRISTAL-SMAC2018]](index.html#cristal-smac2018) however that version of

Gradual does not give the results reported in [[Beaufils1997]](index.html#beaufils1997) which is the

paper that first introduced the strategy. For a longer discussion of this

see: <https://github.com/Axelrod-Python/Axelrod/issues/1294>. This is why this

strategy has been renamed to OriginalGradual.

Names:

* Gradual: [[Beaufils1997]](index.html#beaufils1997)

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/titfortat.html#OriginalGradual.strategy)[¶](#axelrod.strategies.titfortat.OriginalGradual.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.titfortat.``RandomTitForTat`(*p: float = 0.5*)[[source]](_modules/axelrod/strategies/titfortat.html#RandomTitForTat)[¶](#axelrod.strategies.titfortat.RandomTitForTat "Permalink to this definition")

A player starts by cooperating and then follows by copying its

opponent (tit for tat style). From then on the player

will switch between copying its opponent and randomly

responding every other iteration.

Name:

* Random TitForTat: Original name by Zachary M. Taylor

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/titfortat.html#RandomTitForTat.strategy)[¶](#axelrod.strategies.titfortat.RandomTitForTat.strategy "Permalink to this definition")

This is the actual strategy

*class* `axelrod.strategies.titfortat.``SlowTitForTwoTats2`[[source]](_modules/axelrod/strategies/titfortat.html#SlowTitForTwoTats2)[¶](#axelrod.strategies.titfortat.SlowTitForTwoTats2 "Permalink to this definition")

A player plays C twice, then if the opponent plays the same move twice,

plays that move, otherwise plays previous move.

Names:

* Slow Tit For Tat: [[Prison1998]](index.html#prison1998)

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/titfortat.html#SlowTitForTwoTats2.strategy)[¶](#axelrod.strategies.titfortat.SlowTitForTwoTats2.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.titfortat.``SneakyTitForTat`[[source]](_modules/axelrod/strategies/titfortat.html#SneakyTitForTat)[¶](#axelrod.strategies.titfortat.SneakyTitForTat "Permalink to this definition")

Tries defecting once and repents if punished.

Names:

* Sneaky Tit For Tat: Original name by Karol Langner

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/titfortat.html#SneakyTitForTat.strategy)[¶](#axelrod.strategies.titfortat.SneakyTitForTat.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.titfortat.``SpitefulTitForTat`[[source]](_modules/axelrod/strategies/titfortat.html#SpitefulTitForTat)[¶](#axelrod.strategies.titfortat.SpitefulTitForTat "Permalink to this definition")

A player starts by cooperating and then mimics the previous action of the

opponent until opponent defects twice in a row, at which point player

always defects

Names:

* Spiteful Tit For Tat: [[Prison1998]](index.html#prison1998)

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/titfortat.html#SpitefulTitForTat.strategy)[¶](#axelrod.strategies.titfortat.SpitefulTitForTat.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.titfortat.``SuspiciousTitForTat`[[source]](_modules/axelrod/strategies/titfortat.html#SuspiciousTitForTat)[¶](#axelrod.strategies.titfortat.SuspiciousTitForTat "Permalink to this definition")

A variant of Tit For Tat that starts off with a defection.

Names:

* Suspicious Tit For Tat: [[Hilbe2013]](index.html#hilbe2013)

* Mistrust: [[Beaufils1997]](index.html#beaufils1997)

*static* `strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/titfortat.html#SuspiciousTitForTat.strategy)[¶](#axelrod.strategies.titfortat.SuspiciousTitForTat.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.titfortat.``TitFor2Tats`[[source]](_modules/axelrod/strategies/titfortat.html#TitFor2Tats)[¶](#axelrod.strategies.titfortat.TitFor2Tats "Permalink to this definition")

A player starts by cooperating and then defects only after two defects by

opponent.

Submitted to Axelrod’s second tournament by John Maynard Smith; it came in

24th in that tournament.

Names:

* Tit for two Tats: [[Axelrod1984]](index.html#axelrod1984)

* Slow tit for two tats: Original name by Ranjini Das

* JMaynardSmith: [[Axelrod1980b]](index.html#axelrod1980b)

*static* `strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/titfortat.html#TitFor2Tats.strategy)[¶](#axelrod.strategies.titfortat.TitFor2Tats.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.titfortat.``TitForTat`[[source]](_modules/axelrod/strategies/titfortat.html#TitForTat)[¶](#axelrod.strategies.titfortat.TitForTat "Permalink to this definition")

A player starts by cooperating and then mimics the previous action of the

opponent.

This strategy was referred to as the *‘simplest’* strategy submitted to

Axelrod’s first tournament. It came first.

Note that the code for this strategy is written in a fairly verbose

way. This is done so that it can serve as an example strategy for

those who might be new to Python.

Names:

* Rapoport’s strategy: [[Axelrod1980]](index.html#axelrod1980)

* TitForTat: [[Axelrod1980]](index.html#axelrod1980)

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/titfortat.html#TitForTat.strategy)[¶](#axelrod.strategies.titfortat.TitForTat.strategy "Permalink to this definition")

This is the actual strategy

*class* `axelrod.strategies.titfortat.``TwoTitsForTat`[[source]](_modules/axelrod/strategies/titfortat.html#TwoTitsForTat)[¶](#axelrod.strategies.titfortat.TwoTitsForTat "Permalink to this definition")

A player starts by cooperating and replies to each defect by two

defections.

Names:

* Two Tits for Tats: [[Axelrod1984]](index.html#axelrod1984)

*static* `strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/titfortat.html#TwoTitsForTat.strategy)[¶](#axelrod.strategies.titfortat.TwoTitsForTat.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.verybad.``VeryBad`[[source]](_modules/axelrod/strategies/verybad.html#VeryBad)[¶](#axelrod.strategies.verybad.VeryBad "Permalink to this definition")

It cooperates in the first three rounds, and uses probability

(it implements a memory, which stores the opponent’s moves) to decide for

cooperating or defecting.

Due to a lack of information as to what that probability refers to in this

context, probability(P(X)) refers to (Count(X)/Total\_Moves) in this

implementation

P(C) = Cooperations / Total\_Moves

P(D) = Defections / Total\_Moves = 1 - P(C)

Names:

* VeryBad: [[Andre2013]](index.html#andre2013)

*static* `strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/verybad.html#VeryBad.strategy)[¶](#axelrod.strategies.verybad.VeryBad.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.worse_and_worse.``KnowledgeableWorseAndWorse`[[source]](_modules/axelrod/strategies/worse_and_worse.html#KnowledgeableWorseAndWorse)[¶](#axelrod.strategies.worse_and_worse.KnowledgeableWorseAndWorse "Permalink to this definition")

This strategy is based on ‘Worse And Worse’ but will defect with probability

of ‘current turn / total no. of turns’.

Names:

* Knowledgeable Worse and Worse: Original name by Adam Pohl

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/worse_and_worse.html#KnowledgeableWorseAndWorse.strategy)[¶](#axelrod.strategies.worse_and_worse.KnowledgeableWorseAndWorse.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.worse_and_worse.``WorseAndWorse`[[source]](_modules/axelrod/strategies/worse_and_worse.html#WorseAndWorse)[¶](#axelrod.strategies.worse_and_worse.WorseAndWorse "Permalink to this definition")

Defects with probability of ‘current turn / 1000’. Therefore

it is more and more likely to defect as the round goes on.

Source code available at the download tab of [[Prison1998]](index.html#prison1998)

Names:

* Worse and Worse: [[Prison1998]](index.html#prison1998)

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/worse_and_worse.html#WorseAndWorse.strategy)[¶](#axelrod.strategies.worse_and_worse.WorseAndWorse.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.worse_and_worse.``WorseAndWorse2`[[source]](_modules/axelrod/strategies/worse_and_worse.html#WorseAndWorse2)[¶](#axelrod.strategies.worse_and_worse.WorseAndWorse2 "Permalink to this definition")

Plays as tit for tat during the first 20 moves.

Then defects with probability (current turn - 20) / current turn.

Therefore it is more and more likely to defect as the round goes on.

Names:

* Worse and Worse 2: [[Prison1998]](index.html#prison1998)

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/worse_and_worse.html#WorseAndWorse2.strategy)[¶](#axelrod.strategies.worse_and_worse.WorseAndWorse2.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.worse_and_worse.``WorseAndWorse3`[[source]](_modules/axelrod/strategies/worse_and_worse.html#WorseAndWorse3)[¶](#axelrod.strategies.worse_and_worse.WorseAndWorse3 "Permalink to this definition")

Cooperates in the first turn.

Then defects with probability no. of opponent defects / (current turn - 1).

Therefore it is more likely to defect when the opponent defects for a larger

proportion of the turns.

Names:

* Worse and Worse 3: [[Prison1998]](index.html#prison1998)

`strategy`(*opponent: axelrod.player.Player*) → axelrod.action.Action[[source]](_modules/axelrod/strategies/worse_and_worse.html#WorseAndWorse3.strategy)[¶](#axelrod.strategies.worse_and_worse.WorseAndWorse3.strategy "Permalink to this definition")

Actual strategy definition that determines player’s action.

*class* `axelrod.strategies.zero_determinant.``LRPlayer`(*phi: float = 0.2*, *s: float = 0.1*, *l: float = 1*)[[source]](_modules/axelrod/strategies/zero_determinant.html#LRPlayer)[¶](#axelrod.strategies.zero_determinant.LRPlayer "Permalink to this definition")

Abstraction for Linear Relation players. These players enforce a linear

difference in stationary payoffs \(s (S\_{xy} - l) = S\_{yx} - l.\)

The parameter \(s\) is called the slope and the parameter \(l\) the

baseline payoff. For extortionate strategies, the extortion factor

\(\chi\) is the inverse of the slope \(s\).

For the standard prisoner’s dilemma where \(T > R > P > S\) and

\(R > (T + S) / 2 > P\), a pair \((l, s)\) is enforceable iff

\begin{eqnarray}

&P &<= l <= R \\

&s\_{min} &= -\min\left( \frac{T - l}{l - S}, \frac{l - S}{T - l}\right) <= s <= 1

\end{eqnarray}And also that there exists \(\phi\) such that

\begin{eqnarray}

 p\_1 &= P(C|CC) &= 1 - \phi (1 - s)(R - l) \\

 p\_2 &= P(C|CD) &= 1 - \phi (s(l - S) + (T - l)) \\

 p\_3 &= P(C|DC) &= \phi ((l - S) + s(T - l)) \\

 p\_4 &= P(C|DD) &= \phi (1 - s)(l - P)

\end{eqnarray}These conditions also force \(\phi >= 0\). For a given pair \((l, s)\)

there may be multiple such \(\phi\).

This parameterization is Equation 14 in [[Hilbe2013]](index.html#hilbe2013).

See Figure 2 of the article for a more in-depth explanation. Other game

parameters can alter the relations and bounds above.

Names:

* Linear Relation player: [[Hilbe2013]](index.html#hilbe2013)

`receive_match_attributes`()[[source]](_modules/axelrod/strategies/zero_determinant.html#LRPlayer.receive_match_attributes)[¶](#axelrod.strategies.zero_determinant.LRPlayer.receive_match_attributes "Permalink to this definition")

Parameters

phi, s, l: floats

Parameter used to compute the four-vector according to the

parameterization of the strategies below.

*class* `axelrod.strategies.zero_determinant.``ZDExtort2`(*phi: float = 0.1111111111111111*, *s: float = 0.5*)[[source]](_modules/axelrod/strategies/zero_determinant.html#ZDExtort2)[¶](#axelrod.strategies.zero_determinant.ZDExtort2 "Permalink to this definition")

An Extortionate Zero Determinant Strategy with l=P.

Names:

* Extort-2: [[Stewart2012]](index.html#stewart2012)

`receive_match_attributes`()[[source]](_modules/axelrod/strategies/zero_determinant.html#ZDExtort2.receive_match_attributes)[¶](#axelrod.strategies.zero_determinant.ZDExtort2.receive_match_attributes "Permalink to this definition")

Parameters

phi, s, l: floats

Parameter used to compute the four-vector according to the

parameterization of the strategies below.

*class* `axelrod.strategies.zero_determinant.``ZDExtort2v2`(*phi: float = 0.125*, *s: float = 0.5*, *l: float = 1*)[[source]](_modules/axelrod/strategies/zero_determinant.html#ZDExtort2v2)[¶](#axelrod.strategies.zero_determinant.ZDExtort2v2 "Permalink to this definition")

An Extortionate Zero Determinant Strategy with l=1.

Names:

* EXTORT2: [[Kuhn2017]](index.html#kuhn2017)

*class* `axelrod.strategies.zero_determinant.``ZDExtort3`(*phi: float = 0.11538461538461539*, *s: float = 0.3333333333333333*, *l: float = 1*)[[source]](_modules/axelrod/strategies/zero_determinant.html#ZDExtort3)[¶](#axelrod.strategies.zero_determinant.ZDExtort3 "Permalink to this definition")

An extortionate strategy from Press and Dyson’s paper witn an extortion

factor of 3.

Names:

* ZDExtort3: Original name by Marc Harper

* Unnamed: [[Press2012]](index.html#press2012)

*class* `axelrod.strategies.zero_determinant.``ZDExtort4`(*phi: float = 0.23529411764705882*, *s: float = 0.25*, *l: float = 1*)[[source]](_modules/axelrod/strategies/zero_determinant.html#ZDExtort4)[¶](#axelrod.strategies.zero_determinant.ZDExtort4 "Permalink to this definition")

An Extortionate Zero Determinant Strategy with l=1, s=1/4. TFT is the

other extreme (with l=3, s=1)

Names:

* Extort 4: Original name by Marc Harper

*class* `axelrod.strategies.zero_determinant.``ZDExtortion`(*phi: float = 0.2*, *s: float = 0.1*, *l: float = 1*)[[source]](_modules/axelrod/strategies/zero_determinant.html#ZDExtortion)[¶](#axelrod.strategies.zero_determinant.ZDExtortion "Permalink to this definition")

An example ZD Extortion player.

Names:

* ZDExtortion: [[Roemheld2013]](index.html#roemheld2013)

*class* `axelrod.strategies.zero_determinant.``ZDGTFT2`(*phi: float = 0.25*, *s: float = 0.5*)[[source]](_modules/axelrod/strategies/zero_determinant.html#ZDGTFT2)[¶](#axelrod.strategies.zero_determinant.ZDGTFT2 "Permalink to this definition")

A Generous Zero Determinant Strategy with l=R.

Names:

* ZDGTFT-2: [[Stewart2012]](index.html#stewart2012)

`receive_match_attributes`()[[source]](_modules/axelrod/strategies/zero_determinant.html#ZDGTFT2.receive_match_attributes)[¶](#axelrod.strategies.zero_determinant.ZDGTFT2.receive_match_attributes "Permalink to this definition")

Parameters

phi, s, l: floats

Parameter used to compute the four-vector according to the

parameterization of the strategies below.

*class* `axelrod.strategies.zero_determinant.``ZDGen2`(*phi: float = 0.125*, *s: float = 0.5*, *l: float = 3*)[[source]](_modules/axelrod/strategies/zero_determinant.html#ZDGen2)[¶](#axelrod.strategies.zero_determinant.ZDGen2 "Permalink to this definition")

A Generous Zero Determinant Strategy with l=3.

Names:

* GEN2: [[Kuhn2017]](index.html#kuhn2017)

*class* `axelrod.strategies.zero_determinant.``ZDMischief`(*phi: float = 0.1*, *s: float = 0.0*, *l: float = 1*)[[source]](_modules/axelrod/strategies/zero_determinant.html#ZDMischief)[¶](#axelrod.strategies.zero_determinant.ZDMischief "Permalink to this definition")

An example ZD Mischief player.

Names:

* ZDMischief: [[Roemheld2013]](index.html#roemheld2013)

*class* `axelrod.strategies.zero_determinant.``ZDSet2`(*phi: float = 0.25*, *s: float = 0.0*, *l: float = 2*)[[source]](_modules/axelrod/strategies/zero_determinant.html#ZDSet2)[¶](#axelrod.strategies.zero_determinant.ZDSet2 "Permalink to this definition")

A Generous Zero Determinant Strategy with l=2.

Names:

* SET2: [[Kuhn2017]](index.html#kuhn2017)

#### Glossary[¶](#glossary "Permalink to this headline")

There are a variety of terms used in the documentation and throughout the

library. Here is an overview:

##### An action[¶](#an-action "Permalink to this headline")

An **action** is either `C` or `D`.

You can access these actions as follows but should not really have a reason to:

```

>>> import axelrod as axl

>>> axl.Action.C

C

>>> axl.Action.D

D

```

##### A play[¶](#a-play "Permalink to this headline")

A **play** is a single player choosing an **action**.

In terms of code this is equivalent to:

```

>>> p1, p2 = axl.Cooperator(), axl.Defector()

>>> C = p1.strategy(p2)  # This constitutes two 'plays' (p1 plays and p2 plays).

>>> D = p2.strategy(p1)  # This constitutes two 'plays' (p1 plays and p2 plays).

```

##### A turn[¶](#a-turn "Permalink to this headline")

A **turn** is a 1 shot interaction between two players. It is in effect a

composition of two **plays**.

Each turn has four possible outcomes of a play: `(C, C)`, `(C, D)`,

`(D, C)`, or `(D, D)`.

##### A match[¶](#a-match "Permalink to this headline")

A **match** is a consecutive number of **turns**. The default number of turns

used in the tournament is 200. Here is a single match between two players over

3 turns:

```

>>> p1, p2 = axl.Cooperator(), axl.Defector()

>>> match = axl.Match((p1, p2), turns=3)

>>> result = match.play()

>>> result

[(C, D), (C, D), (C, D)]

>>> p1.history, p2.history

([C, C, C], [D, D, D])

```

##### A win[¶](#a-win "Permalink to this headline")

A **win** is attributed to the player who has the higher total score at the end

of a match. For the example above, `Defector` would win that match.

##### A strategy[¶](#a-strategy "Permalink to this headline")

A **strategy** is a set of instructions that dictate how to play given one’s own

strategy and the strategy of an opponent. In the library these correspond to the

strategy classes: TitForTat, Grudger, Cooperator etc…

When appropriate to do so this will be used interchangeable with [A player](#a-player).

##### A player[¶](#a-player "Permalink to this headline")

A **player** is a single agent using a given strategy. Players are the

participants of tournament, usually they each represent one strategy but of

course you can have multiple players choosing the same strategy. In the library

these correspond to \_\_instances\_\_ of classes:

```

>>> p1, p2 = axl.Cooperator(), axl.Defector()

>>> p1

Cooperator

>>> p2

Defector

```

When appropriate to do so this will be used interchangeable with [A strategy](#a-strategy).

##### A round robin[¶](#a-round-robin "Permalink to this headline")

A **round robin** is the set of all potential (order invariant) matches between

a given collection of players.

##### A tournament[¶](#a-tournament "Permalink to this headline")

A **tournament** is a repetition of round robins so as to smooth out stochastic effects.

##### Noise[¶](#noise "Permalink to this headline")

A match or tournament can be played with **noise**: this is the probability that

indicates the chance of an action dictated by a strategy being swapped.

Indices and tables[¶](#indices-and-tables "Permalink to this headline")

=======================================================================

* [Index](genindex.html)

* [Module Index](py-modindex.html)

* [Search Page](search.html)

