Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 16 17 [18] 19 20 ... 26

Author Topic: Improving Pathfinding. (Computer sciency)  (Read 64045 times)

Sunken

  • Bay Watcher
  • Wabewalker
    • View Profile
Re: Improving Pathfinding. (Computer sciency)
« Reply #255 on: April 08, 2011, 12:59:34 pm »

Kohaku:
Doesn't your extra storage at each level in the tree negate any gains from having a tree structure in the first place?

And won't the resulting paths be silly when the shortest path is a cross-branch step? For a simple example, consider a map that is only one huge ring-shaped tunnel (or series of rooms). Opposite the root node in the ring will be two nodes which are only connected through the root node - so the path found will go all the way around the ring unnecessarily?

Pardon me if I've misunderstood, but it seems like you're trying to squeeze performance out of pathing that is provably theoretically impossible - unless the map is *actually* a tree, topologically!
Logged
Alpha version? More like elf aversion!

Draco18s

  • Bay Watcher
    • View Profile
Re: Improving Pathfinding. (Computer sciency)
« Reply #256 on: April 08, 2011, 01:21:58 pm »

You're confusing storage with processing.  Storage we have plenty of, processing we're using too much of.

By storing the data in the tree you trade away CPU usage for more RAM footprint.
Logged

NW_Kohaku

  • Bay Watcher
  • [ETHIC:SCIENCE_FOR_FUN: REQUIRED]
    • View Profile
Re: Improving Pathfinding. (Computer sciency)
« Reply #257 on: April 08, 2011, 03:26:41 pm »

Kohaku:
Doesn't your extra storage at each level in the tree negate any gains from having a tree structure in the first place?

And won't the resulting paths be silly when the shortest path is a cross-branch step? For a simple example, consider a map that is only one huge ring-shaped tunnel (or series of rooms). Opposite the root node in the ring will be two nodes which are only connected through the root node - so the path found will go all the way around the ring unnecessarily?

Pardon me if I've misunderstood, but it seems like you're trying to squeeze performance out of pathing that is provably theoretically impossible - unless the map is *actually* a tree, topologically!

Draco18s has already responded to the first paragraph, so I'll skip that.

As for the second, you're right - you will return a valid, if theoretically unoptimized path if you simply go for the simplest, fastest, first path you can find.  In some ways, this might be preferable (if you want faster pathfinding, even if it costs you optimal pathfinding in return), but there are ways to return more optimal paths, although they have some costs associated with them.  I simply left them out of that last post I made, because I wanted to keep the post simpler.

In the first method, (let's use Wikipedia's page on trees for an illustration), let's assume that we found a path in that tree from the "5" node on the bottom left to the "9" node on the right.  This would return a path of "5->6->7->2->5->9", but at the same time, 7 and 5 are connected, so you can cut out the path with 2 inside of it.

When making that original chain of nodes, you basically are only looking for going up and down the tree, not laterally - you go "down" the tree ("down" being towards the roots) until you find a route directly up the tree you can follow.  To do this, you have a list of all the points "up the tree" from a given node.  Once you have that chain, however, you can look for lateral shortcuts by simply comparing all the connections (up, down, or lateral on the tree) that allow a given node to bypass one or more steps in the chain.

This method has a complexity of an additional O(n^2/2) where n is the length of the chain you returned previously.  It winds up with some extra memory calls, but should still be much faster than A*-ing the entire fort.

This will basically return you the previous path, but with a few shortcuts taken where they are found.



The other option is more complex, and will return you an optimal route at a greater cost, especially memory-wise. 

Let's look at the example picture I made earlier, again, because this was something I made to try to illustrate the exact problem you were pointing out in my idea, when I realized it was there.

Spoiler: big picture again (click to show/hide)

The same organizational rules from the previous times I used this graph still apply - bright red stairwell is the root node (or the lowest-level node visible on this level, at least), and the changing colors radiating out from it represent lower levels of nodes (with dividers in the red-orange "ring" hallway to denote different branches on the same layer of the tree).

We path from (S)tart to (F)inish.

This map assumes rectangular nodes and doors as their own personal nodes.

