-
Notifications
You must be signed in to change notification settings - Fork 262
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
Implemented K32R by Charles Kluepfel. #1138
Conversation
Strategy submitted to Axelrod's second tournament by Charles Kluepfel (K32R).
Forgot to include in earlier commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good!
Just some initial comments for now after an initial pass through, we'll need to also confirm the logic is correct and corresponds to the Fortran code.
At the moment there are a few things failing in the test suite outside of the unit tests you have written (which look good!):
-
All the documentation is tested and the
74
stochastic strategies in this file (https://github.com/Axelrod-Python/Axelrod/blob/master/docs/tutorials/advanced/classification_of_strategies.rst) would need to be bumped to75
. -
There is a family of strategies that makes use of other strategies. In this case it's using this strategy and needs to update it's test. In this file: https://github.com/Axelrod-Python/Axelrod/blob/master/axelrod/tests/strategies/test_meta.py at line 338 we need
actions
to be:[(C, C), (C, D), (C, C), (C, D), (D, C)]
-
We will need to update the documentation for the second tournament in this file https://github.com/Axelrod-Python/Axelrod/blob/master/docs/reference/overview_of_strategies.rst to point at this strategy (there's a table in there.
I've pointed at something wrong with the rest syntax in the docstring which is currently broken but there might be one or two other things :) (No big deal we'll figure them out.)
As I mentioned on gitter: make these changes and commit them and then push to your fork, that'll automatically update here :)
axelrod/strategies/axelrod_second.py
Outdated
player decides that the opponent is random if | ||
C1 >= (C1+C2)/2 - 1.5*sqrt(C1+C2)/2 AND | ||
C4 >= (C3+C4)/2 - 1.5*sqrt(C3+C4)/2. | ||
If the player decides that she is playing against a random player, then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gender neutral: "they will" or "the player will".
axelrod/strategies/axelrod_second.py
Outdated
If the player decides that she is playing against a random player, then | ||
she will always defect. | ||
|
||
Otherwise, she will use a straight-forward set of rules: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gender neutral.
axelrod/strategies/axelrod_second.py
Outdated
Otherwise, she will use a straight-forward set of rules: | ||
- If opponent's last three choices are the same, then respond in kind. | ||
- If opponent's last two choices are the same, then respond in kind with | ||
probability 90%. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these are currently breaking the formatting of the documentation: the second line needs to start at the same level as the If
:
- If opponent's last two choices are the same, then respond in kind with
probability 90%.
axelrod/strategies/axelrod_second.py
Outdated
def __init__(self): | ||
super().__init__() | ||
self.C1, self.C2, self.C3, self.C4 = 0, 0, 0, 0 | ||
# These are defined by opponent's reaction to player (me) according to: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to repeat this.
axelrod/strategies/axelrod_second.py
Outdated
return D | ||
|
||
# Otherwise, straight-forward strategy | ||
r = random.random() # Will use later |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's move the r = random.random()
to line 559 so this random sample only happens if it's necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do. Changing test file too.
axelrod/strategies/axelrod_second.py
Outdated
# Otherwise, straight-forward strategy | ||
r = random.random() # Will use later | ||
|
||
# Use the defaults from Python |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain what you mean by this?
self.versus_test(axelrod.Alternator(), expected_actions=actions, seed=3) | ||
|
||
# Now we have to test the detect-random logic, which doesn't pick up | ||
# until after 26 trips. So we need a big sample. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
turns
axelrod/strategies/axelrod_second.py
Outdated
- Otherwise if opponent's last action was to defect, then defect | ||
with probability 60%. | ||
|
||
Names: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Blank line after Names
please.
axelrod/strategies/axelrod_second.py
Outdated
|
||
I did: | ||
Def Coop | ||
She does: Coop C1 | C3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gender neutral please. Go with player
for your current I
and opponent
for your current she
. Although it's probably also worth changing this to a bullet point list (only because the rest syntax can be troublesome at times). I'd suggest:
This player keeps track of the the opponent's responses to own behavior:
- C1 counts: Opponent cooperates as response to player defecting.
- C2 counts: Opponent defects as response to player defecting.
- C3 counts: Opponent cooperates as response to player cooperating.
- C4 counts: Opponent defects as response to player cooperating.
Could we however change these variable names (unless there's a good reason) to be more explicit. Perhaps:
- `cd_count` counts: Opponent cooperates as response to player defecting.
- `dd_count` counts: Opponent defects as response to player defecting.
- `cc_count` counts: Opponent cooperates as response to player cooperating.
- `dc_count` counts: Opponent defects as response to player cooperating.
Was only using this for sqrt. Seemed like it was causing problems, so I replaced with half powers.
Thanks for all the feedback. I made changes to the code, and will work on documentation for the second tournament a little later. I'm not sure I understand the issue with test_meta.py... |
There's a strategy in
So in the third round the expected action is
|
I have run fingerprints of this implementation and >>> import axelrod as axl
>>> import axelrod_fortran as axlf
>>> fortran_player = axlf.Player("k32r")
>>> axl_player = axl.Kluepfel()
>>> repetitions = 10000
>>> fortran_player, axl_player, repetitions
(Player: k32r, libstrategies.so, Kluepfel, 10000) >>> axl_tf = axl.TransitiveFingerprint(axl_player)
>>> axl_tf.fingerprint(repetitions=repetitions, processes=0)
>>> axl_tf.plot(); >>> fortran_tf = axl.TransitiveFingerprint(fortran_player)
>>> fortran_tf.fingerprint(repetitions=repetitions, processes=0)
>>> fortran_tf.plot(); >>> opponents = [s() for s in axl.basic_strategies]
>>> axl_tf_v_basic = axl.TransitiveFingerprint(axl_player, opponents=opponents)
>>> axl_tf_v_basic.fingerprint(repetitions=repetitions, processes=0)
>>> axl_tf_v_basic.plot(display_names=True); >>> fortran_tf_v_basic = axl.TransitiveFingerprint(fortran_player, opponents=opponents)
>>> fortran_tf_v_basic.fingerprint(repetitions=repetitions, processes=0)
>>> fortran_tf_v_basic.plot(display_names=True); Before merging having someone else double check the logic would be great but this is looking good to me 👍 |
Re a7a6c1b
Using |
axelrod/strategies/axelrod_second.py
Outdated
|
||
After 26 turns, the player then tries to detect a random player. The | ||
player decides that the opponent is random if | ||
C1 >= (C1+C2)/2 - 1.5*sqrt(C1+C2)/2 AND |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These (and anywhere else) needs to be updated to cd_count, ...
In the future is this something I should run when making a strategy? |
So in the third round the expected action is (D, C) however when making use of your strategy MetaLongMemory in fact cooperates in the third round so that line just needs to be changed.
Sorry. I'm still trying to figure out this test piece. I ran unittest discover on my end and was able to get the same error, and I can see that making the change fixes it. But it looks like this test gets run for every infinite memory ordinary strategy. How come changing this code doesn't break other strategies? [I think that maybe the unittest detects changed code, but then will this break future changes? I don't see why we should expect all infinite memory ordinary strategies to have this expected action.] |
Edited in wrong place before.
Added blank lines around bulleted lists.
Alright. I think I've fixed everything. Please let me know if anything else needs to be fixed. Thanks again for the help. |
That's not quite what's happening. For info:
So with the addition of your strategy to the team, the majority of the players in this third round turns out to be Don't worry too much if that's still unclear, essentially these meta players are black boxes and their tests are more regression tests than anything else. Sometimes when adding new strategies their behaviour (and so their tests) changes :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just the one very minor comment about an inline comment I don't understand but otherwise this looks great to me.
As well as running the fingerprints, I have worked through the logic and I'm happy this has been implemented correctly.
axelrod/strategies/axelrod_second.py
Outdated
|
||
# Otherwise respond to recent history | ||
|
||
# Use the defaults from Python |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand what this inline comment is saying. Perhaps remove?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, I'll remove it.
If you could that would be super helpful. Depending on how much cpu time you have free feel free to run them with less repetitions. |
Excellent Job @gaffney2010 Thank you very much indeed! |
Strategy submitted to Axelrod's second tournament by Charles Kluepfel (K32R).