J2ME of roaming (chasing) AI

Source: Internet
Author: User

As a game developer, to create a challenge to the player, as long as the difficulty of the game has increased, so that the imaginary players in the game as witty, as with human intelligence and adaptability. This requires the use of a new scientific AI in the field of computer science (artificial intelligence, AI).

Artificial intelligence, as a new science, the simulation of human thinking is the main research field of AI, is also a difficult and hot one. The human mind is a very uncertain process, it is very difficult to model it accurately. In this game I do use the AI is still very rough, is the basic knowledge of artificial intelligence. Game development experts divide the game-related AI into 3 basic types:

• Roaming ai--determines how a game object roams in a virtual game world;

• Behavioral ai--Determines how aggressive it is to track or chase a different gameobject behind a game object or multiple gameobject;

• Strategy ai--in a strategy game, the best move is determined from a set of roaming rules that are defined by a fixed implementation.

Roaming AI is the most common Ai method for shooting games, and it is the AI that models the object of the game, that is, the objects make decisions and determine how they roam in a virtual world. A typical example of a roaming AI is a space shooting game like Galaga, in which aliens often try to track and chase players. Similarly, the roaming AI is also used to achieve a predetermined way of flying, firing bullets or shooting enemy aircraft. Basically, a roaming AI is used for objects that are controlled by a computer (or program), whether it has to make a decision to change the current path, or to implement the desired results in the game, or simply to follow a particular way of moving. In this game I do, the result of an enemy plane is to follow a certain kind of movement, while trying to collide with the player's plane and reduce the player's life value. In other games, the result that a computer player needs may be to avoid bullets fired by a human player.

The implementation of roaming AI is usually relatively simple, generally include an object (player's aircraft) position, change the other object (enemy aircraft) speed or position. The roaming movement of an object can also be affected by a random or predefined manner. There are usually 3 types of roaming AI: Chase, Dodge and pattern.

The chase is a kind of roaming: A game object that tracks or chases another game object or multiple gameobject. Chasing is a method used by many shooting games, in which enemy aircraft often chase players. Depending on the location of the player's ship, changing the speed and position of the alien, this is the pursuit.

For example, I do this in the game to achieve the chasing algorithm:

/*flag标记具有跟踪能力的小飞机*/
private int flag=-1;
for(int i=0;i<MAX_SP;i++)
       if(smallPlane[i].isVisible())
       {
         if(i==flag)
         {
           if(smallPlane[i].getX()>playerSprite.getX())
                         smallPlane[i].move(-speedOfSP, speedOfSP);
           else
             smallPlane[i].move(speedOfSP, speedOfSP);
         }
         else
           smallPlane[i].move(0,speedOfSP);
     }

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.