You are on page 1of 2

Before assigning a ghost a direction, both the location of other ghosts, and the viability of

heading in a particular direction, are considered. First, the distances between a particular ghost
and all other participants are calculated. In order to strategically discern which direction to
head, all possible directions for a single ghost are evaluated. An advantageous direction will
minimize the direction between the given ghost and cmptMan, while maximizing the distance
between ghosts, so that the ghosts do not clump together. When the given ghost is within 2
units of another ghost, a different strategy is utilized, which is biased towards separating the
ghosts. For each other ghost participating in the game, an advantageous direction is
individually calculated, resulting in a list of potential directions. In cases where three potential
directions have been calculated, the recurring direction is chosen, if it exists. In cases where
these calculations are not fruitful, as the given directions will force the ghost into a block, a
second set of strategies are used.
Here, the viability of heading in a particular direction is evaluated by calculating a direct
route to cmptMan. A brute force method is applied, which calculates all possible paths using
two directions to traverse from the ghost to cmptMan. First, the total distance is calculated, and
every possible iteration of a binary directional subset is generated, at the length set by total
distance. On the following page, every binary iteration is shown for a path with a length of 4.
However, since one is concerned with a specic rectangle, some of these iterations are
irrelevant. To lter out the irrelevant results, the difference between the x distance and the y
distance is calculated. Then each list (or row in gure 1) is summed, and the lists which are not
equal to the difference are discarded. Notably, 1 is always assigned to x values, and -1 to y
values. In most cases, the rst path search is unsuccessful if the ghost must travel in three
directions (N,W and S) to reach cmptMan. For example, in the diagram shown below, the rst
search path would try to nd paths comprised of North and West movement (within the blue
eld). As a result, an expanded path search would take place, which tries to locate the closest
coordinate from which a path to cmptMan can be created, moving outwards from the ghosts
current position. As shown below, when a new path origin is tested at 8,5, two successful paths
can be generated (within the green and red elds). Unfortunately, this program only breaks the
path into two pieces, as an exhaustive application of this concept (i.e. breaking the path into
many pieces and coordinating their integration) could be quite powerful, but is likely beyond the
scope of this class. Since the extended path search can take a long time to complete, a timeout
condition of 0.5s per ghost has been coded into the program.
Before instructing the ghosts to move in the directions determined by the above
algorithms, the program checks to make sure no ghosts are about to collide. If ghosts are on a
collision path, one ghost is instructed not to move. In subsequent turns, the algorithms are
biased towards separating the ghosts by at least 2 units. As a nal precaution, when there are
ve or fewer dots on the map, the ghosts are instructed to nd the closest dot and sit on it.
cmptM
(8, 5)
ghost





















sum
-1 -1 -1 -1 -4
1 -2
-1 1 -2
1 0
-1 -1 1 -2
1 0
-1 1 0
1 2
-1 -1 -1 1 -2
1 0
-1 1 0
1 2
-1 -1 1 0
1 2
-1 1 2
1 4

You might also like