Posted: 7th Oct 2011 20:03
Hi folks,

I've been working on a simple path find function and thought I would share it with anyone that needs it.

The algorithm itself is based in the article of Patrick Lester that you can find here : http://www.policyalmanac.org/games/aStarTutorial.htm

You can use the buttons below the grid for pretty much everything.

The first three buttons will let you choose what will be placed on the grid if you click it (Wall, Start point, End point)
As you press each one of these buttons the sprite on its left will highlight to let you know it's chosen.

The toggle diagonals button will do exactly that, toggling between "no diagonals", "diagonals without cutting corners" and "diagonals allowing to cut corners", you can see which one is active by the green text on the top right of the screen.

The Find Path button will do just that and the Clear Path will clear the path markings if there is any on the grid. Each time you press Find Path it will automatically clear the existing one if any.

Hope someone will find this useful and if you have comments or suggestions please post them

Cheers.

Edit : Just thought I would add a screenshot as well.

Posted: 8th Oct 2011 10:00
Nice!
Iam going to check it later on!

Please add it to the agk codebase here !!!

So will it never get lost in the flodwave off thread posts

http://www.thegamecreators.com/?m=codebase_list&a=&c=&l=4
Posted: 8th Oct 2011 20:39
Thank you Cliff, I did like you suggested


I felt that the found path was too rigid as it was always the same for the same set of origin/destination coordinates so I decided to add a litlle random factor to it, each time you press Find Path you have the chance to get a different route with the same number of steps.

In order to avoid changing the original post since it disappeared once already, which I guess it's because of this "guilty until proven innocent" posting phase I will add the code change here, so all you have to do is to replace the code from line 255 to 265 in the file ast.agc with the following code :

+ Code Snippet
//and we compare them to the best we found so far
If  AuxValue <= MinimoF and AuxValue2 <= MinimoH
	//lets give the decision of selecting the
	//best cell a certain randomness
	ChangeCell=1
	If AuxValue2 = MinimoH
		ChangeProbability = random(1,100)
		If ChangeProbability > 50 Then ChangeCell = 0
	EndIf
	If ChangeCell=1
		//if they are better we prepare the cell to be examined next
		MinimoF = AuxValue
		MinimoH = AuxValue2
		OpenCurrent = i
		Px = a
		Py = b
		P = MapCalc[a,b]
	EndIf
endif


Cheers
Posted: 9th Oct 2011 0:48
I guess you did a good job I had one in C++, It is good that you wrote in in agk. I also like the random path thing. It is a great totorial.
Posted: 9th Oct 2011 6:05
Great to see some cool A.I in AGK. Given the progress of AppGameKit apps, I won't be surprised at all if we see a Pacman or Boulderdash game borrowing this code in the not too distant future Would that I had the time myself...
Posted: 9th Oct 2011 10:26
In order to avoid changing the original post since it disappeared once already,

Simply add the latest changes as an new post in the codebase.

And write extra for my pathfinding code.

Add this for an random path in my pathfinding code

So can anyone choose if they want the straight path or random?
Posted: 9th Oct 2011 11:21
I was beginning to consider changing my code for my own AI to use a 'tile' based method like this but it doesn't really suit the game I'm making. Great work though I'm certain I'll use it at some point and when I do I'll be sure to thank you!

Posted: 9th Oct 2011 23:55
Thank you guys, and thank you for all the bits of code you fellas shared before I decided to come forward. When everyone chips in things become easier and creative juices flow better