The last method I mentioned will return the blue line.  Although the red line really should go through the other door I punched in the F-room late in making the graph, the red line basically demonstrates an optimal path (going through the southern door would be 1 tile faster). (Also, the F-Room should have been recolored yellow-green instead of just green, as it connects to a yellow door node.)

Now, again, at least in this case, the blue line actually returns a sub-optimal but still acceptably inefficient path.  Rather than going to the central stairwell, it takes the "lateral shortcut" by going from the western red-orange "ring hallway" node to the northern red-orange "ring hallway" node before going back "up the tree" by going through the hallways, door, and finally hitting the green F-room. 

I cannot make a "lateral shortcut" with the pathfinding to use the yellow-orange hallway next to "D" on the map because it is not in the pathfinding chain I originally constructed.

In order to actually make that path potentially show up, I would have to make a much slower, and more complex method of building that chain of connections in the first place.  This means that we are going to have to search for more than just a path, but an optimal path, and this means that we have to start storing much more data to actually search for what is optimal, and what is not. 

For example, we can make the red line a potential returnable path if we were to include the green "F" room as being "up the tree" from the western orange hallway, as well as storing it as "up the tree" from the northern orange hallway - basically duplicating the amount of data. 

This means that every hallway node that connects to a given node higher than its own tier on the tree is recorded as being "directly up from it", which means that all of that area in the northwestern arc between the two big orange hallways has their nodes pointed to in the big hash list of nodes "up the tree" from both hallways. 

This becomes very problematic as you get many more small nodes clogging up the diagram - the size of these lists increases geometrically with the number of layers of nodes we're dealing with if we use this method.  Using some sort of method to trim down on the actual numbers of nodes in the data structure would significantly help trim down the size of the resulting data structure.  Either multiple layers of nodes, or more permissive node-constructing methods would keep the overall size of the tree down. 
Logged
Personally, I like [DF] because after climbing the damned learning cliff, I'm too elitist to consider not liking it.
"And no Frankenstein-esque body part stitching?"
"Not yet"

Improved Farming
Class Warfare

NW_Kohaku

  • Bay Watcher
  • [ETHIC:SCIENCE_FOR_FUN: REQUIRED]
    • View Profile
Re: Improving Pathfinding. (Computer sciency)
« Reply #258 on: April 08, 2011, 03:27:50 pm »

Actually, I think I've thought of a much simpler/better way to explain what this tree system would represent.

Think of your address.  Let's assume you want to get somewhere.  Let's say, oh, 123 Sesame Street, which is in New York City, which is in New York, which is in The United States of America, which is on Earth, which is in the Sol System, which is in The Milky Way Galaxy.

So, if we ask the computer "Can you tell me how to get to Sesame Street?" (sorry, sorry!) we start by asking, "Are we on Sesame Street already?" "No."  OK, then, we have to search a broader area.  We know that Sesame Street is in New York City, so we have to ask, "Are we in New York City already?" "No."  Then we have to look broader still, "Are we in New York State already?" "No." Go further out, "Are we in the USA already?" "Yes."  Well, OK, then, we only have to look as far as traveling inside the USA, and don't have to ask ourselves how to get to the Sol System or rent a space ship or anything. 

From there, we can tell that we are in state , and need to travel on the interstate/national level to get to the New York State area, then into the New York City area on a state level, then onto Sesame Street on a city level, then to the specific address of Sesame Street want to get to on a street level.

This is why this isn't a matter of local pathfinding - it just assumes something else handles local pathfinding for it.  This works better for the longest-range pathfinding, and tells the local pathfinding to stay within the borders of one locality when looking for a path that is within one relatively-sized area instead of another.
Logged
Personally, I like [DF] because after climbing the damned learning cliff, I'm too elitist to consider not liking it.
"And no Frankenstein-esque body part stitching?"
"Not yet"

Improved Farming
Class Warfare

Sunken

  • Bay Watcher
  • Wabewalker
    • View Profile
Re: Improving Pathfinding. (Computer sciency)
« Reply #259 on: April 09, 2011, 12:14:13 am »

