top of page
TowerDeffenceAStar.gif

A* Pathfinding Source Code

  Red Circle - Eney using A* Pathfinding

  White Square - Wall

  Yellow Square - Goal

  Purple Triangle - Shooting Tower

  Green Square - Places for placing Towers

Definitions:

 - Frontier - This is the list of the fields that are set to be checked

 - Heuristic - The sum of the rows and columns from a field until the goal.

 - Cost - Minimum of steps required to get to this field

 - Priority - This is the sum of the Cost and Heuristic or a field

A* Algorithm

Explanation:

Step 1 - Select a start and end point and then put the start point in the frontier.

Step 2 - Remove the first point from the frontier, change its priority so that it is not put in the frontier again and check if that point is the goal.

If it is the goal, return the path that got you to this point and exit. If not, continue.

Step 3 - Loop through all of its neighbours of the point you just removed from the frontier, calculate their cost and priority and put them in the frontier.

Step 4 - Repeat "Step 2" and "Step 3" until you have found a path or until the frontier is empty.

The fields (the blocks you move on)

Field.h

Field.cpp

Heuristic:

The algorithm:

Returning the path

bottom of page