-
Notifications
You must be signed in to change notification settings - Fork 282
Add Alexei strategy #997
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 Alexei strategy #997
Conversation
|
Tests are failing on a syntax error. |
|
This is failing at |
|
@meatballs I am not sure if the strategy written is fully correct. |
|
Can someone check the strategy written? It plays like Tit-for-Tat with a defection at the end. |
|
The strategy you have written does not do what you describe (there's no reference to the number of turns in it which is what is needed to be able to defect on the last move). Take a look at strategy transformers for an way to do this easily: http://axelrod.readthedocs.io/en/latest/tutorials/advanced/strategy_transformers.html In particular use the Final Transformer: take a look at backstabber. |
Nikoleta-v3
left a comment
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.
Hello @souravsingh. Your tests are currently failing at various places. Here are some comments to help you
axelrod/strategies/titfortat.py
Outdated
| classifier = { | ||
| 'memory_depth': 1, | ||
| 'stochastic': False, | ||
| 'makes_use_of': set(), |
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.
your strategy makes use of length.
| self.versus_test(axelrod.Alternator(), expected_actions=actions) | ||
|
|
||
| actions = [(C, C), (C, C), (C, C), (C, C), (C, C)] | ||
| self.versus_test(axelrod.Cooperator(), expected_actions=actions) |
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.
You are getting a failure against Cooperator.
| documentation. | ||
| """ | ||
|
|
||
| name = "Alexei" |
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.
Now that your are using @FinalTransformer the name of your strategy is different.
AssertionError: 'Alexei: D' != 'Alexei'
Take a look at the backstabber tests https://github.com/Axelrod-Python/Axelrod/blob/master/axelrod/tests/strategies/test_backstabber.py.
|
@souravsingh thank you for the changes, though you did not get everything correct.
I would recommend you run your tests before pushing and if you are getting an error you can't solve feel free to throw it in here! |
| 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)] |
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.
Try to keep in mind how your strategy plays. Again I would do the expected actions by hand before writing the test. Your strategy has a rule, Defect on the last round
|
@Nikoleta-v3 All tests pass except for one which is unrelated to the strategy. |
@souravsingh that failing test might be related to the strategy in some way (I'm not sure how) but all tests pass on the library so that failure is being cause by this addition. |
axelrod/strategies/titfortat.py
Outdated
| Names: | ||
| - From http://lesswrong.com/lw/7f2/prisoners_dilemma_tournament_results/ |
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.
Can you reference this as for other strategies please.
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.
This is the only strategy implemented from the site.
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.
Yes that's fine but can you move the site to the bibliography and make the Names section fit the guidelines: http://axelrod.readthedocs.io/en/stable/tutorials/contributing/strategy/docstrings.html
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.
Take a look at how Prison is written in the bibliography. Let me know if you'd like a hand.
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.
Oh, I had forgotten the docstrings conventions for Axelrod.
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.
(I think you actually wrote that file I linked to :) 🤣 👍 )
|
Was there an update made to |
I don't believe so but rebasing anyway sounds like a good idea. Then you can run the full test locally |
|
I've just confirmed that all tests on |
|
And I've just confirmed the failure locally. It's failing on the test for probalistic ending tournaments with probability 1. So it's something to do with the strategy not behaving as expected when it does not know the length of the game. Could point to something not right with the Transformer. I'm investigating. |
|
This brings up the failure: |
|
The error seems to be something to do with the |
axelrod/strategies/titfortat.py
Outdated
| # Otherwise play previous move | ||
| return self.history[-1] | ||
|
|
||
| @FinalTransformer(D, name_prefix=None) |
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.
FinalTransformer takes a sequence. Change this to (D, ) (although that doesn't fix what's going wrong).
axelrod/strategies/titfortat.py
Outdated
|
|
||
| name = 'Alexei' | ||
| classifier = { | ||
| 'memory_depth': 1, |
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.
This strategy has memory depth: float('inf') as it needs to keep count of how many turns it has played to be able to know when to defect on the last round.
Fixing this will fix the other test failure as it was being picked up as a basic strategy (which it is not).
axelrod/strategies/titfortat.py
Outdated
| # Otherwise play previous move | ||
| return self.history[-1] | ||
|
|
||
| @FinalTransformer((D, ) name_prefix=None) |
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.
(D,) (no space)
For the record: this was not the issue, the transformer works exactly as expected. |
axelrod/strategies/titfortat.py
Outdated
| # Otherwise play previous move | ||
| return self.history[-1] | ||
|
|
||
| @FinalTransformer((D,) name_prefix=None) |
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.
You now have a syntax error, type exactly this:
@FinalTransformer((D,), name_prefix=None)
There's information on running the tests (that would have picked this up immediately) here: http://axelrod.readthedocs.io/en/stable/tutorials/contributing/running_tests.html
|
@drvinceknight I have made the fixes. Can you review and suggest any more changes? |
drvinceknight
left a comment
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.
I'll review properly as soon as I get a moment @souravsingh.
| .. [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. | ||
| .. [Hilde2013] 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. | ||
| .. [Kraines1989] Kraines, D. & Kraines, V. Theor Decis (1989) 26: 47. doi:10.1007/BF00134056 | ||
| .. [LessWrong2011] Zoo of Strategies (2011) LessWrong. Available at: http://lesswrong.com/lw/7f2/prisoners_dilemma_tournament_results/ |
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.
All on one line please. I think this doesn't play properly with sphinx otherwise.
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.
I think I have written in one line. Unless I am misunderstanding something.
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.
You have indeed. I'll review properly when I get a moment.
drvinceknight
left a comment
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.
Looking good, some minor adjustments to the tests from me.
| actions = [(C, D), (D, D), (D, D), (D, D), (D, D)] | ||
| self.versus_test(axelrod.Defector(), expected_actions=actions) | ||
|
|
||
| actions = [(C, C), (C, D), (D, C), (C, D), (D, C)] |
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.
Could you add one more round to this actions, the point of having match_attributes={"length":-1} is to show how the strategy acts when playing without knowledge of the when the last round is so the last actions would be:
actions = [(C, C), (C, D), (D, C), (C, D), (D, C), (C, D)]Then can you repeat the exact same test but without match_attributes which should then have:
actions = [(C, C), (C, D), (D, C), (C, D), (D, C), (D D)]Which shows that the "last round" instruction is working. (So just move your other alternator test here and add the extra round).
| self.versus_test(axelrod.Alternator(), expected_actions=actions, | ||
| match_attributes={"length": -1}) | ||
|
|
||
| actions = [(C, D), (D, D), (D, C), (C, C), (D, D)] |
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.
I think all the test case will be covered by the cases above, we can simplify this and remove everything below.
| self.versus_test(axelrod.Alternator(), expected_actions=actions) | ||
|
|
||
|
|
||
| actions = [(C, D), (D, D), (D, C), (C, C), (D, D)] |
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.
As long as coverage remains the same, I think we can remove this test.
| self.versus_test(axelrod.Random(), expected_actions=actions, | ||
| seed=0) | ||
|
|
||
| actions = [(C, C), (C, D), (D, D), (D, C)] |
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.
As long as coverage remains the same, I think we can remove this test.
| self.versus_test(axelrod.Random(), expected_actions=actions, | ||
| seed=1) | ||
|
|
||
| opponent = axelrod.MockPlayer(actions=[C, D]) |
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.
As long as coverage remains the same, I think we can remove this test.
| actions = [(C, C), (C, D), (D, C), (D, D)] | ||
| self.versus_test(opponent, expected_actions=actions) | ||
|
|
||
| opponent = axelrod.MockPlayer(actions=[C, C, D, D, C, D]) |
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.
As long as coverage remains the same, I think we can remove this test.
| self.first_play_test(C) | ||
| self.second_play_test(rCC=C, rCD=D, rDC=C, rDD=D) | ||
|
|
||
| actions = [(C, C), (C, D), (D, C), (C, D), (D, C)] |
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.
We can remove this test because you moved it.
|
This looks great to me. Thanks @souravsingh 👍 |
Strategy is adapted from http://lesswrong.com/lw/7f2/prisoners_dilemma_tournament_results/