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

TidemanAndChieruzzi strategy #1118

Merged
merged 8 commits into from
Aug 16, 2017

Conversation

dmanc
Copy link
Contributor

@dmanc dmanc commented Aug 13, 2017

This is the implementation of Tideman and Chieruzzi's strategy from Axelrod's first tournament.
Resolves #1105.

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 this: a quick scan looks good! I'll review properly tomorrow.

The tests on travis are failing because of the dosctring formatting.

1. Every run of defections played by the opponent increases the number of
defections that this strategy retaliates with by 1.
2. The opponent is given a ‘fresh start’ if:
- it is 10 points behind this strategy
Copy link
Member

Choose a reason for hiding this comment

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

Need a space between this line and 2. The opponent is

- and it has been at least 20 rounds since the last ‘fresh start’
- and there are more than 10 rounds remaining in the tournament
- and the total number of defections differs from a 50-50 random sample
by at least 3.0 standard deviations.
Copy link
Member

Choose a reason for hiding this comment

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

This needs to be at the same level of indentation as the previous line:

+        - and the total number of defections differs from a 50-50 random sample
           by at least 3.0 standard deviations.

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 is looking fantastic and my requests are minor doc changes (you've understandably grabbed what was in the issue but I perhaps should have written that a tiny bit better) and a few more tests please.


class TidemanAndChieruzzi(Player):
"""
This strategy begins by playing Tit For Tat and then things get slightly
Copy link
Member

Choose a reason for hiding this comment

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

Change and then things get slightly complicated to and then follows the following rules

- it is 10 points behind this strategy
- and it has not just started a run of defections
- and it has been at least 20 rounds since the last ‘fresh start’
- and there are more than 10 rounds remaining in the tournament
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 match

'retaliation_length': 4,
'retaliation_remaining': 1})


Copy link
Member

Choose a reason for hiding this comment

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

To be a slight pain (this strategy really is excellently written), could we add a couple more tests please:

  • Check the standard deviation condition (test similar actions where one is and one isn't within bounds)
  • Check the self.fresh_start attribute

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the description of the strategy

and the total number of defections differs from a 50-50 random sample by at least 3.0 standard deviations.

I implemented this as if self.defections <= lower or self.defections >= upper:
But I am now question what "total defections" means, would it be self.defections + opponent.defections?

Copy link
Member

Choose a reason for hiding this comment

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

I agree that the wording is not completely clear but I am 99.9% sure that the way you have interpreted/implemented it is correct.

It makes sense to check the behaviour of the opponent.

@drvinceknight
Copy link
Member

This looks great. Thanks 👍

One final request from me (sorry I should have realised this earlier). Can you modify https://github.com/Axelrod-Python/Axelrod/blob/master/docs/reference/overview_of_strategies.rst to show that this is now implemented please.

@drvinceknight
Copy link
Member

Thanks this looks good to me 👍


if valid_fresh_start:
valid_points = self.current_score - self.opponent_score >= 10
valid_rounds = self.match_attributes['length'] - current_round >= 10
Copy link
Member

Choose a reason for hiding this comment

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

What will happen if length is not supplied?

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 did not consider this but I just tried the strategy in a probabilistic ending tournament and self.match_attributes['length'] evaluated to inf. When would the length not be supplied?

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 dealt with this the correct way. When a length is not supplied the match tells the players that it's infinite (we have a few players that do this). 👍

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 add a test where we don't tell the match length to the players?

Similar to the test for Alexei in this file: https://github.com/Axelrod-Python/Axelrod/blob/master/axelrod/tests/strategies/test_titfortat.py

Copy link
Member

Choose a reason for hiding this comment

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

Except go for match_attributes={"length": float('inf')}, that's essentially equivalent to -1 but more readable (I'll probably open a PR to that test file and change it #1120).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wouldn't the behavior be different if I use -1?
valid_rounds = self.match_attributes['length'] - current_round >= 10 would be true if length was float('inf') and false if length was -1.

Copy link
Member

Choose a reason for hiding this comment

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

Yup you're correct. float('inf') is the correct choice here: in essence if match length is not known then that corresponds to an infinite match length from the point of view of the strategy.

In this case: are we within ten turns of the end? Probably not: we don't know when the end is. So it's essentially going to assume there is always more than 10 rounds remaining.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright thanks, i'll make a quick change to the test.

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.

Just the one extra request for a test with match_attributes={"length": float('inf')} please (ideally showing a change in behaviour).

# Similar to the last test except the length is not given.
opponent = axelrod.Cycler('DDCDD')
self.versus_test(opponent, expected_actions=actions,
match_attributes={'length': float('inf')})
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 a way to devise a test where the play plays differently when the match length is not given? Or even if the actions are the same, are the attrs different?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I can change this test so with 15 rounds of play this strategy will give a fresh start on the last two rounds when the length is not given. Otherwise if the length was 15 it would defect on the last two rounds.

Copy link
Member

Choose a reason for hiding this comment

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

Perfect!

@drvinceknight
Copy link
Member

Perfect! Thanks 👍

@drvinceknight drvinceknight merged commit dd0bb42 into Axelrod-Python:master Aug 16, 2017
@dmanc dmanc deleted the TidemanAndChieruzzi branch August 17, 2017 03:33
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.

None yet

3 participants