You're confusing storage with processing.  Storage we have plenty of, processing we're using too much of.

By storing the data in the tree you trade away CPU usage for more RAM footprint.
You misunderstand me; I meant that the extra storage has to be searched as well for each node, costing CPU. Even if it's a hash map, if it has to be done for every node it's still going to affect the time complexity.
Logged
Alpha version? More like elf aversion!

Sunken

  • Bay Watcher
  • Wabewalker
    • View Profile
Re: Improving Pathfinding. (Computer sciency)
« Reply #260 on: April 09, 2011, 12:18:59 am »

Actually, I think I've thought of a much simpler/better way to explain what this tree system would represent.

Think of your address.  Let's assume you want to get somewhere.  Let's say, oh, 123 Sesame Street, which is in New York City, which is in New York, which is in The United States of America, which is on Earth, which is in the Sol System, which is in The Milky Way Galaxy.

So, if we ask the computer "Can you tell me how to get to Sesame Street?" (sorry, sorry!) we start by asking, "Are we on Sesame Street already?" "No."  OK, then, we have to search a broader area.  We know that Sesame Street is in New York City, so we have to ask, "Are we in New York City already?" "No."  Then we have to look broader still, "Are we in New York State already?" "No." Go further out, "Are we in the USA already?" "Yes."  Well, OK, then, we only have to look as far as traveling inside the USA, and don't have to ask ourselves how to get to the Sol System or rent a space ship or anything. 

From there, we can tell that we are in state , and need to travel on the interstate/national level to get to the New York State area, then into the New York City area on a state level, then onto Sesame Street on a city level, then to the specific address of Sesame Street want to get to on a street level.

This is why this isn't a matter of local pathfinding - it just assumes something else handles local pathfinding for it.  This works better for the longest-range pathfinding, and tells the local pathfinding to stay within the borders of one locality when looking for a path that is within one relatively-sized area instead of another.
Yeah, this is the essence of hierarchical pathfinding, and it is pretty much what we do as humans when trying to plan how to get somewhere on a large scale.
The trouble is always how to delineate the different units, though. With cities and planets, at least, it's easy - they're clearly defined and well separated. There's nothing so neat about a Dwarf Fortress map. Rooms are one thing, but how are they supposed to be clustered together into larger units? It's not obvious.
Logged
Alpha version? More like elf aversion!

Draco18s

  • Bay Watcher
    • View Profile
Re: Improving Pathfinding. (Computer sciency)
« Reply #261 on: April 09, 2011, 12:33:09 am »

You misunderstand me; I meant that the extra storage has to be searched as well for each node, costing CPU. Even if it's a hash map, if it has to be done for every node it's still going to affect the time complexity.

It's not extra data for extra data's sake.

Lets put it like this:
You're looking for your keys.  You don't remember where you left them or when it was that you last had them.  They're somewhere in your house.

The current pathfinding method is equivalent to going from room to room to room in your house and itemizing everything in each room, on each shelf in each cupboard and every drawr, one at a time until you locate your keys.  Ok, not quite.  A* does make some generally good guesses about where to search next that makes it slightly better than the analogy here, which is equivalent to either BFS.

The pathfinding optimiations we're talking about are more like this:

