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.

2D All the way! / 2D pathfinding....i'm in need of aid!

Author
Message
Prep
22
Years of Service
User Offline
Joined: 17th Nov 2003
Location:
Posted: 13th May 2004 00:15
I just tried to post a rather large and somewhat amusing post about how awful my current movement AI is...it works on the premises that if its X position and Y are greater then the pc then randomly move up or left. Genius eh? Anyway that post managed to disappear when I pressed space and was gifted with learning the forum rules (?) ah well.

To cut a long story short (relatively) my current movement AI is crud, it gets stuck in little corners and while it often does get to the PC it often doesn't.

I'm after advice on writing a pathfinding routine where to start and such, some example code is always helpful but I know its often too much to ask.

Specifics, my games turn based, always fort or a 16,12 grid with varying bits of impassable terrain and cover from ranged attacks.

I have attached my current movement "AI" (or the better part of it, its called several times for the same creature if it has more then 1 move a turn, it varries depending on what it is)

If I have been too vague in what I ask please ask for clarifican, i'm really at a loss of where to go, and I looked at that A* pathfinding and become very scared.

I think the below functions explain themselves rather well as they are pretty basic.

Thanks for any wise words...or unwise ones...any words will do really...

Rest of the games coming on well though.

To be no more, sad cure.
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 13th May 2004 01:01
Aha, it may be too much for you to ask for example code, but that's what you are going to get anyway

I worked on a fairly flexible grid-based A* code last year, and I posted the results in the CodeBase : http://www.thegamecreators.com/?m=codebase_view&i=56984d6fa64dd67ceb1e01c8d835c957

Feel free to study it, modify it, and generally rip it off

*** Coming soon - Network Plug-in - Check my site for info ***
For free Plug-ins, source and the Interface library for Visual C++ 6, .NET and now for Dev-C++ http://www.matrix1.demon.co.uk
Prep
22
Years of Service
User Offline
Joined: 17th Nov 2003
Location:
Posted: 13th May 2004 23:16
After looking at your wonderful masterful almighty godlike code of greatness for several hours I am no longer scared; perhaps cowed, but no longer scared.

Even more amazingly I managed to bodge it in with a minimal amount of effort...although it has taken my game over 5000 lines now which is starting to get clumbersome.

Anyway thanks for the help, assuming you don't mind me completely *coughs* borrowing the code

You are my new diety...I will spread the word to the non-believers!

Hail IanM deity of all that is code and numbers and er... pathfinding!

If you didn't get it already, thanks you have been a great help to me. There isn't a smiley that would do this justice, so i'll use a er... gameboy instead...

To be no more, sad cure.
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 14th May 2004 22:09
Nice. It's good that you could 'use' it

Just a note on your code size - The path-finding code itself was designed to be held in a separate file for inclusion using the IDE. Did you use it this way, or paste it into your main source file?

*** Coming soon - Network Plug-in - Check my site for info ***
For free Plug-ins, source and the Interface library for Visual C++ 6, .NET and now for Dev-C++ http://www.matrix1.demon.co.uk
Prep
22
Years of Service
User Offline
Joined: 17th Nov 2003
Location:
Posted: 15th May 2004 20:38
I included it; apart from the globals and types which I shoved with the rest of my similar deleclarations.

I have split my code into a varity of files to make it somewhat easier to keep track of but its often just as confusing when debuging.

What would be nice if included files line numbers counted from the end of the file they are following. ah wel, a man can dream.

To be no more, sad cure.

Login to post a reply

Server time is: 2026-06-09 13:56:14
Your offset time is: 2026-06-09 13:56:14