From 1e9642912c9d88e878d14d6733d6a3240611a12b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A1lint=20Bokros?= Date: Fri, 9 Feb 2018 17:27:51 +0100 Subject: [PATCH] Create initial implementation for solution check --- lib/tfw/fsm_base.py | 8 +++++++- src/app/app.py | 4 ++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/tfw/fsm_base.py b/lib/tfw/fsm_base.py index d6a586c..fc1300f 100644 --- a/lib/tfw/fsm_base.py +++ b/lib/tfw/fsm_base.py @@ -1,11 +1,14 @@ +from typing import List + from transitions import Machine class FSMBase: states, transitions = [], [] - def __init__(self, initial: str = None): + def __init__(self, initial: str = None, accepted_states: List[str] = None): self.message_handlers = [] + self.accepted_states = accepted_states or [self.states[-1]] self.machine = Machine(model=self, states=self.states, transitions=self.transitions, @@ -24,3 +27,6 @@ class FSMBase: def unsubscribe_message_handler(self, msghandler): self.message_handlers.remove(msghandler) + + def is_solved(self): + return self.state in self.accepted_states diff --git a/src/app/app.py b/src/app/app.py index 383fd9a..70d3c65 100644 --- a/src/app/app.py +++ b/src/app/app.py @@ -20,8 +20,8 @@ def zmq_callback(stream, msg_parts): stream.send_multipart(serialize_all(key, 'OK')) if key == 'solution_check': stream.send_multipart(serialize_all(key, { - 'solved': True, - 'message': 'solved' + 'solved': fsm.is_solved(), + 'message': 'solved' if fsm.is_solved() else 'not solved' }))