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.

DarkBASIC Discussion / A* Pathfinding

Author
Message
pictionaryjr
15
Years of Service
User Offline
Joined: 12th Mar 2009
Location:
Posted: 12th Mar 2010 06:50 Edited at: 12th Mar 2010 07:15
I took my first venture into true AI with A* pathfinding and it turned out pretty good.

The current game I'm making required a little more then the simple follow the leader type pathfinding I used to use, so I decided to look into A* pathfinding and I found out it wasn't too hard. I think I've got a pretty good working example of it. I'm hoping this example will at least help someone get a little better understanding of AI.



The Controls:
-Left click to place blocks
-Right click to erase blocks
-Enter key to randomly place blocks
-Control key to clear all blocks
-Spacekey to activate path finding


The Colors:
-Red = End Point
-Green = Start Point
-Yellow = Explored Point
-Cyan = Seen Point
-Magenta = Path
-Blue = Block



The Example:



TheComet
16
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 12th Mar 2010 09:08
It freezes if you enclose one of the targets.

I also find it weird that it will go through diagonal walls.

Other from that, nice job

TheComet

Ashingda 27
16
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 12th Mar 2010 18:40
@pictionaryjr
That's awsome and good job!

- It also freezes if the start or finnish are not there so you may want to code a safety check.


Quote: "go through diagonal walls"

If it was modify to skip the diagonal checks then it solves this isssue, but the only time to really use this is on tile-based games with restricted movements.
pictionaryjr
15
Years of Service
User Offline
Joined: 12th Mar 2009
Location:
Posted: 13th Mar 2010 00:50 Edited at: 13th Mar 2010 01:36
Yea, I know, I'm just happy I got a basic form of it working. I never really understood it and used to just try and force my character in the general direction of the goal. But with my character getting stuck and stuff. it got a little annoying lol

just for a little notice, i tried fixing the trap and wall glitch but got a little lazy. ill fix it in a bit.

EDIT:

Fixed it now it only moves up down left and right and you can trap it, but it won't freeze up.

Example:



-EDIT:

I found out if you enclose just the green brick it freezes, but if there are any other open points enclosed with the green brick, it will work.

--EDIT:

Alrighty, I finally got it completely working. I just had to check if there were blocks all around the green block and if so just skip pathfinding.

Here's the final (I hope):



Ashingda 27
16
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 13th Mar 2010 01:58 Edited at: 13th Mar 2010 02:03
Quote: "force my character in the general direction of the goal"

LOL I know what you mean! Takes alot of focus to learn A* but it's all worth it.


<Edit>
Now that you got it working, the next step is to speed it up. I notice it takes quite some time for it to search.
pictionaryjr
15
Years of Service
User Offline
Joined: 12th Mar 2009
Location:
Posted: 13th Mar 2010 02:15 Edited at: 13th Mar 2010 02:19
Yea, it expands too far. I think i'm going to add a few more circumstances to narrow the search.

EDIT:

I think I may implement waypoints and also do a sort of time check to see how long it would take to walk the path so it doesnt just go from its parents point. It sometimes heads in the other direction and strays from the path. A time check would make it only use the required blocks. Gots to think of a way to do it.

Login to post a reply

Server time is: 2024-04-27 07:47:00
Your offset time is: 2024-04-27 07:47:00