mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-22 23:31:31 +00:00
Create initial implementation for solution check
This commit is contained in:
parent
4f181b8f09
commit
1e9642912c
@ -1,11 +1,14 @@
|
|||||||
|
from typing import List
|
||||||
|
|
||||||
from transitions import Machine
|
from transitions import Machine
|
||||||
|
|
||||||
|
|
||||||
class FSMBase:
|
class FSMBase:
|
||||||
states, transitions = [], []
|
states, transitions = [], []
|
||||||
|
|
||||||
def __init__(self, initial: str = None):
|
def __init__(self, initial: str = None, accepted_states: List[str] = None):
|
||||||
self.message_handlers = []
|
self.message_handlers = []
|
||||||
|
self.accepted_states = accepted_states or [self.states[-1]]
|
||||||
self.machine = Machine(model=self,
|
self.machine = Machine(model=self,
|
||||||
states=self.states,
|
states=self.states,
|
||||||
transitions=self.transitions,
|
transitions=self.transitions,
|
||||||
@ -24,3 +27,6 @@ class FSMBase:
|
|||||||
|
|
||||||
def unsubscribe_message_handler(self, msghandler):
|
def unsubscribe_message_handler(self, msghandler):
|
||||||
self.message_handlers.remove(msghandler)
|
self.message_handlers.remove(msghandler)
|
||||||
|
|
||||||
|
def is_solved(self):
|
||||||
|
return self.state in self.accepted_states
|
||||||
|
@ -20,8 +20,8 @@ def zmq_callback(stream, msg_parts):
|
|||||||
stream.send_multipart(serialize_all(key, 'OK'))
|
stream.send_multipart(serialize_all(key, 'OK'))
|
||||||
if key == 'solution_check':
|
if key == 'solution_check':
|
||||||
stream.send_multipart(serialize_all(key, {
|
stream.send_multipart(serialize_all(key, {
|
||||||
'solved': True,
|
'solved': fsm.is_solved(),
|
||||||
'message': 'solved'
|
'message': 'solved' if fsm.is_solved() else 'not solved'
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user