You don't know where your keys are...but you do know they're not in the fridge or in the eating utensil drawer.  So instead of searching every square inch of your house you check your pants pockets (usual place), the bedside table (where you left them yesterday), and next to the phone (ah, here they are.  That's right, the phone was ringing when I came in earlier!)

Rather than having to search each tile to find a path, we're instead checking in a more general sense of where to look to start looking.  By having a much smaller search space you increase the search performance by a huge factor.  You're not searching the extra data, but rather using the extra data as a search space.

Hmm.

Like this.  Imagine a huge grid of tiles, featureless plane.  Millions of tiles.  Your job: find the distance from point A to point B by walking on each one and counting, "one, two three..."  It's going to take a while.

Now imagine that every 10 squares there's a thick border.  And every hundred a huge dark border even more recognizable than the one every 10.  You realize that your start and end locations are not only not in the same 10-square, they're not even in neighboring 100 squares!  So rather than counting each tile you generalize.  You count hundred-squares.  You find that there are 4.  Next you count the partial hundred-squares using the ten-squares.  There's 6 of those, two on one end, four on the other.  Finally you count the last remaining distance.  13.  9 tiles on one end, four on the other.  How far's the distance?

One, two, three, four....
Logged

Sunken

  • Bay Watcher
  • Wabewalker
    • View Profile
Re: Improving Pathfinding. (Computer sciency)
« Reply #262 on: April 09, 2011, 06:19:49 am »

You misunderstand me; I meant that the extra storage has to be searched as well for each node, costing CPU. Even if it's a hash map, if it has to be done for every node it's still going to affect the time complexity.
Now imagine that every 10 squares there's a thick border.  And every hundred a huge dark border even more recognizable than the one every 10.  You realize that your start and end locations are not only not in the same 10-square, they're not even in neighboring 100 squares!  So rather than counting each tile you generalize.  You count hundred-squares.  You find that there are 4.  Next you count the partial hundred-squares using the ten-squares.  There's 6 of those, two on one end, four on the other.  Finally you count the last remaining distance.  13.  9 tiles on one end, four on the other.  How far's the distance?

One, two, three, four....
Except, of course, in that scheme nothing needs to be stored because the hierarchical structure is implicit. Not so in Kohaku's scheme. If each square at each scale had to keep an explicit list (or hash table) of all the smallest-scale squares that are in it, it wouldn't look so nice anymore.
Logged
Alpha version? More like elf aversion!

Mohican

  • Bay Watcher
    • View Profile
Re: Improving Pathfinding. (Computer sciency)
« Reply #263 on: April 09, 2011, 08:17:15 am »

I am in the mood of writing some code, so I made the "merge node" algorithm, which I used to slice in rectangles some maps (I add all the walkable tiles one by one, like if it was a digged tile).
here is what it gives on some classic maps.

a classic fortress, 304 tiles represented with 14 nodes
Code: [Select]
##################################
###########+++++##################
###########+++++##################
#######+++#+++++#++++++++#########
#######+++#+++++#++++++++#########
#######+++#+++++#++++++++#########
#######++++++++++++++++++#########
###########+++++#++++++++#########
###########+++++#++++++++#########
###########+++++#++++++++#########
###########+++++##################
###########+++++##################
###########+++++##################
###########+++++##################
######++++#+++++##################
######++++#+++++##################
######++++++++++##################
######++++#+++++##################
######++++#+++++##################
######++++#+++++##################
######++++#+++++##################
######++++#+++++##################
######++++#+++++##################
######++++#+++++##################
######++++#+++++##################
######++++#+++++##################
######++++++++++#+++##############
######++++#+++++#+++##############
###########+++++++++##############
###########+++++#+++##############
###########+++++#+++##############
###########+++++##################
###########+++++##################
##################################

Code: [Select]
###################################
###########44444###################
###########44444###################
#######333#44444#11111111##########
#######333#44444#11111111##########
#######333#44444#11111111##########
#######333222222222222222##########
###########55555#77777777##########
###########55555#77777777##########
###########55555#77777777##########
###########55555###################
###########55555###################
###########55555###################
###########55555###################
######<<<<#55555###################
######<<<<#55555###################
######<<<<666666###################
######<<<<#:::::###################
######<<<<#:::::###################
######<<<<#:::::###################
######<<<<#:::::###################
######<<<<#:::::###################
######<<<<#:::::###################
######<<<<#:::::###################
######<<<<#:::::###################
######<<<<#:::::###################
######<<<<888888#===###############
######<<<<#?????#===###############
###########?????9999###############
###########?????#>>>###############
###########?????#>>>###############
###########?????###################
###########?????###################
###################################
###################################

the "corridor", 18 tiles represented by 12 nodes.

Code: [Select]
##################################
##+#+#+#+#+#+#####################
#++++++++++++#####################
##################################
##################################
##################################
##################################
##################################
##################################
##################################
##################################
##################################
##################################
##################################
##################################
##################################
##################################
##################################
##################################
##################################
##################################
##################################
##################################
##################################
##################################
##################################
##################################
##################################
##################################
##################################
##################################
##################################
##################################
##################################


Code: [Select]
###################################
##1#2#3#4#5#6######################
#718293a4b5c6######################
###################################
###################################
###################################
###################################
###################################
###################################
###################################
###################################
###################################
###################################
###################################
###################################
###################################
###################################
###################################
###################################
###################################
###################################
###################################
###################################
###################################
###################################
###################################
###################################
###################################
###################################
###################################
###################################
###################################
###################################
###################################
###################################


the forest, 234 tiles represented with 33 nodes.
Code: [Select]
##################################
#######++++++++++#################
######+++++++++#+#################
######+#++#++#+++#################
######+++++++++++#################
######+++++++#+++#################
######+++++++++++#################
######++++++++++##################
######+++++++++++#################
######+++#+++++++#################
#######++++++++++#################
######+++++++++#+#################
######+++++++++++#################
######+++++#+++++#################
######+++++++++++#################
######++#+++#++++#################
######++++++++++##################
######++++#++++++#################
######+++++++++++#################
######+++++++++#+#################
######++++#++++++#################
######+++++++++++#################
#######++++++++++#################
######++++++++#++#################
##################################
##################################
##################################
##################################
##################################
##################################
##################################
##################################
##################################
##################################
Code: [Select]
###################################
#######1111111111##################
######222222222#3##################
######4#55#66#773##################
######48888888883##################
######4999999#::3##################
######4999999<<<3##################
######4999999<<<###################
######4999999<<<;##################
######4??#>>>>>>;##################
#######??=======;##################
######AAAAAAAAA#;##################
######AAAAAAAAA@;##################
######DDDDD#CCC@;##################
######DDDDDBBBB@;##################
######NN#FFF#GG@;##################
######NNEEEEEEE@###################
######NNHH#JJJJ@K##################
######NNHHIIIII@K##################
######NNHHIIIII#K##################
######NNHH#LLLLLK##################
######NNHHMMMMMMK##################
#######OOOOOOOOOK##################
######PPPPPPPP#QK##################
###################################
###################################
###################################
###################################
###################################
###################################
###################################
###################################
###################################
###################################
###################################


the "teeth" 96 tiles represented with 9 nodes

Code: [Select]
##################################
######++++++++++##################
######++++++++++##################
######+++++++++###################
######+++++++++###################
######+++++++++###################
######+++++++++###################
######++++++++####################
######+++++++#####################
######+++++++#####################
######+++++#######################
######++++########################
######+++#########################
######++##########################
######++##########################
######+###########################
######+###########################
##################################
##################################
##################################
##################################
##################################
##################################
##################################
##################################
##################################
##################################
##################################
##################################
##################################
##################################
##################################
##################################
##################################


Code: [Select]
###################################
######2222222222###################
######2222222222###################
######333333333####################
######333333333####################
######333333333####################
######333333333####################
######11111111#####################
######5555555######################
######5555555######################
######44444########################
######6666#########################
######777##########################
######99###########################
######99###########################
######8############################
######8############################
###################################
###################################
###################################
###################################
###################################
###################################
###################################
###################################
###################################
###################################
###################################
###################################
###################################
###################################
###################################
###################################
###################################
###################################

here is the source code : http://www.megaupload.com/?d=4G4RUAIK
the graph.c is a bunch of function I use to manipulate graph and list (I used the adjacency list  graph representation)

And btw
Quote
The problem is to create nodes while digging out rooms. Niseg's idea makes it easy, because there is no prerequisite for a tile being included in a node, you just check for an adjacent node and add to it. However, with this idea, unless a highly efficient algorithm to create and merge nodes is used, the overhead may outweigh the benefit, and the benefit may be mitigated by highly suboptimal shapes.
My code is still utterly unoptimized and the complexity of the merge function is O(n) in the worst case where n is the number of connections of the node where the tile is merged (O(1) if the digged tile can't be merged). The only real problem of this method is to find out how to (very) efficiently slice the map (see the "classic fortress" the main hall is cut in 8 parts)
« Last Edit: April 09, 2011, 10:03:46 am by Mohican »
Logged

Draco18s

  • Bay Watcher
    • View Profile
Re: Improving Pathfinding. (Computer sciency)
« Reply #264 on: April 09, 2011, 10:25:21 am »

Except, of course, in that scheme nothing needs to be stored because the hierarchical structure is implicit. Not so in Kohaku's scheme. If each square at each scale had to keep an explicit list (or hash table) of all the smallest-scale squares that are in it, it wouldn't look so nice anymore.

Doesn't matter if you're explicitly storing larger chunks or implicitly knowing what they are.  The point is that A* takes fewer steps.  The reason this works is because every explicitly defined area is a convex solid, meaning that from any point within its boundaries to any other point within its boundaries there exists an uninterrupted strait line (of unknown length) between them.  A* doesn't need to check of the path exists on the tile level so long as it exists on the "node map" level.
Logged

Sunken

  • Bay Watcher
  • Wabewalker
    • View Profile
Re: Improving Pathfinding. (Computer sciency)
« Reply #265 on: April 09, 2011, 10:50:46 am »

Doesn't matter if you're explicitly storing larger chunks or implicitly knowing what they are.  The point is that A* takes fewer steps.  The reason this works is because every explicitly defined area is a convex solid, meaning that from any point within its boundaries to any other point within its boundaries there exists an uninterrupted strait line (of unknown length) between them.  A* doesn't need to check of the path exists on the tile level so long as it exists on the "node map" level.
Your answer has nothing to do with the tree structure or the hash tables.
Logged
Alpha version? More like elf aversion!

Draco18s

  • Bay Watcher
    • View Profile
Re: Improving Pathfinding. (Computer sciency)
« Reply #266 on: April 09, 2011, 10:58:15 am »

Doesn't matter if you're explicitly storing larger chunks or implicitly knowing what they are.  The point is that A* takes fewer steps.  The reason this works is because every explicitly defined area is a convex solid, meaning that from any point within its boundaries to any other point within its boundaries there exists an uninterrupted strait line (of unknown length) between them.  A* doesn't need to check of the path exists on the tile level so long as it exists on the "node map" level.
Your answer has nothing to do with the tree structure or the hash tables.

Doesn't matter.  The data structure used is one of generalization.  A tile always knows which node it is in in the tree/hash/mesh* thereby ignoring the "search the data structure" part of your worry.  Of course, even that doesn't matter, as searching a data structure of points for a given point is trivial compared to the time that is saved by using the data structure.

*For trees, it actually doesn't matter, it can be determined because the data structure is a god damn tree.  If you don't know how to search a tree, and why it takes O(n) time to search, you don't know how a tree is set up.
Logged

Sunken

  • Bay Watcher
  • Wabewalker
    • View Profile
Re: Improving Pathfinding. (Computer sciency)
« Reply #267 on: April 09, 2011, 11:35:52 am »

Doesn't matter if you're explicitly storing larger chunks or implicitly knowing what they are.  The point is that A* takes fewer steps.  The reason this works is because every explicitly defined area is a convex solid, meaning that from any point within its boundaries to any other point within its boundaries there exists an uninterrupted strait line (of unknown length) between them.  A* doesn't need to check of the path exists on the tile level so long as it exists on the "node map" level.
Your answer has nothing to do with the tree structure or the hash tables.

Doesn't matter.  The data structure used is one of generalization.  A tile always knows which node it is in in the tree/hash/mesh* thereby ignoring the "search the data structure" part of your worry.  Of course, even that doesn't matter, as searching a data structure of points for a given point is trivial compared to the time that is saved by using the data structure.

*For trees, it actually doesn't matter, it can be determined because the data structure is a god damn tree.  If you don't know how to search a tree, and why it takes O(n) time to search, you don't know how a tree is set up.
We're still talking about pathfinding, right? Not about searching for a single node?
I quote:
Quote
Now, in order to search this tree, you start from the starting node, and search the hash list of branches and leaves connected to the starting node.  If the destination node is not in that list, you go down a node on the tree, and search the lower node that connects to the starting node, and see if you can reach the destination node by only going up from there.  If that doesn't work, you keep going down the tree all the way to the roots until you can find a path to the destination node.

Once you find a branch with a connection to the destination node, you just go up the tree, testing which branches will have connections to the destination node, until you finally strike the destination node, itself.
Now tell me how the searching of data structures doesn't impact performance in this algorithm.

I submit: Yes, if you restrict your pathfinding to only considering this star-shaped topology of your map, ignoring any cross-connections, then you can find a path faster like Kohaku says. But
a: Your paths can be arbitrarily bad and
b: Your time cost will be multiplied by a hash table (or similar) lookup (since it occurs at every step) and
c: Your space cost will be much increased

b and c would be mitigated if we had something like the square-in square subdivision you suggested earlier - then a couple of comparisons would do and no extra storage would be needed. But that carries the extra problem that not all space in each super-square is connected. That's been discussed earlier in this thread; you could split each node into multiple ones representing connected subcomponents. This throws the best-case complexity out the window however.
Logged
Alpha version? More like elf aversion!

Niseg

  • Bay Watcher
    • View Profile
Re: Improving Pathfinding. (Computer sciency)
« Reply #268 on: April 09, 2011, 12:28:39 pm »

I added a few things to my simulator. people on modding forum suggested using either the vector heuristic or max. Manhaten always overestimate which is pretty bad.

add a silly path smoother but it's less than optimal.

I am in the mood of writing some code, so I made the "merge node" algorithm, which I used to slice in rectangles some maps (I add all the walkable tiles one by one, like if it was a digged tile).
here is what it gives on some classic maps.

Ok I looked at some of your code I think you should have used an array of structs instead of 3d array . Well doesn't matter.

my idea was to use this data type for node:
Spoiler (click to show/hide)

This can save nodes in any shape even overlapping rooms with max size of 256. There are more useful function like growing and shrinking it to the appropriate room size (adding rows and columns at the edges) .

This data type help you avoid wasting memory on small rooms(I saw your program was going crazy when it couldn't merge). all you need to do is to floodfill (Breadth first) and save the node into a room  rooms. My approach is "a start big, divide map into chunks -> validate room and turn unconnected parts into their own rooms -> connect the rooms with edges -> merge smaller rooms  into bigger rooms  . The general guideline is to avoid creating new rooms unless it's necessary .
Logged
Projects:Path finding simulator(thread) -A*,weighted A*(traffic zones), user set waypoints (path caching), automatic waypoint room navigation,no-cache room navigation.

Mohican

  • Bay Watcher
    • View Profile
Re: Improving Pathfinding. (Computer sciency)
« Reply #269 on: April 09, 2011, 01:24:53 pm »


Ok I looked at some of your code I think you should have used an array of structs instead of 3d array . Well doesn't matter.

my idea was to use this data type for node:
Spoiler (click to show/hide)

This can save nodes in any shape even overlapping rooms with max size of 256. There are more useful function like growing and shrinking it to the appropriate room size (adding rows and columns at the edges) .

I'm not sure I understand your struct , do you define a node by a (at most) 10 edges shape? if so, what are the 2 corners?
how can it store this shape for exemple? (which is convex) (edit: forget this , but still how do you represent this shape and whith how many nodes?)
Code: [Select]
##################
##+#+#+#+#+#######
#++++++++++#######
##################

And more importantly how do you know if you can add a tile to a shape (does the new shape will still be convex?).

But my main goal was to make the function that dinamically change the graph when you add (dig) a new walkable tile not the room slicing function. I just tried to slice the map by digging 1 tile by 1 tile, and it was surprisingly not so bad and pretty fast for a first try.

Feel free to do whatever you want with my code.
I'll try to improve my struct, make the split function, the A* using my struct and the basic A* to have a first idea of the degree of improvement this method gives.
« Last Edit: April 09, 2011, 05:34:10 pm by Mohican »
Logged
Pages: 1 ... 16 17 [18] 19 20 ... 26