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 - pugi

Pages: [1] 2
1
DF Modding / Re: HTML +JS path-finding simulator
« on: April 08, 2011, 05:55:42 pm »
Good thing too. If you have 2000 stones, its trivial to find a close one but not so trivial to check all 2000 for the shortest path. We talked about cool ways to address this a year ago or so in a different thread but a discussion of graphs is a little off topic in a thread about pathfinding. I'll just let you guys have fun and not troll this too much hehe.

I know why DF just checks the distance and not calculates the actual path and I've read that thread around the time when it was posted ;)
I just want to help Niseg to get his simulator working nicely.

2
DF Modding / Re: HTML +JS path-finding simulator
« on: April 08, 2011, 04:29:21 pm »
Nice improvements you made there :)
I also noticed that the max(dx,dy) heuristic tries to get dx=dy... I had not thought about that, it looks a bit weird. But then i noticed that in some cases the max heuristic didn't get the optimal path, the vector path was one step shorter. That should not happen, as the heuristic never overestimates the cost and then i found the mistake.
The A* search algorithm you based your program on has a mistake in it: when you expand a node and find a neighbor that is already open list, it just skips that node. The algorithm forgets to check if the new path to the node is shorter than the one already on the open list. I guess that this was made to keep the open list small, as that doesn't happen very often, but it could lead to not being able to find the optimal path.
You can see an example of that happening in this maze.
The sqrt heuristic checks the left side of the wall first, as the neighbors there have a lower vector distance to the destination, while the max heuristic checks the right side of the wall first to try to keep dx = dy. After a few more expansions the max heuristic should also notice that going on the left side of the wall is shorter, but apparently the node below the small wall was first expanded from the node on the right, so the shorter path didn't get updated.

And trying to find an effective heuristic may be a bit complicated, i know :D

3
DF Modding / Re: HTML +JS path-finding simulator
« on: April 08, 2011, 11:44:15 am »
Sigh... i tried to make it clear to you, Niseg:
You can not use the Manhattan distance heuristic when you can move diagonally!

A heuristic calculates the approximate distance from the current point to the destination. You can not chose a heuristic, that overestimates the remaining distance; that means the result of the heuristic has to be less or equal to the real number of remaining steps. If you choose a heuristic that overestimates the cost, you can't be sure if you get an optimal solution / the shortest path.
For the Manhattan heuristic the distance for a diagonal move is 2: 1 to the side and 1 up/down, while the distance for a horizontal/vertical move is 1. It doesn't know that you can also move diagonally. So if the destination would be 10 tiles south-west of the start, the heuristic would calculate the cost 20 (10 steps south, 10 steps west), while the real distance would be 10 (10 steps south-west).

I can show you an example where you can see the problem:
http://niseg.0adz.com/test_maze.html?maze=v02AUAUAQETEwAAAAAAAAAAAAAAAAAAAAAAAAP_wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
Here the Manhattan distance chooses to go diagonally towards the wall, then straight east to the end and then straight south to the destination. The heuristic doesn't know, that it can also move diagonally so it chooses the shortest way for only vertical/horizontal movement.
When you choose the vector heuristic, it correctly calculates the shortest path, by moving diagonally and left of the wall.

And i know that the sqrt(dx2 + dy2) is harder to calculate, just use the other heuristic i recommended: max(dx, dy)

4
DF Modding / Re: HTML +JS path-finding simulator
« on: April 08, 2011, 09:51:34 am »
Wouldn't that fail to take into account that diagonals cost sqrt(2) instead of 1 (which is definitely true in Dwarf Fortress)?

Yes, that wouldn't take that into account. But the simulation is already built in the way that a move to each of the 8 possible sides costs 1. And using the other formula wouldn't change anything, because floor(sqrt(2)) = 1.
If you want to take that into account you would have to increase the default movement cost to 100 or something, so a diagonal move has the cost 141.


Isn't the A* Algorithm always optimal? When you look at this and compare vector and manhattan, there must be something wrong???

Yes, the A* Algorithm is always optimal, i said so in the first reply. I don't know what heuristic is used when selecting "vector" and the heuristic "Manhattan" (normally defined as cost = dx + dy) would overestimate the remaining distance to the goal, which is not allowed in most if not all pathfinding algorithms. You can only use the Manhattan distance as a heuristic when the allowed moves are up/down/left/right.

5
DF Modding / Re: HTML +JS path-finding simulator
« on: April 08, 2011, 04:40:54 am »
The A* code looked fine, but i found something you can change:
Code: [Select]
new_node.g = current_node.g + Math.floor(Math.sqrt(Math.pow(new_node.x-current_node.x, 2)+Math.pow(new_node.y-current_node.y, 2)));Because you always only take one step in any direction and the cost for each step is currently always 1 you should change it to:
Code: [Select]
new_node.g = current_node.g + 1;And when you include traffic zones you can just change it to current_node.g + new_node.traffic or whatever.


