Artificial Intelligence (AI)

The following showcases two artificial intelligence (AI) techniques: A* path-finding, and flocking simulation achieved using a finite-state machine. The “Pub Crawl Fantasy” project also includes an example of an implemented fuzzy logic AI system used for determining an enemy’s action from a number of combat options.

A video of the demo can be found on YouTube here.

These demos were rewritten and included as part of the James Potts Portfolio app, which was released onto the Google Play Store in August 2016.

A* Path-finding

Technical Skills: C++; A* Path-finding;

astar

The project was to create an AI agent (blue) that could navigate through the maze to a given goal point while avoiding the enemy patrols (orange). The maze is constructed from a 20 x 20 tile grid where each tile has its property set to default (white), wall (red), agent path (purple), or enemy patrol (yellow).

When the program is run the agent is given the location of a goal tile and proceeds to generate a path to it using the A* path-finding algorithm. If the current tile being checked by the algorithm is part of the enemy’s patrol path an additional weighting is applied to it as it is a more difficult/less preferred path to take. After the algorithm completes it calculations the agent will follow the path. When the agent reaches the goal node a new goal node is set and the process is repeated. The patrolling enemy AI is calculated in the same way, except their path-finding only cycles between the two end tiles of their patrol area.

The project used a provided graphics framework to run on a Windows PC and the A* algorithm and all logic for the agents were written in C++.

Flocking Simulation

Technical Skills: C++; Flocking Simulation; Finite-state Machine;

flocking

The second part of the project was to produce a flocking simulation. The flock (yellow) attempts to flock around the alpha (blue) while evading the predator (red) who is seeking the alpha.

The AI in the simulation is built on a finite state machine so the appropriate behaviour is selected depending on certain key factors. The implemented behaviours are: seek; evade; wander; and align.

The basic logic for the finite-state machine for each agent is described below:

  • The predator
    • seeks the alpha.
  • The alpha
    • evades from predator if it gets too close,
    • otherwise it wanders/continues at current velocity.
  • A follower
    • evades from predator if too close to predator,
    • evades/separates from alpha if too close to alpha,
    • aligns to the leader if close enough (factors the alpha’s velocity into its own velocity calculations),
    • Seeks/cohesion towards the alpha if too far away from alpha for alignment to occur,
    • otherwise wanders/continues at current velocity.
    • Additionally, evades from other followers to avoid collisions if too close together (not part of the finite state machine).

As this is part of the A* project, it also used a provided graphics framework to run on a Windows PC and all logic was written in C++.