Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Messages - Mohican

Pages: [1] 2
1
DF Suggestions / Re: Improving Pathfinding. (Computer sciency)
« on: April 12, 2011, 09:29:17 am »
Why shouldn't it be possible to have the computer calculate some lines that follow the best path fairly closely, and then the dwarf just goes along those lines and doesn't have to recalculate until it reaches the end of the line? Then the dwarf doesn't have to figure out where it's going again every time it takes a step. It'd make a 200-dwarf fort a snap.
how do you know if a line follow a path if you don't know the path?

2
DF Suggestions / Re: Improving Pathfinding. (Computer sciency)
« 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.

3
DF Suggestions / Re: Improving Pathfinding. (Computer sciency)
« 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)

4
DF Suggestions / Re: Improving Pathfinding. (Computer sciency)
« on: March 23, 2011, 12:47:32 pm »
Mohican:
While sub-optimal, it's still fewer nodes (in the end that are saved) than the original A* path.
it's true, in the end it'll still be better. But we should start expliciting all the algorithms if we want that Toady give a look.

5
DF Suggestions / Re: Improving Pathfinding. (Computer sciency)
« on: March 23, 2011, 12:03:06 pm »
As far as I've read and noticed A* is a variation of BFS (Breadth First search)  where you prioritize the order in which you go through nodes by using the heuristic function.  here is one of the worst cases:
Code: [Select]
##################
#sSSSSSSS#dDDDDDD#
#A##############J#
#AAAAAAAA#G#H#I#J#
#B########G#H#I#J#
#BBBBBBBB#G#H#I#J#
#C########G#H#I#J#
#CCCCCCCC#G#H#I#J#
#E########G#H#I#J#
#EEEEEEEE#G#H#I#J#
#E########G#H#I#J#
#FFFFFFFFFFFFFFFF#
#FFFFFFFFFFFFFFFF#
##################

As you can see it turns The pathing algorithm to simple  path length 8 and then the sub-pathes between the nodes become a simple short paths which run in best case times .

So if you are asking if it's worth the trouble - it does . The advantages are huge compared to pure A*.  While A* is a global algorithm (runs on the whole map) the node is a local algorithm which runs on a local area. Just think about 10X10 embarks with no performance degradation.

Giving fliers the option of vector Pathing through the air would also do a lot of good . Even though A* is optimal in air it's usually not necessary in air traversal which can use a vector (rise over run - like drawing lines ;) )  which is more or less O(1).  If it hit the wall it would switch to A* and try to find it's "way in".
Do you have a method to be sure your map will be sliced like this and not like that:
Code: [Select]
##################
#sSSSSSSS#dDDDDDD#
#Q##############J#
#AAAAAAAA#G#H#I#J#
#K########G#H#I#J#
#BBBBBBBB#G#H#I#J#
#L########G#H#I#J#
#CCCCCCCC#G#H#I#J#
#M########G#H#I#J#
#EEEEEEEE#G#H#I#J#
#N########G#H#I#J#
#FFFFFFFFFFFHOIPJ#
#FFFFFFFFFFFHOIPJ#
##################

6
DF Suggestions / Re: Improving Pathfinding. (Computer sciency)
« on: March 23, 2011, 10:13:37 am »
Two things:

1) Please describe the Xs better.  I had to read it four times and look at the image to figure out WTF it meant.
2) Why are you making maximum rectangles that overlap?

I've edited my previous post with showing what X I choose each step (I call it Y).
I use these rectangles to be sure to not have a "bad" graph like:
Code: [Select]
AAB
DCB
DEE
It is a possible repesentation of a rectangle that could be trivially represented as one node.
The "depth" of the graph using maximal rectangle is minimal (but there are more connections between nodes), so it's a sure way (the representation is unique) to have a quite optimised representation..

7
DF Suggestions / Re: Improving Pathfinding. (Computer sciency)
« on: March 23, 2011, 09:48:54 am »
the algorithm finding the "maximal" rectangles is very simple:
0)- just take a random tile
[...]
3)- look at all the tiles in this area that are touching a tile that is not in the area, take one of this tile
[...]

I'm not saying this is 'wrong', but I'm wary of aiming for optimality by starting off with a random tile, and continuing with random tiles.

