-
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 new strategy SelfSteem #866
Changes from 3 commits
57a94d7
b58b6b9
15463da
21ad4d7
a50750f
f7654bc
04ed431
d00e419
6623e00
aacf48e
09a94eb
90b8bd8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
from axelrod.actions import Action, Actions | ||
from axelrod.player import Player | ||
|
||
from math import pi, sin | ||
import random | ||
|
||
C, D = Actions.C, Actions.D | ||
|
||
|
||
class SelfSteem(Player): | ||
""" | ||
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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. current iteration There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. |
||
|
||
If f > 0.95, 'ego' of the algorithm is inflated; always defects. | ||
If 0.95 > |f| > 0.3, rational behavior; follows TitForTat algortithm. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line is creating an error as sphinx is confused by |
||
If 0.3 > f > -0.3; random behavior. | ||
If f < -0.95, algorithm is at rock bottom; always cooperates. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you also add this strategy to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
""" | ||
|
||
name = 'SelfSteem' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the name of this strategy?
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is |
||
classifier = { | ||
'memory_depth': 1, | ||
'stochastic': False, | ||
'makes_use_of': set(), | ||
'long_run_time': False, | ||
'inspects_source': False, | ||
'manipulates_source': False, | ||
'manipulates_state': False | ||
} | ||
|
||
def strategy(self, opponent: Player) -> Action: | ||
turns_number = len(self.history) | ||
sine_value = sin(2*pi*turns_number/10) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PEP8: |
||
|
||
if sine_value > 0.95: | ||
return D | ||
|
||
elif abs(sine_value) < 0.95 and abs(sine_value) > 0.3: | ||
return opponent.history[-1] | ||
|
||
elif sine_value < 0.3 and sine_value > -0.3: | ||
return random.choice((C, D)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Better to use the inbuilt |
||
|
||
else: | ||
return C | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
"""Tests for the SelfSteem strategy.""" | ||
|
||
import axelrod | ||
import random | ||
from .test_player import TestPlayer | ||
|
||
C, D = axelrod.Actions.C, axelrod.Actions.D | ||
|
||
class TestSelfSteem(TestPlayer): | ||
|
||
name = "SelfSteem" | ||
player = axelrod.SelfSteem | ||
expected_classifier = { | ||
'memory_depth': 1, | ||
'stochastic': False, | ||
'makes_use_of': set(), | ||
'inspects_source': False, | ||
'manipulates_source': False, | ||
'manipulates_state': False | ||
} | ||
|
||
def test_strategy(self): | ||
# Check for f > 0.95 | ||
self.responses_test([D], [C] * 2 , [C] * 2 ) | ||
self.responses_test([D], [C] * 13, [C] * 13) | ||
|
||
# Check for f < -0.95 | ||
self.responses_test([C], [C] * 7, [C] * 7) | ||
self.responses_test([C], [C] * 18, [D] * 18) | ||
|
||
# Check for 0.95 > abs(f) > 0.3 | ||
self.responses_test([C], [C], [C]) | ||
self.responses_test([D], [C] * 16, [D] * 16) | ||
self.responses_test([C], [D] * 9, [C] * 9) | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you get rid of the blank lines but also include a test for the random behaviour, you can do this by passing a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What exactly is happening here with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So a random process starts with a random seed. This just ensures the "randomness" can be repeated:
The |
||
|
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.
self esteem?
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.
It means self esteem, that's how its named in the paper. I decided not to change it.