Skip to content

Commit c14a9eb

Browse files
committed
Adding a reset method to FSM.
The test checks that the reset method changes the value of the state.
1 parent 6137332 commit c14a9eb

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

axelrod/strategies/finite_state_machines.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def __init__(self, transitions=None, initial_state=None, initial_action=None):
5454
initial_state = 1
5555
initial_action = C
5656
Player.__init__(self)
57+
self.initial_state = initial_state
5758
self.initial_action = initial_action
5859
self.fsm = SimpleFSM(transitions, initial_state)
5960

@@ -67,6 +68,10 @@ def strategy(self, opponent):
6768
self.state = self.fsm.state
6869
return action
6970

71+
def reset(self):
72+
Player.reset(self)
73+
self.fsm.state = self.initial_state
74+
7075

7176
class Fortress3(FSMPlayer):
7277
"""Finite state machine player specified in DOI:10.1109/CEC.2006.1688322.

axelrod/tests/unit/test_finite_state_machines.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@ def test_transitions(self):
111111
fsm = player.fsm
112112
self.assertTrue(check_state_transitions(fsm.state_transitions))
113113

114+
def test_reset_initial_state(self):
115+
player = self.player()
116+
player.fsm.state = -1
117+
player.reset()
118+
self.assertFalse(player.fsm.state == -1)
119+
114120

115121
class TestFortress3(TestFSMPlayer):
116122

0 commit comments

Comments
 (0)