Of all the possible starting/next tiles, there may be one that is the absolute worst-case (creating a very sub-optimal 'optimal' division and/ or leading down the route where the most work is put into the map compared with the savings it ends up giving).
Every step of this algorithm find a new maximal rectangle (The decomposition in maximal rectangle is unique) , so the starting tile doesn't matter, and I may be wrong but I think this algorithm is optimal. Here is an example step by step, the "X" are the choices we look at for the next step (the tiles in the area which are in contact with at least one tile wich is not in the area), the blank represent the area we've already cover. the A,B,C... are the maximal rectangles.

Code: [Select]
##################   ##################   ##################
#+++++#++++#+++++#   #+++++#++++#+++++#   #+++++#++++#+++++#
#+++++#++++#+++++#   #+++++#++++#+++++#   #+++++#++++#+++++#
#+++++###+##+++++#   #+++++###+##+++++#   #+++++###+##+++++# 
#++++++++++++++++#   #++++++++++++++++#   #++++++++++++++++#
#######++++#######   #######++++#######   #######++++#######
#+++++#++++#+X+++#   #+++++#++++#AAAAA#   #+++++#++++#     # we choose randomly a X , there is only one.
#+++++#++++#+++++#   #+++++#++++#AAAAA#   #+++++#++++#     #
#++++++++++++++++#   #+++++++++++AAAAA#   #+++++++++++X    #
#######++++#######   #######++++#######   #######++++#######
#+++++#++++#+++++#   #+++++#++++#+++++#   #+++++#++++#+++++#
#+++++#++++#+++++#   #+++++#++++#+++++#   #+++++#++++#+++++#
#++++++++++++++++#   #++++++++++++++++#   #++++++++++++++++#
##################   ##################   ##################

Code: [Select]

##################   ##################   ##################
#+++++#++++#+++++#   #+++++#++++#+++++#   #+++++#++++#+++++#
#+++++#++++#+++++#   #+++++#++++#+++++#   #+++++#++++#+++++#
#+++++###+##+++++#   #+++++###+##+++++#   #+++++###+##+++++#
#++++++++++++++++#   #++++++++++++++++#   #++++++++++++++++#
#######++++#######   #######++++#######   #######++++####### we choose randomly a X , and call it Y
#+++++#++++#     #   #+++++#++++#     #   #+++++#++++#+++++#
#+++++#++++#     #   #+++++#++++#     #   #+++++#++++#+++++#
#BBBBBBBBBBBBBBBB#   #XXXXX XXXX      #   #XXXXX XXYX      #
#######++++#######   #######++++#######   #######++++#######
#+++++#++++#+++++#   #+++++#++++#+++++#   #+++++#++++#+++++#   
#+++++#++++#+++++#   #+++++#++++#+++++#   #+++++#++++#+++++#   
#++++++++++++++++#   #++++++++++++++++#   #++++++++++++++++#   
##################   ##################   ################## 
 

Code: [Select]

##################   ##################
#+++++#++++#+++++#   #+++++#++++#+++++#
#+++++#++++#+++++#   #+++++#++++#+++++#
#+++++###+##+++++#   #+++++###+##+++++#
#++++++CCCC++++++#   #++++++X XX++++++#
#######CCCC#######   #######    #######
#+++++#CCCC#     #   #+++++#    #     # we make the maximal rectangle from the previous Y, and starting again choosing randomly a X.
#+++++#CCCC#     #   #+++++#    #     #
#XXXXX CCCC      #   #XXXXX           #
#######CCCC#######   #######    ####### 
#+++++#CCCC#+++++#   #+++++#    #+++++#   
#+++++#CCCC#+++++#   #+++++#    #+++++#   
#++++++CCCC++++++#   #++++++Y  X++++++#   
##################   ################## 

Code: [Select]

##################   ##################
#+++++#++++#+++++#   #+++++#++++#+++++#
#+++++#++++#+++++#   #+++++#++++#+++++#
#+++++###+##+++++#   #+++++###+##+++++#
#++++++X XX++++++#   #++++++X YX++++++#
#######    #######   #######    #######
#+++++#    #     #   #+++++#    #     #
#+++++#    #     #   #+++++#    #     #
#XXXXX           #   #XXXXX           #
#######    #######   #######    ####### 
#+++++#    #+++++#   #+++++#    #+++++#   
#+++++#    #+++++#   #+++++#    #+++++#   
#DDDDDDDDDDDDDDDD#   #XXXXX      XXXXX#   
##################   ################## 

