Skip to content
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

[MRG] Add Resurrection Strategy #865

Merged
merged 17 commits into from
Mar 1, 2017
Merged

[MRG] Add Resurrection Strategy #865

merged 17 commits into from
Mar 1, 2017

Conversation

souravsingh
Copy link
Contributor

No description provided.

C, D = Actions.C, Actions.D


class TitForTat(Player):
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 named this incorrectly.

The class will also need tests.

@souravsingh
Copy link
Contributor Author

Travis seems to error due to this line- https://github.com/Axelrod-Python/Axelrod/pull/865/files#diff-ac262d93edeeeaa83660b643a34b6580R35.

Is there a fix for this?

@drvinceknight
Copy link
Member

Yes the error is occurring because your strategy logic is not quite correct:

+        if self.history:
 +            return C
 +        if len(self.history) >= 5 and self.history[-5:] == [D,D,D,D,D]:
 +            return D
 +        else:
 +            return opponent.history[-1]

That first line if self.history will pass as True if self.history is not empty which implies that if there is no history then you pass on to the next set of statements which in turn leads to return opponent.history[-1] however as there is no history, this creates an error.

I believe you want:

+        if len(self.history) == 0:
 +            return C
 +        if len(self.history) >= 5 and self.history[-5:] == [D,D,D,D,D]:
 +            return D
 +        else:
 +            return opponent.history[-1]

@souravsingh
Copy link
Contributor Author

Thanks a lot @drvinceknight

@souravsingh
Copy link
Contributor Author

The tests for the strategy pass.

@souravsingh
Copy link
Contributor Author

@marcharper I need some help in finishing the PR.

@drvinceknight
Copy link
Member

@marcharper I need some help in finishing the PR

The tests are currently failing because of the doctests, you need to update the relevant docs:.

======================================================================
FAIL: ./docs/tutorials/advanced/classification_of_strategies.rst
Doctest: classification_of_strategies.rst
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/opt/python/3.5.2/lib/python3.5/doctest.py", line 2190, in runTest
    raise self.failureException(self.format_failure(new.getvalue()))
AssertionError: Failed doctest test for classification_of_strategies.rst
  File "./docs/tutorials/advanced/classification_of_strategies.rst", line 0
----------------------------------------------------------------------
File "./docs/tutorials/advanced/classification_of_strategies.rst", line 59, in classification_of_strategies.rst
Failed example:
    len(strategies)
Expected:
    27
Got:
    28
----------------------------------------------------------------------
File "./docs/tutorials/advanced/classification_of_strategies.rst", line 71, in classification_of_strategies.rst
Failed example:
    len(strategies)
Expected:
    48
Got:
    49

@souravsingh
Copy link
Contributor Author

souravsingh commented Feb 24, 2017

Done! Fixed the Errors!

@souravsingh souravsingh changed the title Add Resurrection Strategy [MRG] Add Resurrection Strategy Feb 25, 2017

class Resurrection(Player):
"""
A player starts by cooperating and defects if the the number of rounds
Copy link
Member

Choose a reason for hiding this comment

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

minor: "the the"

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 mention that the strategy plays like TFT otherwise?

#Check if turns played are less than 5.
self.responses_test([C], [D, C, D, C], [C] * 4)


Copy link
Member

Choose a reason for hiding this comment

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

Can we add two tests for TFT behaviors after five rounds, and one for more than five rounds, with four defections and a cooperation by the opponent?

Copy link
Contributor Author

@souravsingh souravsingh Feb 26, 2017

Choose a reason for hiding this comment

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

@marcharper Just to confirm- For first test, the player_history=[C,C,C,C,C,C] and opponent_history=[C,C,C,C,C,D]
And for second test- the player_history=[C,C,C,C,C] and opponent_history=[C,D,D,D,D], correct?

@marcharper
Copy link
Member

@souravsingh Just a request for a few more tests, otherwise it's looking good to me.

played by the player is greater than five and last five rounds are defections.
Otherwise, the strtategy plays like Tit-for-tat.
Copy link
Member

Choose a reason for hiding this comment

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

"strategy"

@souravsingh
Copy link
Contributor Author

Is the patch ready for merging?

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.

Sorry for taking a little while to get back to this, just two very minor things from me.

def strategy(self, opponent: Player) -> Action:
if len(self.history) == 0:
return C
if len(self.history) >= 5 and self.history[-5:] == [D,D,D,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.

Very minor: could you tidy the PEP8 here: [D, D, D, D, D].

class Resurrection(Player):
"""
A player starts by cooperating and defects if the number of rounds
played by the player is greater than five and last five rounds are defections.
Copy link
Member

Choose a reason for hiding this comment

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

and the last five rounds

@drvinceknight
Copy link
Member

Also, can you add this module to the index of strategies (so that it's automatically indexed). See http://axelrod.readthedocs.io/en/latest/tutorials/contributing/strategy/adding_the_new_strategy.html:

Finally, if you have created a new module (a new <strategy.py> file) please add it to the docs/references/all_strategies.rst file so that it will automatically be documented.

@meatballs meatballs merged commit 19779ab into Axelrod-Python:master Mar 1, 2017
@souravsingh souravsingh deleted the add-strategy branch March 2, 2017 00:14
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