I am trying to build a pacman game. Currently I am in the process of building the AI for the ghosts. The way I have the AI working is whenever a ghost enters an intersection, it will check where the player is relative to its position, then it will move in one of the possible directions depending on the intersection it is at.

The problem I am experiencing though is whenever the ghost is moving horizontally it cannot be sent to the left. Similarly, when it is moving vertically, it cannot be sent up or down. This doesn't allow it to turn around when it is moving to the right or to the bottom. It can be sent right when moving left though. When searching through my code I cannot see why this is.

Unfortunately the code is long and I am inexperienced so it may be difficult to understand.

I am unsure how to post it up here. It would be convenient to upload the whole project but there seems to be no option for that.

After more troubleshooting I realized that my method has more flaws than I first thought. I may not be able to use this method at all in the end.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.