Code: [Select]

##################   ##################
#+++++#++E+#+++++#   #+++++#++X+#+++++#
#+++++#++E+#+++++#   #+++++#++X+#+++++#
#+++++###E##+++++#   #+++++### ##+++++#
#++++++X EX++++++#   #++++++X  X++++++#
#######  E #######   #######    #######
#+++++#  E #     #   #+++++#    #     #
#+++++#  E #     #   #+++++#    #     #
#XXXXX   E       #   #XYXXX           #
#######  E #######   #######    ####### 
#+++++#  E #+++++#   #+++++#    #+++++#   
#+++++#  E #+++++#   #+++++#    #+++++#   
#XXXXX   E  XXXXX#   #XXXXX      XXXXX#   
##################   ################## 

Code: [Select]

##################   ##################
#+++++#++X+#+++++#   #+++++#++X+#+++++#
#+++++#++X+#+++++#   #+++++#++X+#+++++#
#+++++### ##+++++#   #+++++### ##+++++#
#++++++X  X++++++#   #++++++Y  X++++++#
#######    #######   #######    #######
#FFFFF#    #     #   #     #    #     #
#FFFFF#    #     #   #     #    #     #
#FFFFF           #   #                #
#######    #######   #######    ####### 
#+++++#    #+++++#   #+++++#    #+++++#   
#+++++#    #+++++#   #+++++#    #+++++#   
#XXXXX      XXXXX#   #XXXXX      XXXXX#   
##################   ##################

Code: [Select]

##################   ##################
#+++++#++X+#+++++#   #+++++#++X+#+++++#
#+++++#++X+#+++++#   #+++++#++Y+#+++++#
#+++++### ##+++++#   #+++++### ##+++++#
#GGGGGGGGGGGGGGGG#   #XXXXX      XXXXX#
#######    #######   #######    #######
#     #    #     #   #     #    #     #
#     #    #     #   #     #    #     #
#                #   #                #
#######    #######   #######    ####### 
#+++++#    #+++++#   #+++++#    #+++++#   
#+++++#    #+++++#   #+++++#    #+++++#   
#XXXXX      XXXXX#   #XXXXX      XXXXX#   
##################   ##################

Code: [Select]

##################   ##################
#+++++#HHHH#+++++#   #+++++#    #+++++#
#+++++#HHHH#+++++#   #+++++#    #+++++#
#+++++### ##+++++#   #+++++### ##+++++#
#XXXXX      XXXXX#   #XXXXX      XYXXX#
#######    #######   #######    #######
#     #    #     #   #     #    #     #
#     #    #     #   #     #    #     #
#                #   #                #
#######    #######   #######    ####### 
#+++++#    #+++++#   #+++++#    #+++++#   
#+++++#    #+++++#   #+++++#    #+++++#   
#XXXXX      XXXXX#   #XXXXX      XXXXX#   
##################   ##################

Code: [Select]

##################   ##################
#+++++#    #IIIII#   #+++++#    #     #
#+++++#    #IIIII#   #+++++#    #     #
#+++++### ##IIIII#   #+++++### ##     #
#XXXXX      IIIII#   #XXXXX           #
#######    #######   #######    #######
#     #    #     #   #     #    #     #   the last steps are trivial
#     #    #     #   #     #    #     #
#                #   #                #
#######    #######   #######    ####### 
#+++++#    #+++++#   #+++++#    #+++++#   
#+++++#    #+++++#   #+++++#    #+++++#   
#XXXXX      XXXXX#   #XXXXX      XXXXX#   
##################   ##################

8
DF Suggestions / Re: Improving Pathfinding. (Computer sciency)
« on: March 23, 2011, 08:00:25 am »

this will be represented by something like that:
Code: [Select]
##################
#22222#1X11#77777#
#22222#1111#77777#
#22222###a##77777#
#22222b6666c77777#
#######6666#######        1
#33333#6666#88888#        |
#33333#6666#88888#    2-b a c-7
#33333g6666d88888#       \|/
#######6666#######    3-g-6-d-8
#44444#6666#55Y55#       / \
#44444#6666#55555#    4-f   e-5
#44444f6666e55555#
##################
The main problem  is how to come  up with that node graph ;) .
Once we have the map sliced in rectangles, obtain the graph is trivial, slicing the map in rectangle is also trivial BUT slicing it optimaly is a much more difficult problem.
The first question to ask is what is an optimal representation? I think it's a representation where the "depth" of the graph (the maximal distance (in nodes) between 2 nodes) is minimal

