-
Notifications
You must be signed in to change notification settings - Fork 263
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 gradual and discussion of tournament #1299
Changes from 4 commits
d04da3c
a367785
91d9f1d
932bf33
a9b9556
b7ff5c6
1c07e88
251a430
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 |
---|---|---|
|
@@ -336,6 +336,229 @@ class TestGradual(TestPlayer): | |
"manipulates_state": False, | ||
} | ||
|
||
def test_strategy(self): | ||
# Punishes defection with a growing number of defections and calms | ||
# the opponent with two cooperations in a row. | ||
opponent = axelrod.MockPlayer(actions=[C]) | ||
actions = [(C, C)] | ||
self.versus_test( | ||
opponent, | ||
expected_actions=actions, | ||
attrs={ | ||
"calm_count": 0, | ||
"punish_count": 0, | ||
}, | ||
) | ||
|
||
opponent = axelrod.MockPlayer(actions=[D]) | ||
actions = [(C, D)] | ||
self.versus_test( | ||
opponent, | ||
expected_actions=actions, | ||
attrs={ | ||
"calm_count": 0, | ||
"punish_count": 0, | ||
}, | ||
) | ||
|
||
opponent = axelrod.MockPlayer(actions=[D, C]) | ||
actions = [(C, D), (D, C)] | ||
self.versus_test( | ||
opponent, | ||
expected_actions=actions, | ||
attrs={ | ||
"calm_count": 2, | ||
"punish_count": 0, | ||
}, | ||
) | ||
|
||
opponent = axelrod.MockPlayer(actions=[D, C, C]) | ||
actions = [(C, D), (D, C), (C, C)] | ||
self.versus_test( | ||
opponent, | ||
expected_actions=actions, | ||
attrs={ | ||
"calm_count": 1, | ||
"punish_count": 0, | ||
}, | ||
) | ||
|
||
opponent = axelrod.MockPlayer(actions=[D, C, D, C]) | ||
actions = [(C, D), (D, C), (C, D), (C, C)] | ||
self.versus_test( | ||
opponent, | ||
expected_actions=actions, | ||
attrs={ | ||
"calm_count": 0, | ||
"punish_count": 0, | ||
}, | ||
) | ||
|
||
opponent = axelrod.MockPlayer(actions=[D, C, D, C, C]) | ||
actions = [(C, D), (D, C), (C, D), (C, C), (C, C)] | ||
self.versus_test( | ||
opponent, | ||
expected_actions=actions, | ||
attrs={ | ||
"calm_count": 0, | ||
"punish_count": 0, | ||
}, | ||
) | ||
|
||
opponent = axelrod.MockPlayer(actions=[D, C, D, C, C, C]) | ||
actions = [(C, D), (D, C), (C, D), (C, C), (C, C), (C, C)] | ||
self.versus_test( | ||
opponent, | ||
expected_actions=actions, | ||
attrs={ | ||
"calm_count": 0, | ||
"punish_count": 0, | ||
}, | ||
) | ||
|
||
opponent = axelrod.MockPlayer(actions=[D, C, D, C, C, C, D, C]) | ||
actions = [(C, D), (D, C), (C, D), (C, C), (C, C), (C, C), (C, D), (D, C)] | ||
self.versus_test( | ||
opponent, | ||
expected_actions=actions, | ||
attrs={ | ||
"calm_count": 2, | ||
"punish_count": 2, | ||
}, | ||
) | ||
|
||
opponent = axelrod.MockPlayer(actions=[D, C, D, C, C, D, D, D]) | ||
actions = [(C, D), (D, C), (C, D), (C, C), (C, C), (C, D), (D, D), (D, D)] | ||
self.versus_test( | ||
opponent, | ||
expected_actions=actions, | ||
attrs={ | ||
"calm_count": 2, | ||
"punish_count": 1, | ||
}, | ||
) | ||
|
||
opponent = axelrod.Defector() | ||
actions = [ | ||
(C, D), | ||
(D, D), # 1 defection as a response to the 1 defection by opponent | ||
(C, D), | ||
(C, D), | ||
(D, D), # starts defecting after a total of 4 defections by the opponent | ||
(D, D), | ||
(D, D), | ||
(D, D), # 4 defections | ||
(C, D), | ||
(C, D), | ||
(D, D), # Start defecting after a total of 10 defections by the opponent | ||
(D, D), | ||
(D, D), | ||
(D, D), | ||
(D, D), | ||
(D, D), | ||
(D, D), | ||
(D, D), | ||
(D, D), | ||
(D, D), # 10 defections | ||
(C, D), | ||
(C, D), | ||
(D, D), # starts defecting after 22 defections by the opponent | ||
(D, D), | ||
(D, D), | ||
(D, D), | ||
(D, D), | ||
(D, D), | ||
(D, D), | ||
(D, D), | ||
(D, D), | ||
(D, D), | ||
(D, D), | ||
(D, D), | ||
(D, D), | ||
(D, D), | ||
(D, D), | ||
(D, D), | ||
(D, D), | ||
(D, D), | ||
(D, D), | ||
(D, D), | ||
(D, D), | ||
(D, D), # 22 defections | ||
(C, D), | ||
(C, D), | ||
(D, D), | ||
(D, D), | ||
(D, D), | ||
(D, D), | ||
] | ||
self.versus_test( | ||
opponent, | ||
expected_actions=actions, | ||
attrs={ | ||
"calm_count": 2, | ||
"punish_count": 42, | ||
}, | ||
) | ||
|
||
def test_specific_set_of_results(self): | ||
""" | ||
This tests specific reported results as discussed in | ||
https://github.com/Axelrod-Python/Axelrod/issues/1294 | ||
The results there used a version of mistrust with a bug that corresponds | ||
to a memory one player that start by defecting and only cooperates if | ||
both players cooperated in the previous round. | ||
""" | ||
mistrust_with_bug = axelrod.MemoryOnePlayer( | ||
initial=D, | ||
four_vector=(1, 0, 0, 0), | ||
) | ||
players = [ | ||
self.player(), | ||
axelrod.TitForTat(), | ||
axelrod.GoByMajority(), | ||
axelrod.Grudger(), | ||
axelrod.WinStayLoseShift(), | ||
axelrod.Prober(), | ||
axelrod.Defector(), | ||
mistrust_with_bug, | ||
axelrod.Cooperator(), | ||
axelrod.CyclerCCD(), | ||
axelrod.CyclerDDC(), | ||
] | ||
axelrod.seed(1) | ||
tournament = axelrod.Tournament(players, turns=1000, repetitions=1) | ||
results = tournament.play(progress_bar=False) | ||
scores = [round(average_score_per_turn * 1000, 1) | ||
for average_score_per_turn in results.payoff_matrix[0]] | ||
expected_scores = [ | ||
3000.0, | ||
3000.0, | ||
3000.0, | ||
3000.0, | ||
3000.0, | ||
2999.0, | ||
983.0, | ||
983.0, | ||
3000.0, | ||
3596.0, | ||
2302.0, | ||
] | ||
self.assertEqual(scores, expected_scores) | ||
|
||
class TestOriginalGradual(TestPlayer): | ||
|
||
name = "Original Gradual" | ||
player = axelrod.OriginalGradual | ||
expected_classifier = { | ||
"memory_depth": float("inf"), | ||
"stochastic": False, | ||
"makes_use_of": set(), | ||
"inspects_source": False, | ||
"manipulates_source": False, | ||
"manipulates_state": False, | ||
} | ||
|
||
def test_strategy(self): | ||
# Punishes defection with a growing number of defections and calms | ||
# the opponent with two cooperations in a row. | ||
|
@@ -466,6 +689,9 @@ def test_output_from_literature(self): | |
Dilemma" Proc. Artif. Life 1996 | ||
This test just ensures that the strategy is as was originally defined. | ||
See https://github.com/Axelrod-Python/Axelrod/issues/1294 for another | ||
discussion of this. | ||
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. Should this be a test similar 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. Sure why not. 👍 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. Note that this will just repeat the doctest. (I'm fine with that.) 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. Sure. It already does that but only for two strategies right? We are testing the output of the paper so I suggest we include all of it, and it will follow the same format as the tests for 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. Done in 1c07e88 |
||
""" | ||
player = self.player() | ||
|
||
|
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.
niggle: too many empty lines (black might need running here)
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.
b7ff5c6 ran black on the file