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

Pages: 1 [2] 3 4 ... 10
16
DF Gameplay Questions / Re: Building my fortress in a labyrinth
« on: May 30, 2011, 03:18:27 am »
In my opinion a labyrinth would be counter productive   It would take you more and more cpu resources  to find a path. In order for it to work you'll have to trap someone in it somehow (probably a presure plate) and tell your dwarves to avoid it using traffic zones.


If there are optional routes, dwarves will reroute if they encounter other dwarves, even if the new path is longer. Even if it's like 10x times longer. They don't crawl if they don't need too, which is sometimes stupid.

This explains a few things in terms of path finding and FPS behavior. 

For a while I tried to figure it out if pathfinding is the real FPS killer. Devek has made a valid claim that pathfinding  can't be it,  because it doesn't happen that often. Still if things are as you claim it explains the fps gradually dropping rather than fluctuating .

If the dwarves are in an enclosed space they would each find a path for themselves and the chances they''ll collide with someone grows . At many intervals  a group of dwarves  may find they can't step into a path because another creature is there. If they recalculate the path they may get a failure due to the blocking creature. a path failiure means A* will go through all the accessible nodes. This may cause heavy backtracking inwards .

This is a major trouble if a few dwarves are trapped between  two groups . They may oscillate back and forth. This can also be worsened if a dwarf is searching for an accessible item. if it gives up as soon as the item is inaccessible it looks for another one. If he's trapped he may try to find a path to each and every valid item in the port (I'm sure there is some sanity check). if he's not traped he can be fooled by the heuristic to try and reach items bellow or above him that may look closer but are really far away. What you get is an 8 way intersection where everyone has a green light and right of way.


17
DF Dwarf Mode Discussion / Re: +400,000 FPS
« on: May 29, 2011, 10:37:57 am »
AMD used to have a timer problem I thought they fixed it by now. I did a search and it's related to RDTSC oppcode. I don't think it should matter. The symptoms  for this is games running too fast.

18
DF Suggestions / Re: Improving Pathfinding. (Computer sciency)
« on: May 26, 2011, 08:36:34 am »
I'm thinking of improving my room model by removing the bitvector description of from the room object and leaving the edges. I'll use the output of my BFS collider as a lookup table of O(1) to find if a node is in a room . Then adding an update scheme would be much easier but the data structure might take a lot of memory but I can add some kind of scheme to reduce it to 1 byte per node or less .

The update scheme would look at a collection of nodes that changed from either wall->floor or floor->wall. A floor->wall is the easier case because at worst it would block or or more access point and removing edges is the easy. a wall->floor change would require looking at all its neighbors and decide which room it should be added to and then update that room and its neighbors .

Other than that I'm thinking about defining the access point using some kind of line or vector . I think the rooms I created can be easily converted to nav meshes and then path finding between them would be very trivial. due to a polygon shape you can just draw line between then without any collisions .  I can also implement a vector method with an A* to walk around obstetrical . This should usually reduce the complexity to almost nothing because it would shorten the space A* would have to look at to nothing.

Even though my rooms don't look nice and rounded it is not really critical for the scheme to work.  I might have mentioned this before but my scheme only look at around 3-4% of the nodes as opposed to A* who looks at over 40%. A* also take more iterations to find the target - about 20 times more (come from insert in order optimization only it used to be more computationally intensive) .  My scheme also support spreading the pathfinding algorithm to many time slices instead of one huge step. no path penalty is extremely low while A* penalty is extremely high .

More things can be added to this scheme like finding the closest item according to the room it's in . This way dwarves won't use a blind heuristic to pick their stones. This can also be fixed with a line of site penalty heuristic like i did in my calculator it draws a line, validate it and add 2 for every  wall it hits (the minimum distance to go around it).it can be made smarter than that.

19
DF Suggestions / Re: Improving Pathfinding. (Computer sciency)
« on: May 19, 2011, 04:45:15 pm »
that ant farm reminds me of path caching which has a big penelty when a path to the destination doesn't exist. you also need a path smoother but that is not to bad in terms of complexity.

my room spliting is a beter choise but i need to figure out an update scheme. you can practicaly regenerate all of them every 1000 frames and be fine. that is not optimal though.

it reduces complexity,  split the path and has a low penalty.  the room system can also help finding the closest item.

it has. room for improvment but. it works. well as is.

posted from a PDA sorry for the bad English ...