Code: [Select]
  B D F H          A-B-C-D-E-F-G-H   is the graph representing it , the depth is 8
 ABCDEFGH
Code: [Select]
A B C D                               
EEEEEEEEEEE                           
                                              C
                                              |
                                            A-E-B   is the graph , the depth is 3
                                              |
                                              D
So the 2nd representaion is better because the depth of the graph is smaller than the first one.
I think I may have an idea , let's take my previous example
Code: [Select]
##################
#+++++#+X++#+++++#
#+++++#++++#+++++#
#+++++###+##+++++#
#++++++++++++++++#
#######++++#######
#+++++#++++#+++++#
#+++++#++++#+++++#
#++++++++++++++++#
#######++++#######
#+++++#++++#++Y++#
#+++++#++++#+++++#
#++++++++++++++++#
##################
My idea consist to take all "maximal" rectangles, here are all of them

Code: [Select]
##################   ##################   ##################
#AAAAA#GGGG#CCCCC#   #+++++#++L+#+++++#   #+++++#++++#+++++#
#AAAAA#GGGG#CCCCC#   #+++++#++L+#+++++#   #+++++#++++#+++++#
#AAAAA###+##CCCCC#   #+++++###L##+++++#   #+++++###+##+++++#
#AAAAA+FFFF+CCCCC#   #++++++++L+++++++#   #IIIIIIIIIIIIIIII#
#######FFFF#######   #######++L+#######   #######++++#######
#BBBBB#FFFF#DDDDD#   #+++++#++L+#+++++#   #+++++#++++#+++++#
#BBBBB#FFFF#DDDDD#   #+++++#++L+#+++++#   #+++++#++++#+++++#
#BBBBB+FFFF+DDDDD#   #++++++++L+++++++#   #JJJJJJJJJJJJJJJJ#
#######FFFF#######   #######++L+#######   #######++++#######
#HHHHH#FFFF#EEEEE#   #+++++#++L+#+++++#   #+++++#++++#+++++#
#HHHHH#FFFF#EEEEE#   #+++++#++L+#+++++#   #+++++#++++#+++++#
#HHHHH+FFFF+EEEEE#   #++++++++L+++++++#   #KKKKKKKKKKKKKKKK#
##################   ##################   ##################


My idea is to make a graph using this rectangles (yes they are not disjoint), a node is still a rectangle , and 2 nodes are connected if the 2 rectangles are touching (or overlaping)
so we should have this graph :

then the A* should give us G->L->K->E. Using a classic Funnel algorithm, we should end up with a path, but not the shortest (we don't pass through F).
But I'm sure by doing just a little trick we should end up with the shortest path. What do you think of this?

Edit :
the algorithm finding the "maximal" rectangles is very simple:
0)- just take a random tile
1)- make the maximal rectangle starting with this tile
2)- save this rectangle
3)- look at all the tiles in this area that are touching a tile that is not in the area, take one of this tile
4)- make a new maximal rectangle starting from this tile
5)- repeat to 2) until the area cover the entire map.

9
DF Suggestions / Re: Improving Pathfinding. (Computer sciency)
« on: March 22, 2011, 06:50:51 pm »
Again, the problem I'm saying you seem to be having is that you're drawing distinctions between what I am talking about and what you are talking about that don't really exist.  The difference between the sort of hierarchical node system and a nav mesh is largely nominal.  It doesn't matter whether you call something a "node" or a "convex rectangular cuboid", so long as the code functions basically the same.

What I was talking about with a "highway" system would do exactly the same slicing of the map up into the same nodes, and follow basically the same path.  The only real difference would be that the dwarf would hug the wall when walking through 6 until it came time to start moving diagonally to hit the door.
well then sorry I may have misunderstood what your highway system is, and I'll reread your posts. (things like using limited 12x12x12 nodes, and "internal pathfinding" in your previous post may have induce me in error)


