Skip to content

Commit

Permalink
Moving how the reset method works - now does not reset score
Browse files Browse the repository at this point in the history
  • Loading branch information
drvinceknight committed Feb 20, 2015
1 parent 6849fbc commit 63eaa85
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 36 deletions.
9 changes: 4 additions & 5 deletions axelrod/strategies/grumpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def strategy(self, opponent):
Won't become nice once that grumpy threshold is hit, but must reach a much lower threshold before it becomes nice again.
"""

self.grumpiness = sum(play=='D' for play in opponent.history) - sum(play=='C' for play in opponent.history)
self.grumpiness = sum(play=='D' for play in opponent.history) - sum(play=='C' for play in opponent.history)

if self.state == 'Nice':
if self.grumpiness > self.grumpy_threshold:
Expand All @@ -37,16 +37,15 @@ def strategy(self, opponent):
self.state = 'Nice'
return 'C'
return 'D'

def reset(self):
"""
Resets score, history and state for the next round of the tournement
"""

self.history = []
self.score = 0
self.state = self.starting_state

def __repr__(self):
"""
The string method for the strategy:
Expand Down
4 changes: 1 addition & 3 deletions axelrod/tests/test_grumpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,8 @@ def test_reset_method(self):
"""
P1 = axelrod.Grumpy(starting_state = 'Grumpy')
P1.history = ['C', 'D', 'D', 'D']
P1.score = 5
P1.state = 'Nice'
P1.reset()
self.assertEqual(P1.history, [])
self.assertEqual(P1.score, 0)
self.assertEqual(P1.state, 'Grumpy')

15 changes: 0 additions & 15 deletions axelrod/tests/test_tournament.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,21 +106,6 @@ def test_tournament(self):
('Grudger', [2001, 2001, 2001, 2001, 2001]),
('Go By Majority', [2001, 2001, 2001, 2001, 2001])]))

def test_reset_players(self):
"""
Test that method to reset scores in between repetitions of tournament works
"""
P1 = axelrod.Defector()
P1.score = 58
P1.history = ['C', 'C', 'D']
P2 = axelrod.Defector()
P2.score = 95
P2.history = ['C', 'D', 'D']
tournament = axelrod.Axelrod(P1, P2)
tournament.reset_players()
self.assertEqual([0, 0],[player.score for player in tournament.players])
self.assertEqual([[], []],[player.history for player in tournament.players])

def test_calculate_score_for_mix(self):
"""
Test that scores are calculated correctly
Expand Down
19 changes: 6 additions & 13 deletions axelrod/tournament.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ def round_robin(self, turns=200):
"""
for p1, p2 in itertools.combinations(self.players, 2):
turn = 0
p1.history = []
p2.history = []
p1.reset()
p2.reset()
while turn < turns:
turn += 1
p1.play(p2)
Expand All @@ -49,19 +49,12 @@ def tournament(self, turns=200, repetitions=10):
"""
dic = {player:[] for player in self.players}
for repetition in range(repetitions):
self.reset_players()
self.round_robin(turns=200)
for player in self.players:
dic[player].append(player.score)
dic[player].append(player.score) # Record score
player.score = 0 # Reset score
return dic

def reset_players(self):
"""
Resets all the player histories
"""
for player in self.players:
player.reset()

def calculate_scores(self, p1, p2):
"""
Calculates the score for two players based their history and on following:
Expand Down Expand Up @@ -110,7 +103,7 @@ class inheritance).

def reset(self):
"""
Resets scores and history
Resets history.
When creating strategies that create new attributes then this method should be re-written (in the inherited class) and should not only reset history but also rest all other attributes.
"""
self.history = []
self.score = 0
Binary file modified results.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 63eaa85

Please sign in to comment.