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.

Code Snippets / [dbc] path finder flow

Author
Message
Alien 001
19
Years of Service
User Offline
Joined: 4th Jul 2005
Location: Gateshead UK
Posted: 9th Oct 2007 13:17
Here is an new way of finding an path. I have check the net and i can not find another path finder like it. it you do could you post an message. time to get to the snippet. It is an old version but it shows the basic of how it works. sorry no comments within the snippet. There are few way to make it faster also some that works for an RTS game. I still have one or two to test out. The path finder is in two parts one that generates the map data and the other one that finds the path. you will find that it is faster that A* path finder. about 80ms for A* , 0-16ms . but the times are depend on the type of map.

here is the snippet.


if you want to see the code in an rts game here is the link.
http://forum.thegamecreators.com/?m=forum_view&t=110489&b=8
still working on the game.
luke810
18
Years of Service
User Offline
Joined: 4th Sep 2006
Location: United States
Posted: 15th Oct 2007 05:39
It looks really good but gets stuck up on certain arrangements of blocks and sometimes it just goes over a block like it isn't there. You might want to check that out before you finish the game or the player's custom maps could have arrangements that freeze up the game. I did my own Astar algorithm for my RTS but your's runs quite a bit faster on average.
Green7
18
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: Switzerland
Posted: 15th Oct 2007 23:59 Edited at: 16th Oct 2007 00:02
@luke810: this is no offense, but are you sure? did you always hit START after drawing new blocks? i noticed that he goes over blocks if i did not hit start. but that is how it should be i think, no recalculation without START. i could not manage to make it fail...

EDIT: ok, it hangs itself if you set the target into a closed room...

luke810
18
Years of Service
User Offline
Joined: 4th Sep 2006
Location: United States
Posted: 16th Oct 2007 05:16
It must have been the start thing for the draw over blocks. But if you do a couple sworls and try to find a path out it hangs up.
Green7
18
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: Switzerland
Posted: 17th Oct 2007 00:21
that's true... and if you set no start and end it does too. but its a nice thing at all. so, respect, i think i could never do such a thing. im more for optical stuff, less the logical one.

Ankillito
17
Years of Service
User Offline
Joined: 10th Dec 2006
Location: Litigious California
Posted: 18th Oct 2007 01:48
wow. I have never understood how a COMPUTER could find a way out of a maze, especially that quickly! I deffinately need to figure out your code once I have time...

http://forum.thegamecreators.com/xt/xt_apollo_pic.php?i=1234759
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 24th Oct 2007 17:30
I came up with something a lot like this but could never get it to work properly. Nice work
The only thing I don't like is that it can move diagonally; when on a square grid that is going through a single pixel.
why do you set emulation on?

If you have the time could you please annotate your code, I'm having trouble following it.

Alien 001
19
Years of Service
User Offline
Joined: 4th Jul 2005
Location: Gateshead UK
Posted: 2nd Nov 2007 12:35 Edited at: 2nd Nov 2007 12:36
I made the snippet to test the idear of an path finder. I have tried to make an A* path finder but i could not get it to work. Then one night i was think about how i could do one. then it come to me, What about you start at the desition position and direct all position around the point to that direction. here is what is does. in an 5x5 grid

where 0 is the desition position.
where -1 is an blank space you can move to this position
where -2 is an wall you cannot move to this position
where S is the starting postion of something that is going to move to D
Where D is the desition.
-1 -1 -1 -1 -1
-1 -1 -1 -1 -1
-1 D -2 S -1
-1 -1 -1 -1 -1
-1 -1 -1 -1 -1

set the desition position to the value of 0.
-1 -1 -1 -1 -1
-1 -1 -1 -1 -1
-1 0 -2 -1 -1
-1 -1 -1 -1 -1
-1 -1 -1 -1 -1

search for current number which at the start is 0. If there is -1 around that position then that position value = current value + 1. here is the next setp.
-1 -1 -1 -1 -1
1 1 -1 -1 -1
1 0 -2 -1 -1
1 1 -1 -1 -1
-1 -1 -1 -1 -1

2 2 2 -1 -1
1 1 2 -1 -1
1 0 -2 -1 -1
1 1 2 -1 -1
2 2 2 -1 -1

2 2 2 3 -1
1 1 2 3 -1
1 0 -2 -1 -1
1 1 2 3 -1
2 2 2 3 -1

2 2 2 3 4
1 1 2 3 4
1 0 -2 4 4
1 1 2 3 4
2 2 2 3 4

This is where is a found a good name for it. All to position point to the desition on the map. or all the point flow to the desition.

that is it for the calulate the map data. now for the path
it is very simple all it does is search around the current position and if there is a value = current value - 1 then move to that position. and that is that. so the path would be 3,2,1,0.
2 2 2 3 4
1 s1 s2 s3 4
1 s0 -2 s4 4
1 s1 s2 s3 4
2 2 2 3 4
The s show the path but there are 2 of then so whick on to take. there both have to same distance. in the snippet it is decided by the order of the if endif staments.

Green7 ... you do have to hit the start button when you have draw new walls. but not when you change to start position.

luke810... it could be that is does not cut the walls.

OBese87... the example at the top sould help you.
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 2nd Nov 2007 19:44 Edited at: 2nd Nov 2007 19:47
Very Clever. You come up with some very interesting programs.

You should enter the DBC challenges.

Enjoy your day.
PALMER
16
Years of Service
User Offline
Joined: 20th Jan 2008
Location: West Sussex
Posted: 17th Feb 2008 17:38
I read you made a A* finder had problems with it.
If you search Codebase "Pathfinder" or "AI" You will find A* By Mince.

I wrote it recently its well documented and very easy to understand.

I am currently making a RTS too, I have just made A Path finder (Today)that can work in the background.
It also has a stack so just add path_needed(startx,starty,destx,desty,unit) to the stack, then
when each path is found flag it,> unit(unit_num).has_path = 1.

I have worker units, fighting units and I think it would be a good idea to make a seperate pathfinder for each type.

Maybe you got it all sorted now, but if not it may help you.
I will post the new Pathfinder to codebase tomo I am sure it will help.

Login to post a reply

Server time is: 2024-11-22 13:09:14
Your offset time is: 2024-11-22 13:09:14