T
- The subclass of CellGameState that this ThinkerState's Thinker is
used byU
- The subclass of Thinker that this ThinkerState is used byV
- The subclass of ThinkerState that this ThinkerState ispublic abstract class ThinkerState<T extends CellGameState<T,U,V>,U extends Thinker<T,U,V>,V extends ThinkerState<T,U,V>>
extends java.lang.Object
A ThinkerState represents a state that a Thinker can occupy. A Thinker may occupy at most one ThinkerState at a time. ThinkerStates take actions alongside their Thinker's own, as well as when entered and left by a Thinker, and can help a Thinker keep track of its position in a multi-frame procedure.
The ThinkerState class is intended to be directly extended by classes V that extend ThinkerState<T,U,V> and interact with CellGameStates of class T and Thinkers of class U. BasicThinkerState is an example of such a class. This allows a ThinkerState's Thinkers and their CellGameStates to interact with it in ways unique to its subclass of ThinkerState.
It is useful to create an individual ThinkerState instance within the class of the Thinker that uses it and override its methods when creating it, allowing those methods to easily access the internal fields and methods of the Thinker.
Constructor and Description |
---|
ThinkerState() |
Modifier and Type | Method and Description |
---|---|
void |
enteredActions(CellGame game,
T state)
Actions for this ThinkerState to take immediately after being entered and
immediately before getDuration() is called.
|
void |
frameActions(CellGame game,
T state)
Actions for this ThinkerState to take once every frame, immediately
before its Thinker takes its own frameActions().
|
abstract int |
getDuration()
Returns how long in time units this ThinkerState should last.
|
abstract V |
getNextState()
Returns the ThinkerState that this ThinkerState's Thinker should enter
after it leaves this one.
|
void |
leftActions(CellGame game,
T state)
Actions for this ThinkerState to take before being left, and immediately
before getNextState() is called.
|
void |
timeUnitActions(CellGame game,
T state)
Actions for this ThinkerState to take once every time unit, immediately
before its Thinker takes its own timeUnitActions().
|
public abstract int getDuration()
public abstract V getNextState()
public void timeUnitActions(CellGame game, T state)
game
- This ThinkerState's Thinker's CellGamestate
- This ThinkerState's Thinker's CellGameStatepublic void frameActions(CellGame game, T state)
game
- This ThinkerState's Thinker's CellGamestate
- This ThinkerState's Thinker's CellGameStatepublic void enteredActions(CellGame game, T state)
game
- This ThinkerState's Thinker's CellGamestate
- This ThinkerState's Thinker's CellGameState