Nodes don't necessarily need to be rectanges every time - a "circular" node will make sense
Yeah, in theory any convex shape should do the job. (but may be difficult to represent)
I think a straight line should be defined as going diagonal then horizontal or vertical OR going first horizontal or vertical then going diagonal.
If we use only one of those definition we have a problem , the straight line [A:B] isnt the same as [B:A], which pose some problem with the convexity. with this definition the corridor problem is solved
Code: [Select]
A B C D
XXXXXXXX

Code: [Select]
B D F H
BBBBBBBB
Yes , the B shape IS convex with the definition of straight line I gave.
but a new problem come with this corridor...
Code: [Select]
A B C D
 A B C D
XXXXXXXX


10
DF Suggestions / Re: Improving Pathfinding. (Computer sciency)
« on: March 22, 2011, 05:26:58 pm »
Whether you call it a nav mesh or not, this is still functionally the same thing we have already been talking about, except for the fact that we are dealing with non-floating-point cubic tiles.  You're coming into the thread, saying we should drop everything, and work on "your system", and then describe "your system" as being almost exactly what we were talking about (except that your is based upon floating-point distances), anyway, and then try telling us how much better your system is.
there isn't any post (except the one of soralin in an other thread) relating to my method , but I don't care this is not MY method , this is just the most efficient method, I didn't invent it.
I don't know why you are talking about float, I never mention it. we use rectangular cube AxBxC where A,B,C are integers.
Also, no, it's not as simple as "it's water now".  The entire node doesn't instantly fill with water.  Only individual tiles fill with water, certain levels of water at a time, and do so sequentially - that means that at one point, there will be water in some of the tiles in one node, and not in other tiles in the node, and you are going to have to start splitting that node up and testing to see whether it fits in with other nearby nodes.  There is an interface point (3/7 water) where swimming creatures and walking creatures can both occupy a tile.  That means those tiles are probably going to be in their own individual nodes, and checking to be put in with other nearby nodes rather frequently, as water sloshes around randomly.  In a situation with 3/7 and 4/7 water in a basin, the 4/7 water is going to be cutting off land access every time that 4/7 water depth shifts around, and that means the nodes are going to be cut up and merged very rapidly with one another.  That's a potentially costly set of calculations to make, and something that can be optimized. 
You have a point here, even if you still don't understand a node represents a cube of tiles of the SAME type, that means there is only tiles with x/7 water in the same cube, so there is no problem for the walking thing, but it could be a lot of node rebuilding during a flood so maybe it could be improved. Though the complexities of the subroutines that add a node , merge 2 nodes , split one or change the type of a node are constant, so the complexity of the function will be linear to the amount of change (if there is 10 changes to do , it'll take as much time as doing 10 times 1 change), so I don't think it's a big deal.
Since I probably need to go into further detail as to why "Funnel" isn't helpful ...
I think I need an example.
Code: [Select]
##################
#+++++#+X++#+++++#
#+++++#++++#+++++#
#+++++###+##+++++#
#++++++++++++++++#
#######++++#######
#+++++#++++#+++++#
#+++++#++++#+++++#
#++++++++++++++++#
#######++++#######
#+++++#++++#++Y++#
#+++++#++++#+++++#
#++++++++++++++++#
##################
this will be represented by something like that:
Code: [Select]
##################
#22222#1X11#77777#
#22222#1111#77777#
#22222###a##77777#
#22222b6666c77777#
#######6666#######        1
#33333#6666#88888#        |
#33333#6666#88888#    2-b a c-7
#33333g6666d88888#       \|/
#######6666#######    3-g-6-d-8
#44444#6666#55Y55#       / \
#44444#6666#55555#    4-f   e-5
#44444f6666e55555#
##################
where 1,2,3,4,5,6,7,8,a,b,c,d,e,f,g are the nodes of the graph, X and Y the points we try to find a path for. X is in 1 , Y in 5.
the A* will tell us , the path go through 1->a->6->e->5, but this is NOT the path, you have all the necessary information to easily find it , but you don't have it yet , you need the funnel algorithm (which is a very simple algorithm with integers mesh) to find out the exact path:
Code: [Select]
##################
#+++++#+X++#+++++#
#+++++#++++#+++++#
#+++++###A##+++++#
#++++++++++++++++#
#######++++#######
#+++++#++++#+++++#
#+++++#++++#+++++#
#++++++++++++++++#
#######++++#######
#+++++#++++#++Y++#
#+++++#++++#+++++#
#+++++++++BC+++++#
##################
Wich means go in straight line from X to A , then go in straight line from A to B , then go in straight line from B to C , then go in straight line from C to Y. You cant skip this step, knowing by wich cube you have to go through is not enough. This algorithm is extremly fast , and the A* has been through only 4-5 nodes instead of about 50 with the current method. I hope I've been clear and my post is understandable.

