Skip to content

Conversation

@souravsingh
Copy link
Contributor

@drvinceknight
Copy link
Member

Tests are failing on a syntax error.

@meatballs
Copy link
Member

This is failing at axelrod/tests/strategies/test_player.py", line 361

AssertionError: 'D' != 'C'

@souravsingh
Copy link
Contributor Author

souravsingh commented May 1, 2017

@meatballs I am not sure if the strategy written is fully correct.

@souravsingh
Copy link
Contributor Author

Can someone check the strategy written? It plays like Tit-for-Tat with a defection at the end.

@drvinceknight
Copy link
Member

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.

Copy link
Member

@Nikoleta-v3 Nikoleta-v3 left a 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

classifier = {
'memory_depth': 1,
'stochastic': False,
'makes_use_of': set(),
Copy link
Member

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)
Copy link
Member

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"
Copy link
Member

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.

@Nikoleta-v3
Copy link
Member

@souravsingh thank you for the changes, though you did not get everything correct.

  1. now that you have included that your strategy is making use of length you should alter your test
  2. Looking at how the @FinalTransformer works the name of the strategy should be Given Name: the action you specified. Thus 'Alexei: D'.
  3. when you play against strategies could you make sure you write down the expected actions by hand first. For example your strategy should always defect on the last round but that's not the case in your tests.

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)]
Copy link
Member

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

@souravsingh
Copy link
Contributor Author

@Nikoleta-v3 All tests pass except for one which is unrelated to the strategy.

@drvinceknight
Copy link
Member

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.

Names:
- From http://lesswrong.com/lw/7f2/prisoners_dilemma_tournament_results/
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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 :) 🤣 👍 )

@souravsingh
Copy link
Contributor Author

Was there an update made to test/unit/test_tournament.py before version 2.11 was released? If so, I just have to do a rebase and it should be fixed.

@drvinceknight
Copy link
Member

Was there an update made to test/unit/test_tournament.py before version 2.11 was released? If so, I just have to do a rebase and it should be fixed.

I don't believe so but rebasing anyway sounds like a good idea. Then you can run the full test locally python -m unittest discover from the master branch and this branch.

@drvinceknight
Copy link
Member

I've just confirmed that all tests on master pass (locally).

@drvinceknight
Copy link
Member

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.

@drvinceknight
Copy link
Member

This brings up the failure:

python -m unittest axelrod.tests.unit.test_tournament.TestProbEndingSpatialTournament

@drvinceknight
Copy link
Member

The error seems to be something to do with the Final transformer not working when there sequence passed has length 1.

# Otherwise play previous move
return self.history[-1]

@FinalTransformer(D, name_prefix=None)
Copy link
Member

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).


name = 'Alexei'
classifier = {
'memory_depth': 1,
Copy link
Member

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).

# Otherwise play previous move
return self.history[-1]

@FinalTransformer((D, ) name_prefix=None)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(D,) (no space)

@drvinceknight
Copy link
Member

The error seems to be something to do with the Final transformer not working when there sequence passed has length 1.

For the record: this was not the issue, the transformer works exactly as expected.

# Otherwise play previous move
return self.history[-1]

@FinalTransformer((D,) name_prefix=None)
Copy link
Member

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

@souravsingh
Copy link
Contributor Author

@drvinceknight I have made the fixes. Can you review and suggest any more changes?

Copy link
Member

@drvinceknight drvinceknight left a 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/
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Member

@drvinceknight drvinceknight left a 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)]
Copy link
Member

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)]
Copy link
Member

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)]
Copy link
Member

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)]
Copy link
Member

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])
Copy link
Member

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])
Copy link
Member

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)]
Copy link
Member

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.

@drvinceknight
Copy link
Member

This looks great to me. Thanks @souravsingh 👍

@meatballs meatballs merged commit cb3bccc into Axelrod-Python:master May 10, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants