mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-09 01:27:17 +00:00
32 lines
1.1 KiB
Python
32 lines
1.1 KiB
Python
# Copyright (C) 2018 Avatao.com Innovative Learning Kft.
|
|
# All Rights Reserved. See LICENSE file for details.
|
|
|
|
from transitions import State
|
|
|
|
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 2
|
|
actions (triggers) between states as such:
|
|
(0) -- step_1 --> (1) -- step_2 --> (2) -- step_3 --> (3) ... and so on
|
|
"""
|
|
def __init__(self, number_of_steps):
|
|
self.states = [State(name=str(index)) for index in range(number_of_steps)]
|
|
self.transitions = []
|
|
for state in self.states[:-1]:
|
|
self.transitions.append({
|
|
'trigger': f'step_{int(state.name)+1}',
|
|
'source': state.name,
|
|
'dest': str(int(state.name)+1)
|
|
})
|
|
self.transitions.append({
|
|
'trigger': 'step_next',
|
|
'source': state.name,
|
|
'dest': str(int(state.name)+1)
|
|
})
|
|
super(LinearFSM, self).__init__()
|