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

3 New Strategies From the PRISON (http://www.lifl.fr/IPD/ipd.frame.html) #715

Merged
merged 10 commits into from
Sep 20, 2016

Conversation

geraintpalmer
Copy link
Member

EasyGo
GrudgerAlternator
GradualKiller

@geraintpalmer
Copy link
Member Author

Hi! Just looked at Issue #379 and implemented 3 new strategies. Hope this helps 😄

"""
It begins by defecting in the first five moves, then cooperates two times.
It then defects all the time if the opponent has defected in move 6 and 7,
else cooperates all the time.
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 a sentence here saying that this is designed to stop Gradual from winning? (And possibly why?)

if len(self.history) < 7:
return firstseven[len(self.history)]
# React to the opponent's 6th and 7th moves
elif opponent.history[5:7] == [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.

This can just be an if statement.

Copy link
Member Author

Choose a reason for hiding this comment

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

We've spoken, it must be elif


class GrudgerAlternator(Player):
"""
A player starts by cooperating until the first opponents defenction,
Copy link
Member

Choose a reason for hiding this comment

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

"defection"


Names:

- c_then_per_dc: [PRISON1998]_
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 also add GrudgerAlternator to this list?


class EasyGo(Player):
"""
A player starts by defecting however will cooperate if at any point the opponent has defected.
Copy link
Member

Choose a reason for hiding this comment

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

if the opponent

Copy link
Member

Choose a reason for hiding this comment

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

Ignore this.

@@ -18,3 +18,4 @@ documentation.
.. [Stewart2012] Stewart, a. J., & Plotkin, J. B. (2012). Extortion and cooperation in the Prisoner’s Dilemma. Proceedings of the National Academy of Sciences, 109(26), 10134–10135. http://doi.org/10.1073/pnas.1208087109
.. [Szabó1992] Szabó, G., & Fáth, G. (2007). Evolutionary games on graphs. Physics Reports, 446(4-6), 97–216. http://doi.org/10.1016/j.physrep.2007.04.004
.. [Tzafestas2000] Tzafestas, E. (2000). Toward adaptive cooperative behavior. From Animals to Animals: Proceedings of the 6th International Conference on the Simulation of Adaptive Behavior {(SAB-2000)}, 2, 334–340.
.. [PRISON1998] LIFL (1998) PRISON. Available at: http://www.lifl.fr/IPD/ipd.frame.html (Accessed: 19 September 2016).
Copy link
Member

Choose a reason for hiding this comment

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

Is there no academic reference?

expected_response = [D if r % 2 == 0 else C for r in range(j)]
self.responses_test(my_hist, opp_hist, expected_response)


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 get rid of the extra lines? Should be 2.

def strategy(self, opponent):
"""This is the actual strategy"""
# First seven moves
firstseven = [D, D, D, D, D, C, 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 have the @initial_sequence decorator to handle this

# return D
# return C

if len(self.history) >= 7:
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 this condition is redundant now that the decorator is being used

Copy link
Member Author

Choose a reason for hiding this comment

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

Wouldn't this line:

if opponent.history[5:7] == [D, D]:

not break before the 7th round?

Copy link
Member

Choose a reason for hiding this comment

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

The decorator should override it in the early turns. Try it!

Copy link
Member Author

Choose a reason for hiding this comment

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

You're right! 👍

Copy link
Member

Choose a reason for hiding this comment

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

I try to be once a month or so!

Copy link
Member

@marcharper marcharper left a comment

Choose a reason for hiding this comment

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

Looks good pending the tests all passing, thanks!

}

def strategy(self, opponent):
"""This is the actual strategy"""
Copy link
Member

Choose a reason for hiding this comment

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

Please delete this line and the commented lines below.

Names:

- c_then_per_dc: [PRISON1998]_
- GrudgerAlternator
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 make this something like:

- Grudger Alternator: Original name by Geraint Palmer

Or whatever self attribution you would like to use?

@drvinceknight drvinceknight merged commit 419ca25 into Axelrod-Python:master Sep 20, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants