Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Simple Pathfind

Author
Message
pedrolbs
13
Years of Service
User Offline
Joined: 18th Aug 2011
Location: PT
Posted: 7th Oct 2011 20:03 Edited at: 8th Oct 2011 00:15
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.

Attachments

Login to view attachments
Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 8th Oct 2011 10:00 Edited at: 8th Oct 2011 10:59
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
pedrolbs
13
Years of Service
User Offline
Joined: 18th Aug 2011
Location: PT
Posted: 8th Oct 2011 20:39 Edited at: 8th Oct 2011 21:58
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 :



Cheers
3d point in space
15
Years of Service
User Offline
Joined: 30th Jun 2009
Location: Idaho
Posted: 9th Oct 2011 00: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.

Go through yourself at a wall.
LeeBamber
TGC Lead Developer
24
Years of Service
User Offline
Joined: 21st Jan 2000
Location: England
Posted: 9th Oct 2011 06: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...

I drink tea, and in my spare time I write software.
Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 9th Oct 2011 10:26
Quote: "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?
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
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!



pedrolbs
13
Years of Service
User Offline
Joined: 18th Aug 2011
Location: PT
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

Login to post a reply

Server time is: 2024-11-22 03:27:48
Your offset time is: 2024-11-22 03:27:48