The essence of Artificial Intelligence programming case study-State-driven intelligent Body Design

Source: Internet
Author: User

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.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.