20
DF Modding / Re: HTML +JS path-finding simulator
« on: May 15, 2011, 10:05:26 am »
Thanx! That explains a few things. ::)  I found the problem debugging a partial reconstruction of your maze- my insert - in order doesn't work   :-[ . The insert in order somehow corrupt the whole queue I'll probably remove/fix  it  today and upload my "redraw" optimization which would make drawing the maze and traffic zones a lot less computationally intensive (helps a lot with 128X128) .

The "insert in order" was my later optimization . I reduced the complexity from 198~  million iterations to about 1 million with my first optimization (on a big 128X128 maze). The insert in order only reduced it to 100000 so it's not as critical for performance. I just didn't want it to run for 13 seconds

EDIT : problem fixed. I disabled insert in order and then fixed it  ;D

21
Maybe you should suggest adding "line drawing"  in designation menu in addition to  filled rectangles . I've added line drawing to my simulator before adding filled and empty rectangles. I admit coding line drawing isn't as intuitive as rectangle but there is plenty of code on the web for that ;).

Here is a simple ambush setup done with traffic zone(image).
Spoiler (click to show/hide)

It works on the simulator I'm not sure about the game. You may want to make sure the dwarves don't look at the goblins and if they do they might take the path around rather than the direct path below . you may be able to improve on it to work with two squads but I admit it's hard to create a battle plan by drawing traffic zones over and over.

22
This is a picture from a similar thread about Moving Civilians During Sieges . I showed how I used traffic zone before enabling the alert which made civilians take the path I wanted  them to take (this works in game):
Spoiler (click to show/hide)

This forced the civilians to avoid the threat('w's) when going from their  position  (S) to fort entrance  (D). This works in game just fine just have to remember to do it before enabling the alert.

I think you might be able to utilize traffic zones to force your military dwarves  to take a path you want them to take. The only problem you'll have is if dwarves ignore traffic  (I doubt it).  The problem with DF is that once a dwarf found a path it will use it until it's interrupted. I think that with military you can use cancel order then press and give them a new station which would cause them to find  a path.

The problem is that it's well known that Military dwarves are extremely brave while civilian dwarves are  the exact opposite . The only effective way you can make them retreat is to deactivate them (from the military). Before you do that (deactivate ) you can redraw traffic zone to encourage them to take a certain path home. This way you might be able to lead your enemies into your "minefield".

23
DF Suggestions / Re: Parallel Processing
« on: May 12, 2011, 04:30:56 am »
Anyway, making DF multithreading at the end... won't work (very well) multithreading has to be in the core design
After writing code in a multi-threading  environment for a long time I can generally say  your statement is  not true. What's true is that you should know what you are doing and what you are trying to achieve . Without going into details you can generally convert any for loop that process independent data  into a work queue scheduler . 

To gain entry, you must start a new forum thread suggesting mutli-threading, improved pathfinding, multiplayer, and/or open source code.

I suggest that people that open a suggestion without giving a clear methodology should donate 10$ to Toady to  figure it out.

The pathfinding suggestions are all in one thread .There is a lot  progress in the in the clear methodology area  . I implemented a demo of 2 of the suggestions . I know  room pathing is half done  but it simplify the problem by a factor of 10 and no path penalty runs at best case time instead of worst case every time.

Toady made DF run a whole lot faster by using coding magic. Also making the game multi-threaded doesn't fix the game's problem, it just hides the symptoms for the time being.

 I haven't noticed much of a performance difference (maybe because my 25% overclock stopped being stable - I blame my cats) . We are totally in the dark in the benchmarking field because it's hard to points out the performance killer because there are more than one. I think it got to do with how data is organized .

24
DF Gameplay Questions / Re: Moving Civilians During Sieges
« on: May 11, 2011, 06:14:11 am »
I have a small tip related to activating the alert - I'm a sore loser so I usually attempt to "win" by killing df reloading  on siege/ambush.

In my last ambush my dwarves were busy outside chopping trees and bringing them home  . My fort has 2 main access points a Northern one and a Southern one. The dwarves were chopping trees at the north east while goblin came from north/northwest.

When turning on the alert the dwarves naturally ran toward the closest fortress entry - the northern one.... and then goblins came and chased them away. This caused the dwarves to run away instead of running home through the south gate.

I've found a simple solution to this - before starting the alert (when you do they find their new path) you have to paint traffic zones so the dwarves go where you want them to go . This works great here is how it looks like (picture folded):
Spoiler (click to show/hide)

