|
David Pittman, Application ID #### |
|
Description:
The AI for the sentry is fairly simple. He operates in one of three discrete states: standing guard/returning to post (no stimuli provided), investigating a potential threat (sounds or distant sightings provided), or moving to sound an alarm (nearby sighting provided). Given a destination (typically either a potential threat, the alarm box, or his initial post), the sentry's path is determined by the A* algorithm. The guard will always move towards the source of the most recently provided stimulus. Upon reaching that node and finding nothing, he will return to seeking the second most recent stimulus, and so forth until every potential threat has been checked. At that point, his state reverts to its lowest level and he returns to his post.
For simplicity's sake, "sound" events triggered by stepping on noisy tiles are heard throughout a map. Sighting of the player must be checked by casting a ray along the line of sight until either the player or a wall is reached.
The A* algorithm is a popular choice for pathfinding which works especially well for this sort of grid-based map. A good article explaining the algorithm can be found at http://www.gamedev.net/reference/articles/article2003.asp. The implementation for this AI is as follows:
The following example is a very simple case, but it may help to illustrate how the algorithm works.
![]() Example 1
In the example above, the red square represents the starting node and the green square is the destination. Grey tiles are walls. The first step is to add the starting node to the open list.
![]() Example 2
Now the node with the lowest F cost is added to the closed list. In this case, there is only the starting node, so it is added (the yellow border indicates its presence in the closed list). Although not illustrated, this node has values G = 0, H = 3, and F = 3. The available movement directions are up, right, and down. The nodes in these directions are added to the open list with the values indicated.
![]() Example 3
The node to the right had the smallest F cost, so it is added to the closed list. From here, only vertical movement is possible (to the left and right are a closed node and a wall, respectively).
![]() Example 4
At this point, there is a tie in the F costs of the two most-recently added nodes (as well as the nodes added in Example 2). Since the bottom one was added last, the tie is broken in its favor. (Technically, this happens because it was pushed to the front of the list, and because the sort operation is stable, it remains in front of the other nodes with equal F cost.) Possibles moves are to the left and down. The node to the left is already on the open list, and since the new G cost would be greater (3), it is left untouched. (Were the new G value lower, the new value would be applied and the parent node changed to the current node.) The node below the current node is added.
![]() Example 5
Of the remaining nodes with F = 5, the one added to the top in Example 3 is the most-recently added, so it is pushed onto the closed list. Again, the node to the left is checked and ignored, and the node to the right is added. This process will continue for two more cycles, until the destination node is eventually added to the closed list.
![]() Example 6
Now the path can be built by following the each node back to its parent (tracing the arrows backwards from the destination).
Controls:
Map editing mode:
Command line options:
Code files:
|