-
Notifications
You must be signed in to change notification settings - Fork 264
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #748 from amkratz/master
Add Neg strategy and change 4 method names for consistency
- Loading branch information
Showing
7 changed files
with
72 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import random | ||
from axelrod import Actions, Player, random_choice, flip_action, init_args | ||
from axelrod.strategy_transformers import TrackHistoryTransformer | ||
|
||
C, D = Actions.C, Actions.D | ||
|
||
class Negation(Player): | ||
""" | ||
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 - [http://www.prisoners-dilemma.com/competition.html] | ||
""" | ||
|
||
name = "Negation" | ||
classifier = { | ||
'memory_depth': 1, | ||
'stochastic': True, | ||
'makes_use_of': set(), | ||
'long_run_time': False, | ||
'inspects_source': False, | ||
'manipulates_source': False, | ||
'manipulates_state': False | ||
} | ||
|
||
def strategy(self, opponent): | ||
# Random first move | ||
if not self.history: | ||
return random_choice(); | ||
|
||
# Act opposite of opponent otherwise | ||
return flip_action(opponent.history[-1]) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
"""Test for the Neg Strategy""" | ||
|
||
import axelrod | ||
from .test_player import TestPlayer | ||
|
||
C, D = axelrod.Actions.C, axelrod.Actions.D | ||
|
||
class TestNegation(TestPlayer): | ||
|
||
name = "Negation" | ||
player = axelrod.Negation | ||
expected_classifier = { | ||
'memory_depth': 1, | ||
'stochastic': True, | ||
'makes_use_of': set(), | ||
'long_run_time': False, | ||
'inspects_source': False, | ||
'manipulates_source': False, | ||
'manipulates_state': False | ||
} | ||
|
||
def test_effect_of_strategy(self): | ||
"""Repeats opposite of opponents last action.""" | ||
self.markov_test([D, C, D, C]) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters