AI Toolkit
|
Classes | |
class | aitoolkit::fsm::state< T > |
A state of the FSM. More... | |
class | aitoolkit::fsm::simple_machine< T > |
A simple FSM. More... | |
class | aitoolkit::fsm::stack_machine< T > |
A stack FSM. More... | |
Typedefs | |
template<typename T > | |
using | aitoolkit::fsm::state_ptr = std::unique_ptr<state<T>> |
Heap-allocated pointer to a state. | |
A finite state machine (FSM) is a mathematical model of computation. It is an abstract machine that can be in exactly one of a finite number of states at any given time. The FSM can change from one state to another in response to some external inputs; the change from one state to another is called a transition.
This library provides 2 types of FSMs: a simple machiine and a stack machine. The simple machine is the simplest form of FSM, it can only be in one state at a time. The stack machine is a more complex form of FSM, it can be in multiple states at a time.
First, include the header:
Then, create a blackboard type:
Then, create a state type for each of your states:
Create an instance of the FSM:
To transition to a new state, call set_state()
:
NB:
- this will call the
exit
method of the current state (if any) and theenter
method of the new state- if the machine is paused while transitioning to a new state, the new state will be paused as well
To pause the machine, call pause()
:
NB: This will call the
pause
method of the current state (if any).
To resume the machine, call resume()
:
NB: This will call the
resume
method of the current state (if any).
To update the machine, call update()
:
NB:
- this will call the
update
method of the current state (if any)- if the machine is paused, calling
update()
will do nothing
To clear any state, call clear_state()
:
NB: This will call the
exit
method of the current state (if any).
Create an instance of the FSM:
To push a new state onto the stack, call push_state()
:
NB: This will call the
pause
method of the current state (if any) and theenter
method of the new state.
To pop the top state off the stack, call pop_state()
:
NB: This will call the
exit
method of the current state (if any) and theresume
method of the new top state (if any).
To update the machine, call update()
:
NB: This will call the
update
method of the top state (if any).