Skip to content

Commit e9abbe8

Browse files
committed
Fixed tests and DynamicsTwoTitsForTat strategy
Signed-off-by: FakeNameSE <grantlycee@gmail.com>
1 parent f07bcb7 commit e9abbe8

File tree

2 files changed

+14
-23
lines changed

2 files changed

+14
-23
lines changed

axelrod/strategies/titfortat.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,16 +119,13 @@ class DynamicTwoTitsForTat(Player):
119119

120120
@staticmethod
121121
def strategy(opponent):
122-
# First move
122+
# First move
123123
if len(opponent.history) == 0:
124124
# Make sure we cooporate first turn
125125
return C
126126
if D in opponent.history[-2:]:
127127
# Probability of cooperating regardless
128-
if random_choice(opponent.cooperations / len(opponent.history)):
129-
return C
130-
else:
131-
return D
128+
return random_choice(opponent.cooperations / len(opponent.history))
132129
else:
133130
return C
134131

axelrod/tests/strategies/test_titfortat.py

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -131,25 +131,19 @@ def test_strategy(self):
131131
# First move is to cooperate
132132
self.first_play_test(C)
133133
# Test that it is stochastic
134-
135-
opponent = axelrod.MockPlayer(actions=[D, C, D, D, C])
136-
actions = [(C, D), (C,C), (C,D), (C,D), (C,C)]
137-
self.versus_test(opponent, expected_actions=actions, seed=2)
134+
opponent = axelrod.MockPlayer(actions=[D, C, D, D, C])
135+
actions = [(C, D), (D, C), (C, D), (D, D), (D, C)]
136+
self.versus_test(opponent, expected_actions=actions, seed=1)
137+
# Should respond differently with a different seed
138+
actions = [(C, D), (D, C), (D, D), (D, D), (C, C)]
139+
self.versus_test(opponent, expected_actions=actions, seed=2)
138140

139-
opponent = axelrod.MockPlayer(actions=[D, C, D, D, C])
140-
actions = [(C, D), (C,C), (C,D), (C,D), (D,C)]
141-
self.versus_test(opponent, expected_actions=actions, seed=13)
142-
143-
## Will cooperate if opponent cooperates.
144-
#actions = [(C, C), (C, C), (C, C), (C, C), (C, C)]
145-
#self.versus_test(axelrod.Cooperator(), expected_actions=actions)
146-
## Will defect twice when last turn of opponent was defection.
147-
#opponent = axelrod.MockPlayer(actions=[D, C, C, D, C])
148-
#actions = [(C, D), (D, C), (D, C), (C, D), (D, C)]
149-
#self.versus_test(opponent, expected_actions=actions)
150-
## Test against defector
151-
#actions = [(C, D), (D, D), (D, D), (D, D), (D, D)]
152-
#self.versus_test(axelrod.Defector(), expected_actions=actions)
141+
# Will cooperate if opponent cooperates.
142+
actions = [(C, C), (C, C), (C, C), (C, C), (C, C)]
143+
self.versus_test(axelrod.Cooperator(), expected_actions=actions)
144+
# Test against defector
145+
actions = [(C, D), (D, D), (D, D), (D, D), (D, D)]
146+
self.versus_test(axelrod.Defector(), expected_actions=actions)
153147

154148
class TestBully(TestPlayer):
155149

0 commit comments

Comments
 (0)