2018-04-10 10:48:53 +00:00
|
|
|
# Copyright (C) 2018 Avatao.com Innovative Learning Kft.
|
|
|
|
# All Rights Reserved. See LICENSE file for details.
|
|
|
|
|
2018-04-07 13:21:13 +00:00
|
|
|
from .fsm_base import FSMBase
|
|
|
|
|
|
|
|
|
|
|
|
class LinearFSM(FSMBase):
|
2018-05-04 15:45:16 +00:00
|
|
|
# pylint: disable=anomalous-backslash-in-string
|
2018-04-18 17:44:26 +00:00
|
|
|
"""
|
|
|
|
This is a state machine for challenges with linear progression, consisting of
|
2018-05-04 15:45:16 +00:00
|
|
|
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-/
|
2018-04-18 17:44:26 +00:00
|
|
|
"""
|
2018-04-07 13:21:13 +00:00
|
|
|
def __init__(self, number_of_steps):
|
|
|
|
self.states = list(map(str, range(number_of_steps)))
|
2018-05-04 15:45:16 +00:00
|
|
|
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)})
|
2018-04-07 13:21:13 +00:00
|
|
|
super(LinearFSM, self).__init__()
|