EDIT:
However there are problems.  The way the zones are created and coalesced has a huge effect on pathfinding.
For example a corridor with cubby holes could be represented (at least) two ways.  Letters represent pathfinding zones:

Code: [Select]
A B C D
XXXXXXXX


Code: [Select]
B D F H
ABCDEFGH

The second case is a bit of a disaster I think?
yes you are right, there is multiple possibilities to represent the same zone, and some are more optimized than other, I can't see right now a way to find out how to represent it optimaly, maybe if someone have an idea. But even a non optimized representation is at least as fast as considering each tile as a node, so it's totally worth it.

11
DF Suggestions / Re: Improving Pathfinding. (Computer sciency)
« on: March 22, 2011, 12:47:54 pm »
For someone who starts off by saying that he didn't read the thread, you're pretty quick to tell people not to post their thoughts on the subject because your ideas are the best.   ::)  What you've posted is basically a repeat of what others have said, except in a few cases that don't make much sense, like the funnel algorithm.

In case you didn't notice, I've been posting in this thread before, and was only talking about how the way in which this gets put into memory, because simply having fast pathfinding is NOT the only goal here - it also has to conserve memory and respond to dynamic changes extremely well.  What you quoted wasn't a new idea, it was the same idea we've been talking about where I was disucssing how it could best fit those constraints on dynamic map changes.

(And to anyone else, what good ideas are there on ways to make a map react better to something like flooding with water as tiles individually flood or empty of water?  For that matter, how do we handle things like digging or bridging in pathfinding cheaply?)

Anyway, just drawing cubes over the map is problematic as long as it is entirely possible for players to not have any vertical access between most areas of the map (such as the central stairwell method of fortress design).  In order for these nodes to work, you need to have any "local" pathfinding capable of finding the other tiles in the same node without leaving the node.  If you then have something like two or three minor hallways with rooms branched off of them, with no access through rooms to other hallways, you would need to make the one-tile tall functional square nodes smaller and skinnier, still, since you wouldn't be able to path from one hallway to another without first finding the major access hallways in other nodes.

I don't see any benefit to using funnel algorithm, which might make sense in a game with floating point location values, but seems like wasted cycles spent on "path smoothing" in a game that has no need for path smoothing.  DF just needs to move diagonally when it can and horizontally when it can't.  There are no other considerations that need to be taken into account.

The game already prefers diagonals, since they are functionally free (or rather, cost no more than a horizontal move), which means that point on preferring diagonals is pointless.

The changing of the node structure based upon locking doors or digging is exactly what I was talking about finding the best ways to accomidate in that last post.  (You did read it, right?)

You also have to be aware of how the node changes aren't something as simple as "it's water now" - each individual tile will have to become flooded, and the game will likely be checking for which portions of the map are being flooded without a good system for how this will actually be updated.

Ok I read the whole thread , and like I thought it was mainly the same idea as the current pathfinding with some tweaks.
For what I can read of your post you didn't get almost every part of my method.

No there is no problem with fortress without vertical access.
No there is no need of any internal pathfinding , a cube is convex , which mean that for any two points of the cube the straight line conecting this two point is also include in the cube. Just in case a cube can be a 1x1x1 tile, which means this method is in the WORST case localy as fast(slow?) as the current method.
I think you just don't understand the funnel algorithm, it's an algorithm which take a bunch of touching convex polygons (with our start point in the first one and the end point in the last one), and returns you a bunch of straight lines conecting the 2 points, these straight lines ARE the path.
The function that take care of the changing of the map only do local changes not global, so it is very cheap in calculation.
I think the fluid system is as simple as "it's water now" (with an index of 1 to 7), I think the fluid system just need to know what is the "fluid index" of every tiles to work, but I may be wrong on this one.
Ho and the navigation mesh is known to be the (actual) best pathfinding method.

Edit: http://www.ai-blog.net/archives/000152.html here is a nice site explaining and showing some nice example of nav mesh.

