• Advertisement
Sign in to follow this  

AI trouble sdl 1.2

This topic is 720 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Guys, I started working on this pacman game again. My ghost1.follow() function is so ugly, it's unreal. I need some pseudocode ideas on how the hell am I supposed to make my ghost follow pacman like a normal ghost. Any ideas are appreciated. ( if code is not too ugly )

Edited by Heelp

Share this post


Link to post
Share on other sites
Advertisement

Yeah, I know this. There is an even better link, you just click over the different ghosts and see what they do. http://pacman.shaunew.com/play/index.htm#learn
But how exactly to make the follow() and scan_tiles() codes pretty and efficient, this now is a completely different story.

Edited by Heelp

Share this post


Link to post
Share on other sites

What you need is a simple, generic pathfinder which you can feed each ghost. The pathfinder gets fed a ghost's current position, current direction of travel, and the position of its "target". That target is very clearly defined in each ghost's Scatter and Chase states; specific map coordinates, or locations relative to PacMan (including +0,+0 relative to PacMan).

 

The pathfinder has to respect the ghost's movement rules; they never reverse their direction, they only turn left, turn right, or carry on straight.

 

You only need to query the pathfinder for a given ghost when they reach a decision point. Once they're on a lane headed towards the next intersection, they can't change their mind anyways, so just let them carry on straight until they can choose to turn again.

 

Post some of your current ghost AI code, and we may be able to give you specific, pointed examples of how to improve what you're doing already.

Edited by Wyrframe

Share this post


Link to post
Share on other sites

I can't.....Spent 2 days and nothing. I made another class Shade that has very fast speed ( 30 pixels in a frame ) and every time the ghost is in a junction, the shade gets the ghost's coordinates and tries all the possible ways ( it tries one way, then goes back to the junction and tries the other one ), but if there are more junctions it gets hard and I just made it like that: if( ghost is in a junction ) and if pacman is above ghost, go up ) and if pacman is below ghost, go down the junction and it kind of works, maybe its too early for me to go to this AI stuff, its too hard, but the good thing is that I kind of made progress in my rail system, so earlier when Pacman was in a junction I checked every single tile of the map with for loop, now I improved the code to actually check only the 4 tiles surrounding pacman, so now instead of 441 tiles being checked every frame, now only 4 tiles are checked every frame. My plan was to learn basic AI first, then make the game states and learn inheritance and stuff, maybe it's good to leave AI for later, what do you think?

EDIT: I mean I read all the articles Alberth gave me, and I can't really implement them in my game, maybe I should take it slower, learn something easier??

Edited by Heelp

Share this post


Link to post
Share on other sites

Sounds like good progress.

 

AI stuff is complicated, although the ghost behavior is not entirely what most people consider AI. It's a state machine with completely fixed (and not trivial) behavior.

Most people see AI as interaction with some form of "smart" knowledge about the surrounding (if a bridge is down, I can use that, else I have to walk around over a rope bridge), their own state (look for food if hungry, medicine if hurt, etc), terrain (don't sleep in flat unprotected land), and so on.

 

You can spend years to a life time on AI if you want. I agree with you however, for now stick something simple in that you can live with, and move on. You'll find both inheritance and game states everywhere, including in AI related studies, so it's a good foundation for a lot of things.

 

The Dijkstra and A* algorithms I gave you are quite simple in nature, the problem is likely that they are written in a way that is difficult to understand at first. You have to shift yourself into the mindset of the algorithm, and then all puzzle pieces fall into their place. The whole idea makes total sense, and you cannot imagine how you once failed to understand it :)

 

Revisiting these algorithms later is good I think, they are quite easy, and they are easy to see visually, which helps in understanding. They are also quite useful at lots of places.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement