Package common
Class FSM
java.lang.Object
common.FSM
- All Implemented Interfaces:
Configuration
Deterministic Finite State Automaton (DFSA)
The FSM class defines a DFSA in terms of a 5-tuple, (Q, Σ, δ, q0, F)
The FSM class defines a DFSA in terms of a 5-tuple, (Q, Σ, δ, q0, F)
- a finite set of states Q
- finite set of input symbols called the alphabet Σ
- transition function δ : Q × Σ → Q
- one initial or start state q0 ∈ Q
- a set of accept states F ⊆ Q
setInitialState(State), and the set of final states with invocations
to setFinalStates(State...)- Author:
- Krish Pillai
-
Nested Class Summary
Nested classes/interfaces inherited from interface common.Configuration
Configuration.Direction -
Field Summary
Fields inherited from interface common.Configuration
AUDIO_DIR, DEFAULT_FRAME_RATE, DRAWABLE_DIR, GAMELOGGER, setViewCallChain -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddStateChangeListener(event.StateChangeListener listener) Defines a listener for this FSM.event.State[]event.StateGives the current state of the FSM.event.StatebooleanReturns true if the state is designated a final state.booleanReturns true if the state is designated a final state.voidpause()Suspends the FSM.voidresume()Puts this FSM into run statevoidsetFinalStates(event.State... states) Defines the final state of this FSM.voidsetInitialState(event.State state) Defines the initial state of this FSMvoidstart()Puts this FSM into run state and invokes the manage() method on the initial state.toString()voidtransition(String action) Computes the next state for the specified action based on the transition table.
-
Constructor Details
-
FSM
The FSM class defines a DFSA in terms of a 5-tuple, (Q, Σ, δ, q0, F). For each state q in Q and each input symbol a in Σ, let δ(q, a) = p. Then the transition diagram has an arc from node q to node p, labeled a.
Reference: Introduction to Automata Theory, Language, and Computation- Hopcroft, Motwane, and Ullman
Invokestart()only after setting initial and final states. Initial state has to be defined. Final states are not required.- Parameters:
states- Represents Q. For each state in Q, there is a nodeactions- Set of input symbolstransitions- The transition table containing δ(q, a)- See Also:
-
-
Method Details
-
inFinalState
public boolean inFinalState()Returns true if the state is designated a final state. There can be multiple final states- Returns:
- true or false
-
inInitialState
public boolean inInitialState()Returns true if the state is designated a final state. There can be only one initial state for a given FSM.- Returns:
- true or false
-
getCurrentState
public event.State getCurrentState()Gives the current state of the FSM.- Returns:
- the current state
- See Also:
-
State
-
getInitial
public event.State getInitial()- Returns:
- the initial
-
getAccepting
public event.State[] getAccepting()- Returns:
- the accepting
-
transition
Computes the next state for the specified action based on the transition table. This method then invokes the overriddenState.manage()method.- Parameters:
action- String defining the action
-
addStateChangeListener
public void addStateChangeListener(event.StateChangeListener listener) Defines a listener for this FSM. If listener is not null, it will be notified of a state change whenever theState.manage()invocation completes.- Parameters:
listener- the listener- See Also:
-
StateStateChangeListenerState.manage()
-
setInitialState
public void setInitialState(event.State state) Defines the initial state of this FSM- Parameters:
state- the initial state
-
setFinalStates
public void setFinalStates(event.State... states) Defines the final state of this FSM. There can be multiple final states. The final states can be supplied either as an array or a comma separated list. An FSM with no final state will run forever.- Parameters:
states- the comma separated list of final states
-
start
public void start()Puts this FSM into run state and invokes the manage() method on the initial state. The initial state should be defined. A severe error is reported and an abend occurs if initial state is undefined. -
pause
public void pause()Suspends the FSM. -
resume
public void resume()Puts this FSM into run state -
toString
-