if S is where dwarves start D is their destination and little w's are the goblins ( the only marker I got  in my program) . Drawing the traffic zones caused the dwarves to avoid the northern (closest ) entrance and take the southern one. It works in my simulator if you want to test it but I don't save traffic zones so you have to draw them yourself. If you use regular A* it would go through the north entrance with A* traffic it will go through the south.

It's critical you draw traffic zone before you enable the alert. The alert tell the dwarf "stop whatever you are doing and find a path to this burrow " . Once a dwarf finds a path they will use it until they hit a wall, see danger etc.

25
DF Suggestions / Re: Using GPU power instead of CPU power?
« on: May 11, 2011, 05:37:53 am »
When trying to solve a complex computer science problem faster you generally have 2 approaches:
1. getting a more powerful computing engine and adapting your code to work with it.
2. simplifying the problem

The approach you took is approach 1. Many people think this approach is the best course of action but in my opinion it's not. There is a limit to how fast you can make the program run using multi-core and multi-threading and in the age of mobile computing pushing the CPU to the edge is not the answer.

The best approach is to simplify the problem  and the most common approach is divide and conquer .  If you replace the problem with a many  smaller problem you'll generally find a more efficient solution.

I had this problem with my path finding simulator. The original A* I used did 3 linear searches  (O(N)), 1 to find best node, and two to check if the node is in the open or closed set . I replaced the "push" (O(1)) to "insert in order" (O(log N) ) which converted the "search for minimum" from O(N) to O(1). This made it run about 1000 times faster. with 128X128 map max(N)=16384.those 3 linear searchs take about 3*(N(N+1)/2) that means max complexity is 268.5 million iterations. This is reduced to 16384 insert in order which is much less than NlogN = 0.229 million iterations.

Now here is the problem. If you have all those optimizations in and I'm guessing Toady got them all. The problem is still too complicated when you have an max(N) = ~1 million. You go through max(N) every time 19*1million is still a lot . For this reason I generated an overlaying graph of "rooms"  which takes about max(N) iterations . It generates room , how they are connected and the access point (I pick the first - not optimal).  This reduces the  "path doesn't exist " penalty from  the number of nodes to the number of rooms. Instead of looking at the "big world"  the pathfinding  creature only looks at the road they picked . Most of the paths also become  trivial where A* performs best case almost every time.  This is also less memory intensive should have very good cache performance. Unfortunately it needs more work  ::) because I didn't even start room updates yet .

I admit pathfinding isn't the only thing that's slowing DF down but I can work on 1 suggestion at a time ;). I think that performance issues are a pressing concern but  I'm hoping that showing a working alternative would make Toady's life easier when he finds the time to work on them.

26
DF Dwarf Mode Discussion / Re: Regarding armour and weapons
« on: May 07, 2011, 11:10:59 am »
Turn off mining/hunting/wood cutting for all of them.

27
DF Dwarf Mode Discussion / Re: copper...
« on: May 05, 2011, 04:38:10 am »
It is possible that an enemy gets a chokehold on such soldier and he is dead then. I had it.

That's one of my favorite adventure mode tactic - learned it from a play along. Choke the guy and administer fun. Big fights = hammer to the head smaller ones - axe all the limbs just in case. I once thought I could train my weapon skill by hitting unconscious enemies but it didn't seem to work . I think a better tactic would be to cut off their arms or legs .

A tend to agree you shouldn't rely on 1 guy even if he can chop off armies . There is always a chance someone hit him in the head with a silver hammer...  Still dwarf power is pretty expendable  :D  I got about 100 idlers and they don't die as often as they my last forts.

28
DF Suggestions / Re: Improving Pathfinding. (Computer sciency)
« on: May 05, 2011, 04:26:39 am »
Once an HFS finds a target, I don't believe they continue the BFS every frame, but I do believe they will seek a target until they find one-- and I don't necessarily see anything wrong with that.  It could be and should be improved with a proper set of connectivity maps that take fliers into account, of course, but the aggressiveness isn't the problem.

HFS can be walled off once breached, which causes severe slowdowns.  Furthermore, there are MASSIVE numbers of HFS, and they respawn (albeit slowly).  This causes a LOT of said BFS.

you are talking about the O((k/2)^N)~ complexity of A* and the no-path penalty = worst case. HFS has a big N and the clowns have big k (the got lots of flags).

