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

New Strategy From the PRISON (http://www.lifl.fr/IPD/ipd.frame.html) #724

Merged
merged 13 commits into from
Sep 28, 2016

Conversation

AdamPohl
Copy link
Member

@AdamPohl AdamPohl commented Sep 25, 2016

Implemented Worse and Worse strategy as suggested in #379 and Knowledgeable Worse and Worse which I started during the PyconUK Axelrod sprint. This pr is the same as #720 but now hopefully the appveyer test should pass

@AdamPohl
Copy link
Member Author

AdamPohl commented Sep 25, 2016

I have absolutely no idea as to why the tests are failing, could it be because I am using sys.version_info in my test function? 😞 😕 😖

@drvinceknight
Copy link
Member

The error messages indicate that you haven't quite coded your strategy right for the case when match lengths are not known by the players.

There should not be a need to use sys.version either.

I will look through this today and fix it.

@drvinceknight
Copy link
Member

drvinceknight commented Sep 26, 2016

I've opened AdamPohl#1 to your branch @Huaraz2.

However, I'm not actually sure this is the correct strategy. I couldn't find this strategy at http://www.lifl.fr/IPD/ipd.frame.html and looking through what I could find in the literature I can't seem to find any details (please point me towards them though).

@AdamPohl
Copy link
Member Author

Thanks for the pr @drvinceknight, I found this strategy in the classics.str file in the prison package that you can get from the downloads page in the link I have attached to this pr. As far as I understood it, each mactch in the tournament would last for 1000 turns, so I read the strategy as: it defects with probability of current_turn / expected_length. I now do not think this is the case and therefore will rename this one to WorseAndWorseRandom and make WorseAndWorse for real.

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.

Thanks for clarifying the source. I've got a couple of change requests but this is looking like it's on the right road. 👍

class WorseAndWorse (Player):
"""
Defects with probability of 'current turn / 1000'. Therefore
it is more and more likely to defect as the round goes on.
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:

Source code available at the download tab of [PRISON1998].

Copy link
Member Author

Choose a reason for hiding this comment

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

Would this line go at the end of line 10 or do you want it as part of the names section?

Copy link
Member

Choose a reason for hiding this comment

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

In between line 10 and the names section. So:

Defects with probability ...
is more likely ...

Source code available ...

Names...

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for the clarification, I have now made this change.


def strategy(self, opponent):
current_round = len(self.history) + 1
if random.randint(0, 1000) < current_round:
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 rewrite this so that it's like the other strategy? IE so that is uses random_choice:

        probability = 1 - float(current_round) / 1000
        return random_choice(probability)

When you do that you can remove the import random at the top of this file.

return C


class WorseAndWorseRandom (Player):
Copy link
Member

Choose a reason for hiding this comment

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

Not a fan of this name: it makes it sound like WorseAndWorse is not random. As this is a version of WorseAndWorse that has some knowledge I suggest you call it KnowledgeableWorseAndWorse.

"""
This strategy is based of 'Worse And Worse' but will defect with probability
of 'current turn / total no. of turns'.

Copy link
Member

@drvinceknight drvinceknight Sep 27, 2016

Choose a reason for hiding this comment

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

This still needs a names section:

    Names:
        - Knowledgeable Worse and Worse: Original name by Adam Phol

opponent = axelrod.Cooperator()
player = axelrod.WorseAndWorse()
match = axelrod.Match((opponent, player), turns=5)
self.assertEqual(match.play(), [('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.

Once you've made the expected change, this might change but either way it would be good if you picked a seed that didn't just have WorseAndWorse cooperate (ie choose one that gives a mix of C and D). Change the strategy first though.

@@ -120,6 +123,6 @@ Here are the docstrings of all the strategies in the library.
.. automodule:: axelrod.strategies.titfortat
:members:
:undoc-members:
.. automodule:: axelrod.strategies.gradualkiller
Copy link
Member

Choose a reason for hiding this comment

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

Do not delete gradualkiller.

Copy link
Member Author

Choose a reason for hiding this comment

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

I didn't, if you look further up you will see that I moved it so that the list was in alphabetical order again.

Copy link
Member

Choose a reason for hiding this comment

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

Ah great: my mistake :) 👍

@@ -10,11 +8,12 @@ class WorseAndWorse (Player):
it is more and more likely to defect as the round goes on.

Names:
- worse_and_worse: [PRISON1998]
- worse_and_worse: Source code available at the download tab of
[PRISON1998].
Copy link
Member

@drvinceknight drvinceknight Sep 27, 2016

Choose a reason for hiding this comment

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

Does this indent render ok? (you can run make html to check from the docs directory, you might have to pip install a sphinx theme...)

I think the rst syntax should be:

        - worse_and_worse: Source code available at the download tab of
          [PRISON1998].

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.

Nearly there as far as I am concerned.


class KnowledgeableWorseAndWorse (Player):
"""
This strategy is based of 'Worse And Worse' but will defect with probability
Copy link
Member

Choose a reason for hiding this comment

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

Typo: should be 'is based on'

Copy link
Member Author

@AdamPohl AdamPohl Sep 28, 2016

Choose a reason for hiding this comment

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

Thanks, I have now made these changes



Names:
- worse_and_worse: [PRISON1998].
Copy link
Member

@drvinceknight drvinceknight Sep 28, 2016

Choose a reason for hiding this comment

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

You need the _ at the end of the [PRISON1998]. So this should be [PRISON1998]_ same for the one above (line 10).

Also can you change it to be:

- Worse and Worse: [PRISON1998]_

@@ -195,12 +195,14 @@
Willing,
WinShiftLoseStay,
WinStayLoseShift,
WorseAndWorse,
KnowledgeableWorseAndWorse,
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 put this in alphabetical order please.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

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.

This now looks good to me. We have a two core reviewer policy so it needs to be checked through by someone else. Thanks for your work on it :)

@AdamPohl
Copy link
Member Author

Thanks Vince, it's been fun 👍

@meatballs meatballs merged commit cb4d840 into Axelrod-Python:master Sep 28, 2016
@AdamPohl AdamPohl deleted the WorseAndWorse branch September 28, 2016 14:40
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.

3 participants