12
DF Suggestions / Re: Improving Pathfinding. (Computer sciency)
« on: March 22, 2011, 08:08:43 am »
Do it like this:

Find all walkable tiles, cluster into nodes (we'll treat workshops differently in a moment).
Then find all swim-able tiles, cluster into additional nodes with the "swim only" modifier (tiles that are in both, which I think is 3/7, are their own node).
(Do the same for magma).
Then find all remaining empty tiles, cluster into nodes, with the note "fly only."
Connect all neighboring nodes, the node connections will also carry the walk/fly/swim flags.
Done.

Here's something I've been thinking about, however - if you are drawing a map where you only make local updates, not global ones, odds are, you're going to start with a wide open field and some caverns and a functionally wide open HFS.  You can basically start by just drawing a big grid over the land surface, and cutting up "rooms" every 12x12 set of tiles or something.  Basically, everything starts out connected (excepting rivers or cliffs), so it should start out as a big grid with some unconnected grids down in the caverns.  Obviously, you have to make separate rooms when you cannot path from one corner of these starting "rooms" to another, and may have to split things up if there are two different z-levels stacked over one another on the surface somehow or in caverns, but basically, it should look like a grid layed out over a varied set of slopes with some inaccessable tiles here and there because of trees or cavern walls.

Then, the instant you start digging into the earth, you basically start modifying or creating new rooms.  If we go with doors creating their own nodes, and segregating rooms, we might have a situation where there is an entrance way, then the door nodes, then the hallway behind it, with all the little rooms or warehouses sprayed off of it.

If you just go by trying to make up 12x12x12 cubes, and looking for what paths are blocked (while having to make doors and drawbridges and floodgates and the like their own nodes, since they can be locked), then you'd wind up naturally adding bits and pieces into the simple starting map gradually.  (Maybe, you'd need to have some sort of sanity check mop-up, maybe at the new year's, with all those other checks and calculations that make the whole thing take a long time processing, anyway, that another second checking to optimize the connection map wouldn't really be noticed.) 

The map would probably wind up looking similar to Granite26's idea, with most of the inside-the-fort stuff being determined by doors and based upon z-levels, but it would have the capacity to react to having water or multi-z-level rooms (like if we eventually get proper flying unit pathing).

We just need to have a stored connectivity map that works in those area-nodes levels at that point, with an assumption we can A* to anything "local" within those nodes.  Simply having a current location in the same node as a destination inherently implies not only connectivity, but a very short and probably direct pathfinding call.  Then we can throw away the current version of the connectivity map, which makes the hierarchical nodal pathfinding structure capable of competing head-to-head with the current A* connectivity map in terms of memory - only the fact that you will need duplicate layers of connectivity maps for things like "flying only" or "water-based movement possible" or "swim only" really drags it down.
see my post here http://www.bay12forums.com/smf/index.php?topic=76278.msg2091518#msg2091518.

I would like that everyone stop posting their idea on how to do pathfinding cause THIS is the best method (see navigation mesh).
Instead try to point out:
-what we may have forget to take in consideration (like workshops or the need to represent all the tiles, even the unwalkable)
-how to easily implement one part of this method, or improving the current idea of implementation.(like using 3d shape instead of 2d, using a flag system for easily representing the different types of nodes)
This is only like this we'll have a serious suggestion that Toady may try to read.
I don't have a good english , so I would want that someone who understand the method post a summary each time someone post a potential improvement.

