-
Notifications
You must be signed in to change notification settings - Fork 264
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Neg strategy and change 4 method names for consistency #748
Merged
Merged
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c612967
Add Neg Strategy
amkratz 564b179
Minor spelling changes
amkratz b238fc8
Change Neg to Negation, reference changes
amkratz 4e44164
Forgot one name update
amkratz d52c396
Removed a comment
amkratz 3dffcfb
Changed files to include Doubler
amkratz 03a0cd0
Merge remote-tracking branch 'refs/remotes/Axelrod-Python/master'
amkratz 7e3de73
Cotinuing to fix repo issues
amkratz 9bf2a22
Last of fixes to files
amkratz 4c27334
Update classification_of_strategies.rst
amkratz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The strategy also needs to be added to the all_strategies list in this file