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

Track CC, CD, DC, DD in Player class #752

Merged
merged 6 commits into from
Nov 2, 2016

Conversation

mturzanska
Copy link

Related to #744

Add play_counts property to Player class (a dictionary counting occurrences of CC, CD, DC, DD).
Update the dictionary after each play.
Add tests for the property.

TODO:
Use play_counts property in existing strategies (e.g. Prober4, Retaliate)

margaret added 2 commits October 23, 2016 14:48
Initialize Player class with an empty dictionary of paired moves.
Update the dictionary when calling play method.
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 a bunch for this @mturzanska, two things:

  • a suggested name change for consistency with the rest of the library;
  • a slightly expanded test

@@ -60,6 +64,9 @@ def test_play(self):
self.assertEqual(p1.defections, 0)
self.assertEqual(p2.cooperations, 0)
self.assertEqual(p2.defections, 2)
# Test play counts
self.assertEqual(p1.play_counts, {(C, D): 2})
self.assertEqual(p2.play_counts, {(D, C): 2})
Copy link
Member

Choose a reason for hiding this comment

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

Could we have a couple more tests leading to a 'fuller' dictionary please.

@@ -52,6 +53,12 @@ def update_history(player, move):
player.defections += 1


def update_play_counts(player, move, reply):
Copy link
Member

Choose a reason for hiding this comment

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

In the glossary http://axelrod.readthedocs.io/en/latest/reference/glossary.html#a-play we have defined a play as "a single player choosing an action."

In the results set and the interaction utils we have called these counters "state distributions". Could we call them the same thing here (for consistency).

  • update_state_distribution
  • player_state_distribution

Copy link
Author

Choose a reason for hiding this comment

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

Sure.
Maybe, because the class is already called Player, the property could be called just state_distribution. What do you think would be better?

Copy link
Member

Choose a reason for hiding this comment

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

Yup: that's better than my suggestion :) 👍

@marcharper
Copy link
Member

Since we're counting C and D as well for each player (in attributes cooperations and defections), should we change those to a dictionary as well? (Not necessarily in this PR -- there will be a lot of places that need to change.)

@drvinceknight
Copy link
Member

Since we're counting C and D as well for each player (in attributes cooperations and defections), should we change those to a dictionary as well? (Not necessarily in this PR -- there will be a lot of places that need to change.)

Good idea but yeah: this could/should be another issue.

@drvinceknight
Copy link
Member

Thanks for the changes @mturzanska, this looks good to me now.

@meatballs meatballs merged commit fc9050c into Axelrod-Python:master Nov 2, 2016
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