From d1305bc879b264cc5e4d10982769e8327cfe33d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Fri, 4 May 2018 17:45:16 +0200 Subject: [PATCH] Add step_next trigger to LinearFSM allowing stateless stepping --- lib/tfw/linear_fsm.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/tfw/linear_fsm.py b/lib/tfw/linear_fsm.py index 274bf52..2728655 100644 --- a/lib/tfw/linear_fsm.py +++ b/lib/tfw/linear_fsm.py @@ -5,14 +5,18 @@ from .fsm_base import FSMBase class LinearFSM(FSMBase): + # pylint: disable=anomalous-backslash-in-string """ This is a state machine for challenges with linear progression, consisting of - a number of steps specified in the constructor. It automatically sets up a single - action between states as such: - 0 ==step_1==> 1 ==step_2==> 2 ==step_3==> 3 ... and so on + a number of steps specified in the constructor. It automatically sets up 2 + actions (triggers) between states as such: + (0) -- step_1 --> (1) -- step_2 --> (2) -- step_3 --> (3) ... and so on + \-step_next-/ \-step_next-/ \-step_next-/ """ def __init__(self, number_of_steps): self.states = list(map(str, range(number_of_steps))) - self.transitions = [{'trigger': f'step_{int(index)+1}', 'source': index, 'dest': str(int(index)+1)} - for index in self.states[:-1]] + self.transitions = [] + for index in self.states[:-1]: + self.transitions.append({'trigger': f'step_{int(index)+1}', 'source': index, 'dest': str(int(index)+1)}) + self.transitions.append({'trigger': 'step_next', 'source': index, 'dest': str(int(index)+1)}) super(LinearFSM, self).__init__()