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.

Author
Message
Wooly Lamb
21
Years of Service
User Offline
Joined: 7th Apr 2004
Location:
Posted: 10th May 2004 03:13
In my game project I've taken the route that most people using DBP is following right now - using a big level model, possibly lightmap it, and then using NGC dll to figure out the collisions. To say the least, it is the most straightforward way for most newbies like me.

If one follows this particular way, what should be the fastest and most accurate way to calculate the shortest path around obstacles?

I know IanM has made a fantastic A* pathfinding routine, but I don't see a way to implement that in the specific level system I intend to use. I'm not sure, but I think the same goes for all A* pathing algorithms. And if I wish to use dynamic decision making in the AI, wouldn't node based AI be inaccurate?
M00NSHiNE
21
Years of Service
User Offline
Joined: 4th Aug 2003
Location: England, UK
Posted: 10th May 2004 03:48
Expand on the dynamic decision making and node based AI bits. I think I follow you, but you need to clarify it to be sure. I started to design (not code) a sort of pathfinding system that used A* as a basis but allowed much more dynamic travelling. No doubt the NGC ray cast would play an important role. Imagine a building with 4 corners. Now put a node at each corner. These would be the points used to travel. Rather than following a grid, if the object moving can see it, then it just goes for it. Saves computing time. Now this would give much more believable movement (in old A* games such as C&C: Red Alert, units would zigzag towards their target. Using this more dynamic system would give the benefit of better looking movement, plus it doesnt waste time working out the jumps from node to node. The best thing I can recommend for you is to head over to [href]http://www-cs-students.stanford.edu/~amitp/gameprog.html [/href] as this is quite probably one of the best pathfinding resources available.

Wooly Lamb
21
Years of Service
User Offline
Joined: 7th Apr 2004
Location:
Posted: 10th May 2004 04:22 Edited at: 10th May 2004 04:27
Actually, I didn't use dynamic decision making as a technical term. I'm just talking about things like taking level environments into account. Like the AI would go around a wall if its still standing, but if a part of it fell, then the AI goes over the fallen portion.

I'm a newbie, and never worked on pathing before. I've made a simple and crude AI for the enemies in my game. They would first start for the player, if an obstacle is in the path within a certain distance, they change direction to find a free one, then rinse and repeat. It is very weak as sometimes the enemies can blunder about trying to find a free path. As my game is ismetric close-up and the action is like Diablo 2, people might not notice. Actually Diablo 2 uses very dumb AI too.

Can you please explain your idea some more? Most of it went over my head. It would help all of us newbies greatly if there's an algorithm or a tutorial on making a fast pathfinding AI for a grid-less level system. It's one of the hardest part for novices like me.
Sparda
21
Years of Service
User Offline
Joined: 13th Jan 2004
Location: Pacifica
Posted: 10th May 2004 04:39
You won't get very far if you don't you waypoints to start with. At least not at first. Hey even the great games use them, just look at Warcraft 3. Do really those peons can find their way all the way across a huge map, climbing mountains and navigating through forests

There 10 kinds of people, those who understand binary and those who don't
Wooly Lamb
21
Years of Service
User Offline
Joined: 7th Apr 2004
Location:
Posted: 10th May 2004 04:55 Edited at: 10th May 2004 05:50
Yes I know Warcraft 3 uses that technique, I opened up the world editor and found the tile system. It is noticable ingame too. What I want to understand is how FPS or tactical games like Freedom Force implement this without making it noticable.

[edit] Does any of you know how middle-wares like Path-engine (http://www.pathengine.com work? Is it possible to make or use such liabraries for DB?
Sparda
21
Years of Service
User Offline
Joined: 13th Jan 2004
Location: Pacifica
Posted: 10th May 2004 08:09
I think almost all games use waypoints, even Half-life and Counter-Strike (PODBot). There was a CS bot that didn't use waypointing but I can't remember the name... might have been RealBot. If you look at the waypointing system for PODBot you'll notice that the bots are allowed to move along paths but still have some area to roam, not much though. For my pathfinding, I'm using waypoints but the pathfinding is much more reliant on the current situation that the paths between waypoints. That way the paths aren't as noticeable.

There 10 kinds of people, those who understand binary and those who don't
Slayer
21
Years of Service
User Offline
Joined: 15th Nov 2003
Location: CA
Posted: 10th May 2004 08:19
http://darkbasicpro.thegamecreators.com/?m=forum_view&t=25531&b=5

try my little demo.

path findeing is a little hard, im still makeing mine.

I dont know how to spell
Wooly Lamb
21
Years of Service
User Offline
Joined: 7th Apr 2004
Location:
Posted: 11th May 2004 02:17
Wow Slayer, that's very impressive! Only 16 lines of code! Can you please give a basic outline of your pathfinding concept?
Slayer
21
Years of Service
User Offline
Joined: 15th Nov 2003
Location: CA
Posted: 11th May 2004 05:37
well there just some points in 3d space. theres many ways to do path findeing. I think the best one is A* wich isent that hard to make.

I dont know how to spell
Tapewormz
22
Years of Service
User Offline
Joined: 15th Sep 2002
Location: Winnipeg, Mantoba, Canada
Posted: 11th May 2004 07:35
Quote: "I think the best one is A* wich isent that hard to make."


I just wished I could fully understand A*. The whole theory behind it. I've read some meandering blurbs about it, but I'm going to have to go out and buy a book on it.

I'm looking at AI Game Programming Wisdom 1 and 2. I'm also looking at Physics For Game Developers and 3D Math Primer for Graphics and Game Development. I figure, it's going to take me a year to read those four books and actually have a rough understanding of what in the hell they're talking about. hehe

Quote: " Timesoft - Your wife is death. How? NO idea.
But it is murder. REVENGE!!!!!!!!!"

Hands down the funniest synopsis for a game ever. All your base are belong to us!
Jess T
Retired Moderator
21
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Over There... Kablam!
Posted: 11th May 2004 14:13 Edited at: 11th May 2004 14:53
@Tapewormz and others;
A* Pathfinding ( and almost all other tile-based Pathfinding ) works like this:

First, your map/level is divided up into tiles, usually hexagonal tiles, and usually no bigger than the smallest unit size ( ie, in an RTS, the space that a single worker would take up [ in Warcraft, that would be roughly the space that a peasant takes up ] ).

Then, before the main loop is executed, the A* algorithm ( that you create ) checks all the tiles in the map/level to see if they're occupied by a part of the map, lets say a tree or such. This is then marked in an array.
Alternatively, this step can be skipped, but it does help to speed up the Pathfinding algorithm in the main loop.

Once in the loop, when a unit, or object wants to move, the A* Pathfinding algorithm takes over.

Lets say that your unit is on Hex coordinate 0,0 ( Bottom Left ).
And, it wants to move in a diagonal fashion upward to its right
Eg, it wants to travel between the two marked hex's below:



The Start and Destination positions are those marked with
The tiles that are blocked/occupied are marked with

The A* Algorithm is then pretty simple.
It checks the hex to the upper right of the current one ( the logical choice as that would send the unit in a direct line toward the destination. This direction is easily obtained with little trig ). If that hex is available, then the unit is moved to there, and that hex's position in the previously populated array becomes marked as occupied.

The new position of the unit ( marked with an arrow ):


The next top-right hex is checked ( again, sending it in a straight line toward the destination ) This hex is empty, thus the unit moves onto it.

The movement of the unit is now like this:


The next check again checks the upper-right adjacent hex, but the result this time is that it is occupied.
From here, there are two options for the unit to take.
(a) It can move straight upward to go around the blocked hex, or,
(b) it can move to the lower right hex.
(b) is the direction it will move, as the hex in (a) is also occupied/blocked.

The units movement would now look like this:


The next move would be to the upper right hex, as it is the closest to a straight line toward the destination.
After this, the next hex would be either directly above or the upper right, because these two options would result in equal distance from a straight line to the destination.

Then, finally, the last move would move the unit onto the destination ( provided of course that it is not occupied/blocked ).

That is a rather simple explanation, and may not be 100% correct, but if you coded something like that, it would work almost without fail ( You may have to cater for a few special cases etc ).

If you would like me to explain anything further then just ask.
Also, if you'd like to make a correction, or complain about the images, feel free to

Jess.


[EDIT]
Another way to do it would be this:
Instead of checking which position to go to each move, it could all be worked out in one go.

For example, in an RTS, when a unit is given a destination, it needs to find it's way there.

So, instantly, the A* algorithm takes over, and calculates the shortest route to the destination, while avoiding blocked/occupied hex's. Each hex move is stored in a seperate array as a waypoint, and the unit simply moves from waypoint to waypoint untill the destination is reached.

The same method for determining the next hex would apply as above.
[/EDIT]


Team EOD :: Programmer/Logical Engineer/All-Round Nice Guy
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 11th May 2004 15:20 Edited at: 11th May 2004 15:22
You missed a few points on A* there ...

For the current cell, calculate a cost value for all surrounding cells that have not yet been visited. This cost is based on distance travelled so far and the best guess of the distance to travel.

The cell and the cost is pushed onto a list (called the open list).

Once the costs of all surrounding cells have been calculated, the lowest cost cell is selected from the open list, marked as visited, and the process repeats for that cell. This will continue until the cell that is current is the one that you are targetting.

Then you can trace the lowest cost path from start to finish to build your final path.

In A* the costs in my code are calculated like this:

Movement cost
Take the movement cost of the current cell and either
- Add 10 for horizontal or vertical movement
- Add 14 for diagonal movement

Best Guess
Usually the manhatten distance (the x difference + the y difference) multiplied by 10.

I use integer values multiplied up by 10 to keep the maths as integer calculations rather than floating point.

A lot of thought needs to go into the open list. If your implementation is 'naive' then you might end up with a simple array and searching this array each time for the lowest cost item. Alternatively, you could use the heap storage method for your open list (also in Codebase).

EDIT: You might be interested to know that I'm looking at reusing my A* code for my current project which will be a mix between tiles and waypoints. Once I have the code done, I'll post it

*** 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
Jess T
Retired Moderator
21
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Over There... Kablam!
Posted: 11th May 2004 15:26
Ah... *nod's knowingly*

Thanks for that addition Ian Much apreciated.

I'm going to have to bookmark this thread now so that I can refer people here for a nice, easy to understand ( yet basic ) explanation of A*/general Pathfinding.

Thanks again Ian

Jess.


Team EOD :: Programmer/Logical Engineer/All-Round Nice Guy
Wooly Lamb
21
Years of Service
User Offline
Joined: 7th Apr 2004
Location:
Posted: 12th May 2004 05:30 Edited at: 12th May 2004 05:33
Wow! That's quite a lot from my last visit!

JessTicular, thanks for the easy to understand tutorial, it really helps. I did make an algorithm on paper very similar to the simple version of A* you've presented here, but didn't quite figure out how to divide the 3d space into tiny squares, or in your case, hexes; also when I thought I'd use an array to store movement points so the ai agent doesn't get stuck inside 'U' shaped obstacles - I feared it'd be too memory consuming, so I was back to square 1.

The crude AI I described above, actually it projects 8, or if I need it, more, plains around the agent to see which 'square' around it is free, and then moves it there. It works perfectly in the scence in your pictures, and in most cases of my game. The problem is it can get stuck inside U shaped obstacles, and sometimes choose more stupid longer paths as it can't use movement cost calculation.

IanM, thanks for posting on this! The movement cost calculation method and storing them in an array is something I should do with my AI. Tht clears some of the problems I've been facing. Can't wait to see your combination of A* and waypoints.


Now, JessTicular and anyone who wishes to help, how can I implement an A* algorithm in the level system I described above? How can I divide the level into smaller hexes and generate the open list and closed list arrays?

I think this post will help newbies like me greatly.

[edit for typos]
Macrosii
21
Years of Service
User Offline
Joined: 31st Mar 2004
Location: Essex, UK
Posted: 12th May 2004 05:42
Can the spaning tree algorithm help any?
Wooly Lamb
21
Years of Service
User Offline
Joined: 7th Apr 2004
Location:
Posted: 12th May 2004 05:50
I don't even know what spanning tree algorithm is!
Ideajuice
21
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Cyberspace.. out near the edge
Posted: 12th May 2004 06:34
A spanning tree algorithm is a method of finding a way to visit *every* point of a given 'graph'. A minimum spanning tree is a way of visiting every point using the shortest total distance or cost.

A 'graph' in this sense just means each square in your grid (or each hexagon).

Finding the shortest route from a given point to another given point is not the same problem, although the two problems do share a lot of commonality.

And a spanning tree for a given graph must contain both points A and B, so a subset of that spanning tree will definitely give you *a* route between them, but it will not neccessarily be the shortest one.

E Unibus Plurum
Wooly Lamb
21
Years of Service
User Offline
Joined: 7th Apr 2004
Location:
Posted: 12th May 2004 06:43
Spanning tree algorithm sounds slower than finding the shortest route from a given point to another one.

Any ideas on how to split a 3d level in small hexes?
Jess T
Retired Moderator
21
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Over There... Kablam!
Posted: 12th May 2004 12:35
It's not that you split the level into hex's, as such...

The level isn't slplit into hex's at all, that's just how you visuallise it, otherwise it's way too hard to get your head around unless you know how it really works.

But, what you want to do is to create a function that will calculate the centre positions ( X and Z, no need for a height value ) of each of the hex's. Then, this would be stored in the array.

Your array would look something like this:

my_array(100,50,2)

That would be for a map that is 100 hex's accross, and 50 hex's deep. The last dimension would store the X and Z positions ( in array positions 0 and 1 ) along with weather or not that hex is occupied ( in array position 2 ).

A simple way to keep track of which Hex's are occupied etc, would be to keep track of everything in your level right from the start.
ie, if your main character's starting point was at coordinates 530,970 which happened to be hex coordinates 21,43 ( these numbers are just made up ), then you would put in:

my_array(21,43,2) = 1

Thus, that position is now occupied.

Alternatively, you could place all your objects etc, then do circle collision tests from the centre of each hex and check to see if there is anything inside the hex. If there is, mark it, if there isn't, then don't. ( this could be quite costly on the processor though )

Then, in-game, *everytime* something moved, my_array() would be updated with the newly occupied hex, and clearing the previously occupied hex to say it's available.

Hope that I explained it a little more clearly for you
Jess.


Team EOD :: Programmer/Logical Engineer/All-Round Nice Guy
Wooly Lamb
21
Years of Service
User Offline
Joined: 7th Apr 2004
Location:
Posted: 12th May 2004 23:38 Edited at: 12th May 2004 23:47
Thank you Jess!

My graduation tests are going on now, when it's finished, I'll post my AI code based on what I've picked up from this thread, maybe then you can tell me how can I make it more efficient.

[edit] Um, can't anyone comment on my question about middlewares like pathengine.com?
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 13th May 2004 00:34
Q. Does any of you know how middle-wares like Path-engine (http://www.pathengine.com) work?

A. That's an impressive system. I would guess that instead of using waypoints, it uses the vertex joins to indicate a passable path. I wouldn't have a clue on how to code that myself though

Q. Is it possible to make or use such liabraries for DB?

A. Yes, it's possible to interface almost anything with DBPro. With this package however, I couldn't find the cost - I think its a case of 'if you have to ask how much then you can't afford it'

Do you have links to other pathfinding middleware, or is that the only one?

*** 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
The Game
22
Years of Service
User Offline
Joined: 22nd Dec 2002
Location: United States
Posted: 13th May 2004 01:21
I found this open source one that's being developed http://opensteer.sourceforge.net/

I am the game and I want to play.
Tapewormz
22
Years of Service
User Offline
Joined: 15th Sep 2002
Location: Winnipeg, Mantoba, Canada
Posted: 13th May 2004 02:11 Edited at: 13th May 2004 02:21
I understand the part of the formula where F = G + H. Where G is the movement cost 10 for vertical and horizontal movement and 14 for diagonal movement, and H is the heuristic of the distance between A and B. Where A is the starting position and B is the destination.

It's handling the array that confuses me.

I've found two really nice articles on a blitz site that explain the theory.

A* Pathfinding for Beginners (1/2)
http://www.blitzcoder.com/cgi-bin/articles/show_article.pl?f=turtle177610292002201622.html

A* Pathfinding for Beginners (2/2)
http://www.blitzcoder.com/cgi-bin/articles/show_article.pl?f=turtle177610292002202109.html

The part that I'm struggling to understand is how to effectively search for the most efficient path in the array. I've seen code on this, but no comments explaining what it was doing. I just really like knowing how things work is all.

@JessTicular: Hey Jess, how's EOD doing lately?

Quote: " Timesoft - Your wife is death. How? NO idea.
But it is murder. REVENGE!!!!!!!!!"

Hands down the funniest synopsis for a game ever. All your base are belong to us!
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 13th May 2004 02:21
When you say 'array' do you mean the open list?

If so, then what you need for fast and efficient array lookup is a 'heap' store. Search in CodeBase for 'Heap' and look at the code that I posted. There is also a link in the description that will tell you how a heap works.

*** 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
Supremacy
21
Years of Service
User Offline
Joined: 30th Dec 2003
Location:
Posted: 13th May 2004 02:24
hmmmm, really great stuff, i already understood A* some time ago, but what i never could solve (in an easy way) was the smooth movement from x to x, i mean

my problem is:

i have a map that is 100X100 pixels

with an array of (10,10)

know i have a peasent at 1,1 , corresponds to 10X10 in real map, want him to go to 1,2 (move one unit up), how do i make him move ?

i cant really explain my problem because im not english and i dont know the words for this, what i kind off mean is, not making him jump, but instead, point him to the center of the upper square, and move him, i could easely do this with a select/case of 3 dimensions, like

global var_m=0
mov=0

select (mov)
case 1:
idle_waiting_order()

case 2:
point object 1,array_waypoints(nextwayponit_var_X#,nextwayponit_var_Z#),0,(nextwayponit_var_X#,nextwayponit_var_Z#)

case 3:
if distance_to_order>0 then move object 1,10 else mov=1


rem end of code:

of couser this inst working code, its just for you to have an ideia,
my problem is, that i dont wont to use this way, because i dont wont to have an "nextwayponit_var," array, because this is making me to use 3 diferent arrays, i need a trignometrci multiplication of the blocked/unblockd primary A* array, damm im going crazy, i cant explain my problem

can someone generous make a small 2d or 3d tuturial that features a small 100*100 matrix with a 10*10 A* array, and an object, that goes alone trueght the map from one point to another till it reaches the end of the map ? just a demo, doesnot needs to implement player I/0

just a demo

man im stupid, lolol, do you by any god's chance get whats my problem here ? please help ianm or jess, i hope you understand me here, fell like a

I will make urban chaos 2, ive already concepted the story, its my dream, i wont to go to muky foot
Wooly Lamb
21
Years of Service
User Offline
Joined: 7th Apr 2004
Location:
Posted: 13th May 2004 04:56 Edited at: 13th May 2004 04:58
I didn't know of any other middleware than pathengine, and yeah, I guess I'll not be able to afford it anyhow

But OpeenSteer, as mentioned by The Game, is a free one. I couldn't understand much from their website as I've never coded in C++, maybe someone here can, and make an usable liabrary for DB Pro users off it.

[edited out typos]
Tapewormz
22
Years of Service
User Offline
Joined: 15th Sep 2002
Location: Winnipeg, Mantoba, Canada
Posted: 13th May 2004 05:05 Edited at: 13th May 2004 05:17
Quote: "When you say 'array' do you mean the open list?

If so, then what you need for fast and efficient array lookup is a 'heap' store. Search in CodeBase for 'Heap' and look at the code that I posted. There is also a link in the description that will tell you how a heap works.
"


Yeah, the open and closed lists. I've made a program that calculates the first step (heh...one step only laugh, but gotta take the baby steps first...) and it works. If I move my start position or end position anywhere it chooses the correct direction using F=G+H. It's the HEAP that confuses me. How to move forward finding the best path, and if there's an obsticle, check for another path and make sure that the path chosen is the fastest.

I'm not a math guru at all, just basic math with me. It admittedly takes me longer to grasp mathimatical formulas. However, I don't mind spending the extra time actually learning how something works rather than knowing that it does, and trying to build a program around code that works. I think it's the scottish in me or something. I'm really stubborn.

I came across your code a few months ago Ian. I have it downloaded, but I haven't looked at it yet. I'll open it up and read through it and hopefully I'll be able to understand it. Programmers are generally as a rule, horrible doccumentation writers.

Quote: " Timesoft - Your wife is death. How? NO idea.
But it is murder. REVENGE!!!!!!!!!"

Hands down the funniest synopsis for a game ever. All your base are belong to us!
Jess T
Retired Moderator
21
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Over There... Kablam!
Posted: 13th May 2004 13:48
@Tapewormz,

EOD's going extremely well. Our team has expanded to encompass many different members, all with different skills which makes for varied and unique perspectives... Just what we were after
On the game making side, we've actually just recently ( last couple of days ) made some large steps toward our goals... Thanks for the interest.


@Mustra Joao,

The easiest way to do it would be like this:
Create a variable that holds the speed that your unit moves.

unitspeed = 5

Then, when moving the unit, just use the "Point Object" command to get it facing in the right direction, then move it using the "unitspeed" variable you made before the loop.

Then, to check if it has arrived at it's destination, you do a quick check like this:

objx = Object Position X(obj)
objz = Object Position Z(obj)
If objx > destX - (unitspeed / 2) And objx < destX + (unitspeed / 2)
If objz > destZ - (unitspeed / 2) And objz < destZ + (unitspeed / 2)
`unit is now at it's destination point
EndIf
EndIf


I hope that was explained clearly enough for you.

Jess.


Team EOD :: Programmer/Logical Engineer/All-Round Nice Guy
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 13th May 2004 15:11
Quote: "Programmers are generally as a rule, horrible doccumentation writers"


In that case, I class myself as a programmer. That's why I provided that link in the description

*** 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
Tapewormz
22
Years of Service
User Offline
Joined: 15th Sep 2002
Location: Winnipeg, Mantoba, Canada
Posted: 14th May 2004 04:35
Quote: "Quote: "Programmers are generally as a rule, horrible doccumentation writers"

In that case, I class myself as a programmer. That's why I provided that link in the description "




Quote: " Timesoft - Your wife is death. How? NO idea.
But it is murder. REVENGE!!!!!!!!!"

Hands down the funniest synopsis for a game ever. All your base are belong to us!
Sparda
21
Years of Service
User Offline
Joined: 13th Jan 2004
Location: Pacifica
Posted: 14th May 2004 05:37
My A* code is good, but I still can't get the ai to avoid deadends (ie. concave rooms, rooms to the nether realm, etc). Any suggestions?

There 10 kinds of people, those who understand binary and those who don't
Tapewormz
22
Years of Service
User Offline
Joined: 15th Sep 2002
Location: Winnipeg, Mantoba, Canada
Posted: 14th May 2004 06:07 Edited at: 14th May 2004 06:08
You have to backtrack your closed list (I think) and look for another path and move from there. Uh, again I'm new to this so I could be wrong. Your closed list should contain all the paths found?

Quote: " Timesoft - Your wife is death. How? NO idea.
But it is murder. REVENGE!!!!!!!!!"

Hands down the funniest synopsis for a game ever. All your base are belong to us!
Ideajuice
21
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Cyberspace.. out near the edge
Posted: 14th May 2004 06:11 Edited at: 14th May 2004 06:12
You can always manually create another grid array and put weights in it to penalize going in those areas.

You could create this one time before you even ship your game. Write an algorithm to examine your map and calculate the 'dead endedness' of each cell.

How you do that is another big questions, but you could simply 'paint' a bitmap in a paint package and then load it into DB and analyze the color of the pixels. Or you could just assign each cell a number that represents how many other cells can be moved to from there.. this would penalize going down narrow corridors vs. open spaces. Whatever method you can come up with.

Once you have this extra grid, add the penalty cost of those cells into the equation that calculates the cost of moving into a specific cell.

The second part of the article mentioned above by Tapewormz has lots of good ideas for extensions like that to the basic algorithm.

[EDIT] - sory.. I thought your code was working and you just didn't like it going *near* things like that.

E Unibus Plurum
Jess T
Retired Moderator
21
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Over There... Kablam!
Posted: 14th May 2004 08:27
You have to impliment the way I said of checking to see if the next cell is blocked or not. Then, if it gets caught in a horse-shoe type of space, temporaraly mark the cell that is in the middle of the horse shoe as blocked.
Re-calculate the next move, then set the cell as unblocked again.

That's a simple way around it, but the best way is to calculate the move cost as IanM said, which should prevent your units getting trapped.

Jess.


Team EOD :: Programmer/Logical Engineer/All-Round Nice Guy
Ian T
22
Years of Service
User Offline
Joined: 12th Sep 2002
Location: Around
Posted: 15th May 2004 04:40
For very large maps, would I be wrong in saying that it might be best to create a large scale A* calculation also, where blocked squares were only considered wholly impassible mega-tiles, calculate the mega-distance, and then idividually calculate each mega-tile of movement? Less calculation is wasted if the movement is cut short that way.

Ideajuice
21
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Cyberspace.. out near the edge
Posted: 15th May 2004 08:02
Read the second article posted several posts up by Tapewormz. It's excellent, and talks about precisely that kind of extension.

E Unibus Plurum
MasterChief
21
Years of Service
User Offline
Joined: 1st Jan 2004
Location: Washington, USA
Posted: 16th May 2004 00:02
WOW! this thread rocks! Thanks to all you gentlemen who provided input. I've learned so much! This would make a great tutorial.

Warm regards,
Doyle
Mentor
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: United Kingdom
Posted: 16th May 2004 00:31 Edited at: 16th May 2004 00:37
heres something I made while back for DB classic, it`s a pathfinder for those who eyes glaze over when A* is discussed, all it does is use an array to represent the map with cells marked as passable or blocked, then it fills in the cells around the target with numbers that represent a move towards that block, then it parses the array again and adds more "pointers", and so on until the array is filled, then all you have to do is to follow the directions indicated by the numbers from any point on the map and you will reach the target, it isn`t blocked by U sections or anything else, if there is a path then it will find it, plus it finds the shortest path in most cases (I would say "all" cases, but I can`t prove that), heres the code I wrote just read the comments to follow it, cheers.



Mentor.

PS: the code is messy and "unstructured" since it was tweaked for speed, not elegance

PC1: P4 hyperthreading 3ghz, 1gig mem, 2x160gig hd`s, Nvidia FX5900 gfx, 6 way surround sound, PC2: AMD 1.2ghz, 512mb ram, FX5200 ultra gfx, stereo 16 bit soundblaster, ups.

Login to post a reply

Server time is: 2025-06-06 16:59:27
Your offset time is: 2025-06-06 16:59:27