Here is the first summary:
-We represent the map with rectangular cuboid of tile of the same type (walkable/swimable/digable/flyable/magma/workshops)
-the map can now be represented as a graph where a node is a cuboid , and 2 nodes are connected if the cuboids they represent are touching.
-we use A* on this graph, this will give us a "basic" path, we'll know through what cuboid the path come, not what tiles.
-We have to use the funnel algorithm to knowing the exact path (http://digestingduck.blogspot.com/2010/03/simple-stupid-funnel-algorithm.html).
-At this point we have a set of points leading to destination , the dwarf only need to go in straight line between each points (There is no internal pathfinding, rectangular cuboid are CONVEX, the shortest path between 2 points is without any calculation the straight line)
-A straight line is defined as going diagonal (starting from starting point) until reaching one of the two coordonates of the destination then going horizontal or vertical.
-Each time a change is done on the map (digging, closing a door, building a wall etc...), we have to (slightly) change our graph.
-A function than can do this only need to be able to:
    -add a node
    -merge 2 nodes (if 2 cuboids have a common side)
    -split a node (when we build a wall for example)
    -changing the type of a node(digable->walkable)

With this method the entire map could be represented whith only few hundreds nodes instead of millions with the current method. And the more important thing, if we only look at the fortress (not the entire map), I think almost all pathfinding occur here, a friendly designed fortress could be represented with a dozen of nodes, and with only a depth of 4 nodes: the surface (surroundings by fortification) , the stairs , the main hall , all the other rooms linked to the main hall.
And finding a path in this type of graph is very fast.

13
DF Suggestions / Re: Improving Pathfinding. (Computer sciency)
« on: March 21, 2011, 12:13:29 pm »
Do it like this:

Find all walkable tiles, cluster into nodes (we'll treat workshops differently in a moment).
Then find all swim-able tiles, cluster into additional nodes with the "swim only" modifier (tiles that are in both, which I think is 3/7, are their own node).
(Do the same for magma).
Then find all remaining empty tiles, cluster into nodes, with the note "fly only."
Connect all neighboring nodes, the node connections will also carry the walk/fly/swim flags.
Done.

Now your volumes of sky are their own node, but dwarves can't path through it ("fly only").

Workshops we treat like this:

3x3* node centered on the workshop which splits the larger "room" node, which is then split thus:
1x1 node in the center as the destination (and walkable) (this aids pathfinding, as only the center tile is the workshop as far as item and locations).
Outside tiles are then removed if they are non-walkable, remaining are grouped as appropriate.

*For non-3x3 buildings, which exist, the node would be the building's size.  The job-location node is split out as normal, followed by the subtraction of non-walkable spaces.
You could maybe apply the flag system to workshops too,  that will prevent dwarves to pass through them, except those who have a job to do in it.
Then every tiles could be represented by a graph representing walkable/non-walkable/swimable/flyable/other(all types of workshops) cuboid.

14
DF Suggestions / Re: Improving Pathfinding. (Computer sciency)
« on: March 20, 2011, 04:15:30 am »
But if your rectangular prisms are just made of open space, you don't even need A* for internal navigation, you can just walk in a straight line.

And rebuilding a node is rather easy.  I mean, if you stick a block in the middle of a big flat rectangle, you can just split it into two wide rectangles, and two narrow rectangles that fill the space that the original one did.  No need for global rebuilding or anything like that.  And removing the object would just work the other way around, generate a new tile, and see if you can merge it with a nearby rectangle (one edge is the same size as the adjoining rectangle), and repeat until you're done.

I wrote up a post on something like this (although without the funnel stuff, just A* from node to node) at http://www.bay12forums.com/smf/index.php?topic=42678
yep, that's the idea with a convex shape, we know the shortest path between every 2 points of the shape is the straight line, so there is no internal pathfinding to do.
And you are right the node building function could work with just the ability to add a node , merge 2 nodes , and split a node, and that's it. So pretty easy and not much calcultation to do.

15
DF Suggestions / Re: Improving Pathfinding. (Computer sciency)
« on: March 19, 2011, 06:37:25 pm »
-First we "cut" the map in convex polygons (rectangle in our case)
-We represent this polygons with a graph , each polygon is a node, 2 nodes are connected if the polygons they represent are touching. ( so a node will often represent more than 100 tiles)
-We use A* on this graph, this will give us the list of polygons our path go through.
-Then we use the funnel algorithme (here is a link http://digestingduck.blogspot.com/2010/03/simple-stupid-funnel-algorithm.html )

One minor tweak: instead of convex polygons, convex polyhedrons (rectangular prisms). Under normal circumstances, there'd be no difference since most forts are mostly 2d floors with very few 3d rooms, but if it considers vertical space first, it should end up with nodes for uninterrupted stair columns (as well as air space, which may be useful later for flight). May want to limit polyhedron size so that any single node doesn't cover half the z level or every bit of open space above the tallest peak, however; Perhaps to map block size, which is some 16 tiles, so 16x16x16 at worst. That would also limit rebuilding the nodes.

Yes, you are right, using polyhedrons would greatly improve pathfinding if it comes through a hundred stairs. Though for the size limitation I don't realy see the utility, I think there will still be the same amount of nodes rebuilding even with a size limit , or maybe I am missing something?

Pages: [1] 2