Adaptive AI Engine for RTS Games

Discussing the theory and practice

Understanding AI of ORTS Game

Posted by Ogail on October 4, 2009

  • Attacking


from AttackCommander.c file

  1. We have a set of units which will be used in the attack. If this set is empty then return.
  2. Else, we get the center of this mass of units.
  3. Update enemies set by clearing the old one, and making new querying about the current set of enemies.
  4. Get the nearest tank as the target. If there’s no tanks, then get the nearest control center, otherwise there’s nothing to attack.
  5. Get the location of this target.
  6. Define a SquadCombatAI
    object.
  7. For each a unit of the attacker units:
    1. Determine the distance square between it and the target.
    2. Given that the unit is idel:
      1. If the target enters the combat distance square , then the unit switch its state to the fighting state.
      2. If not, then make the unit move towards the target, and change its mode to moving.
    3. Given the unit is moving, if the target enters the combat distance square, then fight.
    4. Given the unit is fighting:
      1. If the target exits the distance square, then IDLE.
      2. Otherwise, enable the unit motion or disable it.
  • Base managing

from BaseCommander.c file

  1. We have three main sets : unitsToBuild, buildingsToBuild, and unitsQueued
  2. We also have the obj2buildng set in which, each element is a unit (e.g. worker, builder) associated with the building he works at. So this set needs to be updated each game loop.
  3. For each builder in the finishedbuilders queue, delete the building which this builder he had built from the unitsqueued queue. And then clear the finished builders.
  4. If we have units need of training, then while the unitsTobuild queue isn’t empty:
    1. Pop a unit from the queue.
    2. Find non busy building which can train this unit.
  5. If we have buildings to be built, then start building these buildings. While the buildingsToBuild queue isn’t empty:
    1. Get a bulding which needs to be build.
    2. Try to acquire a worker for this building.
    3. If we have a worker, remove it (to simulate that he has moved to the building).
    4. Add the worker to the activebuilders set.

  • Building

from BuildCommander.c file

If we have a worker and the game in one of the following state:

  • Planning:
    • Find build site.
    • Move to the next site.
  • Ready:
    • Trying to build for 3 times, if it can’t be built, then stop trying.
    • Defining the buildwatch

  • Gathering resources

from GatherCommander.c file

The purpose of GatherCommander is to mine any minerals around a base as efficiently as possible given a set of workers.

  1. If this the first view, then initialize the gather commander by getting the nearby minerals.
  2. If it’s not the first time, and we have minerals, then assess changes to them:
    1. Determining if this mineral is new or not.
    2. If it’s new
      1. Clear the current minerals records set, and fill it with the new set of active minerals records. Now we must clear the newminerals set, as it has been added to the active minerals.
      2. Allocate a route for this mineral, suitable for the number of works of this mineral.
      3. Compute Mineral Clusters.
      4. Compute routes.
  3. Perform workers actions.
  • Defensing

from DefenseCommander.c file

  1. We have a set of units that are used to defend. If this set is empty, so nothing can be done and the base isn’t under control. L
  2. Determine the enemies attacking , and list them in the enemies set. And define a SquadCombatAI object.
  3. If the enemies set is empty, then set the undercontrol flag set to true, and make the following changes for each unit:
    1. Disable the unit motion.
    2. Update the game state:
      1. If the unit state is chasing or attacking, then change it to stopped.
      2. If its state is returning , then the undercontrol flag set to false (as the base didn’t became under control yet.)
      3. If its state is stopped, determine where it is stopped, if it is out of its zone, move it for a free spot, or keep it till we find a free spot later.
  4. If there are enemies, get the best enemy and for each unit:
    1. Get the distance between it and the target.
    2. If the unit state is stopped or attacking
      1. And if the distance is more than 120, then move the unit towards the target, so the state is chasing now.
      2. If the distance is 120 or less, then attack without mercy J
    3. If the unit state is chasing and the distance less than 80, then change the state to attacking.
    4. If it is attacking already, then enable unit motion, and put this unit in the back of the units set.
  • Scouting

from ScoutCommander.c file

  1. we have a set of units work as scouts (explorers) , for each one of them:
    1. Find the borders locations, if the set of locations is empty, then set the finished flag to true.
    2. If the scout is stopped, then get the location with best distance, and move the scout to it.
    3. If we don’t have any more locations to move scouts to (finished ==true), then start Reconnaissance( gathering information)
    4. Retrieve active minerals which were unknown for us.
    5. For each scout:
      1. If it is stopped, get a location of any random one of the found active minerals
      2. Move the scout to it.

About running the game:

What I could do is to run the two .exe files (orts, and ortsg), but I couldn’t issue any game test from the tournaments folders nor adding any sample AI code, because I couldn’t run the game until hours from your call.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: