pacBuzzAI
pacBuzzAI is a chase-and-evade arcade Java applet patterned after the now-famous Pacman arcade game. In this game, our hero pacBuzz tries to gobble up as many of the round power pellets as he can without getting eaten by one of the four bulldog ghosts who inhabit his maze homeland.
In pacBuzzAI, the game is played from the point of view of the actors rather than from the point of view of a human player. What this means is pacBuzz is only aware of the surroundings he can see. He doesn't know if there is a ghost lurking around the corner until he gets to that junction. Therefore, he needs to be constantly on guard, checking for ghosts at every step. In a standard Pacman game, the human player is fully aware of the maze and where the ghosts are. This makes it much easier to avoid deadends and the ghosts.
The pacBuzzAI Pellet-Gathering Algorithm
Several algorithms were explored before it was decided that pacBuzzAI would use a modified greedy algorithm for pellet gathering. At every step, pacBuzz looks down the available corridors and assigns a point value to the number of pellets. Each pellet has a base worth of 30, but that value is reduced based upon pacBuzz's distance from the pellet. This prevents him from walking clear across the maze simply to find a single pellet. After the pellets' values have been summed, a deduction is made if pacBuzz detects one of the bulldog ghosts in the corridor. The corridor which scores highest is the one pacBuzz chooses to traverse.
So what happens if pacBuzz can't find any pellets in the corridor? Well, several algorithms were tried here, including breadth-first searching and a standard maze-walk (keeping the maze wall to the right at all times), but it was found that using a simple random selection was just as good as any of those algorithms, considering the cost in time of doing an exhaustive search for pellets. To prevent the pacBuzz from getting hung up, once he makes the first random selection, he continues moving in that direction until he either comes across a corridor with pellets, or he is blocked. If he gets blocked, he will not go back the way he came, unless that is the only possible option ( i.e. he's in a dead-end ). With the standard Java pseudorandom generator, it is highly unlikely pacBuzz will ever get stuck in a particular area as he might with a standard greedy algorithm.
Ghost Avoidance
pacBuzz has a strong survival instinct. When he encounters a ghost in a hallway, he is aware the ghost is going to begin chasing him. So, he immediately enters a ghost avoidance algorithm designed to put as much distance as possible between himself and the ghost. He figures out whether he is closest to the ghost in the x or y direction and makes his move away from the ghost based on that. (If he is closest to the ghost in the x-direction, then he tries to move away in the x-direction, and if that is impossible, he moves in the y-direction.) pacBuzz only moves towards the ghost as a last resort.
Meet The Ghosts
The original Pacman game had four ghosts named Inky, Blinky, Pinky and Clyde. Our four bulldog ghosts keep the same names and some of the same behaviors as the original ghosts. Blinky is the fastest of the four ghosts and makes a single move every round. Pinky is slightly slower and makes one move every other round. Inky makes a single move every three rounds and Clyde (Pokey) only makes a move every four rounds.
The ghosts move out of their house as quickly as possible and then make random movements until they spot pacBuzz. As pacBuzz does, once the ghosts make a random movement, they continue to go that same direction until they are forced to make another choice (or they spot pacBuzz). Also like pacBuzz, they do not retrace their steps on a random movement.
Once a ghost notices pacBuzz in a corridor, he begins giving chase. Because at level 1, each of the ghosts is only as fast as the pacBuzz, they cannot catch him unless they can corner him or gang up on him.
Performance
I was slightly disappointed by the performance of the modified greedy algorithm. Without ghosts in the picture, pacBuzz successfully cleared the maze with no problems. However, with the ghosts in the picture, he tends to eventually get trapped by the ghosts. The main reason for this is because pacBuzz can only really handle the presence of one ghost at a time. What needs to be done is for pacBuzz to recognize that he is being trapped and try to evade all of the ghosts converging on him.
Future Work
Bugs
There is a flaw in the game which appears very rarely. When three of the ghosts align themselves side-by-side in a corridor, it is impossible for them to find a valid move and the game hangs. This is a simple matter of detecting this error, throwing an exception and the catching the error condition. Unfortunately, the error did not first appear until late Wednesday night.