But the problem was indeed your heuristic. The function dx2+dy2 always overestimates the distance to the destination, which is not allowed. It even says so in the comments. So sqrt(dx2+dy2) should also work and give the shortest way, also it should always try to move towards the destination diagonally and make zigzag-movement, but as both diagonal and straight movement have the same cost, it doesn't matter for the overall length of the path.
The Manhattan heuristic should also NOT work, because it also overestimates the cost, because it doesn't include diagonal movement, which would be two straight moves for Manhattan.
Another heuristic you could use would be min(dx, dy): because you can move diagonally with the same cost as straight movement, only the longest distance of x and y defines the overall distance.
The code for that would be
Code: [Select]
Math.min(Math.abs(current_node.x - destination.x), Math.abs(current_node.y - destination.y))

Edit:
I forgot to add this, i found a nice java applet for the comparison of different search algorithms. It is in German, but you should be able to use it without problems, i couldn't find any other with the amount of features it has. http://www.stefan-baur.de/cs.web.mashup.pathfinding.html
Sadly you can only draw obstacles with a 3x3 brush, but it doesn't really change anything. Something nice about it is that it also shows all the nodes visited and not just the final path.

6
DF Modding / Re: HTML +JS path-finding simulator
« on: April 07, 2011, 02:21:29 pm »
Sorry if my last post was a bit unclear, i mean that the simulator is not using the A* search algorithm, when you click on it. I mean, paths like this can't even be explained with the zigzag distance = straight distance.
Spoiler (click to show/hide)

And as far as i know, DF uses the A* algorithm or some variant of it for pathfinding, it just doesn't check for obstructions when calculating the distance for job items like choosing a stone for a construct rock throne task. It would for example choose the rock in the z-level directly below the center of the workshop (distance 1), even when the dwarf would have to travel 20 tiles to the side to even get to the stairs.

7
DF Modding / Re: HTML +JS path-finding simulator
« on: April 07, 2011, 11:44:43 am »
From what i can see is that you are not using the A* algorithm (which is optimal, it always finds the shortest route), you a simple greedy algorithm that chooses the next node with the shortest distance to the target. The A* algorithm also adds the distance from the starting node (the distance traveled) to the cost of the next move.

8
You mean this, Slye_fox?
You can copy the 1-7 from there and insert in the current tileset.

Hey, png of ore veins please? :D

Sorry man, been a bit busy, being ill and miserable! :P

Here is the most recent test sheet I have:


This is by far the very very best looking tileset in dwarves and goblins. The Trade Depot is ugly though, I almost don't want to build it :b

You mean the wheels in the corners? Bearing in mind that the tile is also used for several other things besides the trade post, what do you think it should be?

9
Tilesets and Graphics / Re: Ironhand's Graphics Set (0.48 released!)
« on: August 15, 2010, 11:19:33 am »
Absolutely beautiful!
A shame, that trees don't have the correct size in DF to begin with.
Hm... Maybe we could do the same "semi-multitile" thing for trees, too?
So that the "tree tile" from Vanilla DF just represents the trunk and we display a 2x3 or something tree at that place?

Shame that it wont be possible to make trees this way...
Spoiler (click to show/hide)

This is possible. You can make something like 24x24 pixel sized trees, expand the tile to 36x36 pixels with the tree remaining in the upper left corner and then add the shadow in the lower right corner. Then you move the tile so the trunk is in the middle of the tile (-3 pixels in x- and y-direction) and the shadow is on the lower right of the tree. You can even vary the x- and y-movement by a random amount like +-4 pixels so multiple trees look nicely next to each other. And you have to make sure that the tiles are rendered from top left to bottom right, so other trees are placed above the shadow of the ones on the left/above.

I could make a little sketch of what i mean if it is too complicated, but i am lacking the motivation :P

10
I guess you made a mistake dwarven trick.

11
Don't trust the wiki page for the tile usage that much, the O is also used for single pieces of constructed/smoothed walls and the ends of those. I guess there are a few more things missing.

Best would be if someone would build every workshop/building/construction and write down what tile is really used for which building and then update the wiki.

Sounds great! *pats you on the back and hands you the proper tools to do it*  :P

I would, but i am currently at work ;)

12
Don't trust the wiki page for the tile usage that much, the O is also used for single pieces of constructed/smoothed walls and the ends of those. I guess there are a few more things missing.

Best would be if someone would build every workshop/building/construction and write down what tile is really used for which building and then update the wiki.

13
I think the ground tiles should be brightened up a bit, looks fine otherwise :)

14
DF Modding / Re: Armor system and bugs
« on: August 08, 2010, 03:35:39 am »
You can edit the size/permit stuff in your raws (item_armor.txt, item_gloves.txt, item_helms.txt etc. in \raw\objects\) and try to find nice values yourself :P

15
I still don't like the constantly howling wolves :(

Pages: [1] 2