Regardless though, the key here is to make a pathfinding system that is efficient for ANY movement type-- walking, flying, swimming, magma... heck, add in digging, climbing, maybe even jumping... and while we're at it, might as well add in multitile movement as well.  It must be robust to handle these kinds of things.
That stuff is trivial  I can easily do it  with my room system (have to turn simulator to 3d add obsticles of diffrent types). All I'll do is add in all the collisions of interest to the list and go through them to calsify movement type on an edge.


Anyways I went alittle crazy with my simulator and made a 128X128 version  ;D . you'll see most of the stuff I did in this thread.
http://www.bay12forums.com/smf/index.php?topic=83804.0

My algorithm runs 1000 times faster than A* and needs about 100ms~ preparation type (no cache version). A* runs on a graph that size using 190~ million iterations (13~ seconds) . I manage to keep it small at about 47000 (14~ms) which is about 2000 iterations per subpath.

EDIT: I made A* run much faster using two bit vectors - one for open and one for closed set.
EDIT2:  insert in order is in now.  A* is orders of magnitudes faster than the original  by replacing linear search with the bit vectors and making all the pushes inserts in order which is log N time (best node always in front). With a regular A* Which is a node explosion it reduced runtime by a lot because it's (k/2)^N is much larger.

29
DF Dwarf Mode Discussion / Re: 16x16 Maps
« on: May 05, 2011, 04:13:11 am »
so, then you'll get your 108x108 embarks with no lag :)
No, the game won't allow more than 16x16.
Oh, and quantum computers would need to be perfected first. And released to common-Joe bozos like us who play DF and don't have military contacts.

You don't need a supercomputer to run a 16X16 embark . What you need is some code optimization and the sky is the limit (provided you got the memory). And I can prove it with a suboptimal algorithm .

I checked how long ( JS is slow had to use profiler or it crashed) the A* run on my 128X128 simulator... about 13 seconds . My algorithm used A* for 8 ms  and another 6 ms for itself. .  That's about  1000 times faster .The path cacher (advanced) does it in about 6ms total (2000 times faster).

The generation of the rooms from scratch takes about 90ms (automatically define rooms and access points), and 265~ ms for path cache generation between rooms . Redraw does take about half a second. The load time is about 1.5 seconds. Whatever you do don't add waypoints those use A* between them ;) (13-14 second of runtime).

You'll notice the penalties are not even that big if you regenerate the connection graph from scratch periodically (every 500 frames). The dwarves can then reevaluate their paths from scratch  (1 room path and 1 local path)and it would take them next to no time to do. My model is also scalable . The rooms can be grouped into sub-regions, sub-regions into regions, regions into continents  , continents into planets  ;).

EDIT: You can't reproduce the results anymore due to an A*  optimization I did ( O(1) lookup if a node exists in one of lists) which made it run about 1000 times faster .

30
DF Dwarf Mode Discussion / Re: 16x16 Maps
« on: May 04, 2011, 01:53:21 pm »
What we'd really need is Toady's input - his No Code Sharing At All policy is hurting performance, it seems. But ah well, that's up to him.
I don't really care about Toady's code, I'll leave him to do the dirty work ;) . According to what I saw in DFhack headers he's doing a pretty good job . I only hope He'll take my suggestions into considerations.

You can't really  suggest path finding optimizations without knowing a thing or two about the subject or a thing or two about computer programming, algorithms and mathematics. The computer simply can't really see the map... unless you teach how.  I happen to like to learn and investigate stuff . I knew nothing about pathfinding before I started playing DF but with the amount of resources on the internet (along with knowing what to look for) it wasn't hard to learn. Then I started small - first some basic UI then at version 15 or so I added A* from there waypoint based path caching , path smoothing and so on. It's all about turning suggestions into code.When one person does it another can duplicate their efforts.

The algorithms I used are really basic it's all a matter of making them work for you. I concentrated on keeping the general concept the same - you call a function - it gives you a path...

anyways I went a little crazy and enlarged the maze a little to 128X128 which is 16 times more node which is comparable to going from 4X4 to 16X16 .Clicking A* freezes for a while and yields " visited nodes:7081, length= 199 iterations= 196,924,942" ( I added commas for readability) . My algorithm the same simple maze(4 squares with U access points) yielded   "visited nodes:372, length= 246 , subpathes =31 iterations= 47,664 " . I bet the room with path cache is super fast because it only needs to find 2 short paths and  a path on the 8X8 map.

here is the link to it  I'll spoiler it so you don't accidently click on it because JS is slow and this kind of stuff will kill it . I recommend chrome if you want to open it. ;)

Pages: 1 [2] 3 4 ... 10