Need help with logic.

Hello! Currenty im making a game, where you should make spaceships to capture planets.
Im stuck in making proccess of choosing the closest path of chosen way. Here is a picture of what i mean.
S - starting point, E - end of path, red arrows show the closest path.
82049--2-bmp.jpg
I was thinking about system like this: Each planet has a list of connectet planets. (Planet 1 has list of 2,4,5) etc. Then you just take ending planet and look for planets, that are connected to it, check if connected planets arent your starting point, if not choose the next one planet. Then store all that paths and just choose the closest one. Im stuck in implemeting way how to store all that paths. Thanks in advance.

I understand that its a bit confusing, so you can ask me anything you dont understand.

The A* algorithm should do exactly what you are looking for, given that you already have a node based system and everything…

http://arongranberg.com/astar/front

http://www.policyalmanac.org/games/aStarTutorial.htm

Helo dear Le_Valius i’m sertainly not a profesional at this, and sure there someone can have a better solution. Anyway i’m going to tell you how i will do it if i was developing that logic. I’m currently developing a prototype of a FPShooter so i have to deal with pathfinding and waypoints systems. I found some years ago on the web a really simply and very useful waypoint system. That is ideal for car racing like games, that store in every waypoint, with are the next one and have a return type function that let you get the next waypoint. Of course may be you would amplify its versatility and functions.

After saying that, what i would do in your place is. Think the solar sistem like a web so every planet have stored wich ones are conected. You can do an array variable with every planet conected. Then you have to create probably a very tricky loop where you are going to check and eliminate those ones wich are not conected until the end of the path. So you propose a very simply example wich can become very complex in more extended scenarios. But lests stay in the simply.

Lets say that you want to go from Start to End like in the example. So in the midle of the path you have a node planet how is not the end but a bridge to rich it. So in the loop you probably have to see is. 1) where are you, and what planets are linked to that one. 2) Take those linked planets and search wich ones have the end path (I have to say that this in first attempt can work on that simply example but in a larger scenario may be can become so tricky). Construct an array of those planest that have linked the end destination. And from here everything should be less problematic. Now you have to compare the distance of full path each other, and pick that one that is the smaller.

You may be notice that this is pretty functional in that specific scenario that you bring to us. But lets say that the system is a web of docens or even hundreds of planets. That’s when the big trouble begun, becouse i have not taking into account that is important to kept track of every node of the path. So to achive a good result may be you will have to do a tremendous scan of the entire web. May be eliminating some obious ponts where is no need for a check.

This is just a general idea i really dont know if it’s going to work, or work properly. Is just what i probably will do if i was trying to achive what you prupose. I dont remember where i found the waypoint system, but if you need it just ask and i will share it.

Good Luck!