A finite state machine is a device or a device model with a limited number of States. It can operate at any given time based on input, so that the State can be changed from one state to another, or an output or action. A finite state machine can only be in one State at any moment.
Status change table
A state change table is a table of statuses caused by conditions and conditions. The table can be trained by the agent at the specified interval, this allows it to perform necessary State Conversion Based on received excitement from the game environment.
Built-in rules
Each status module depends on its own logic to determine whether it should run a function that changes itself to an alternative status. The agent only provides external functions for operations and obtaining its own attributes, the status module uses the functions provided by the agent to find the required information and process the rules.
The implementation of this method is to encapsulate the state into an object, including the logic required to promote the state transformation. In addition, all State objects share a common interface: a pure virtual class called state. A version of the simple interface is provided here.
class State{public: virtual void Execute (Troll *troll) = 0;};
Imagine a troll class that has member variables that indicate characteristics, such as health, anger, and perseverance, and an interface that allows the customer to finish training and adjust those values. A troll class can be assigned with the functionality of a finite state machine. You only need to add a pointer to the instance of the State class inherited object and a method that allows the user to change the instance to which the Pointer Points.
Class troll {/* omitted properties */State * m_pcurrentstate; public:/* interfaces for omitted properties */void Update () {m_pcurrentstate-> execute (this );} void changestate (const state * pnewstate) {Delete m_pcurrentstate; m_pcurrentstate = pnewstate ;}};
When the update method of the troll class is called, it uses the this pointer to call the Execute function of the Current Status type, when updating a troll class, what kind of behavior can be completely dependent on the logic of its current state. The instance can be used to better clarify this, so that we can create a bunch of States so that troll can escape from the enemy side when it feels dangerous, and change to sleeping when it feels safe.