Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 6 7 [8] 9 10 ... 24

Author Topic: DFHack plugin embark-assistant  (Read 94131 times)

Telear

  • Escaped Lunatic
    • View Profile
Re: DFHack plugin embark-assistant
« Reply #105 on: August 24, 2019, 05:45:23 am »

Yup. Very much pseudo code. I'm currently mucking with something that just waits for far too long then grabs a screen shot. Leave it running overnight, then skim through the screen grabs in the morning for any hits. Slightly less elegant, but it should work.
Logged

RedDwarfStepper

  • Bay Watcher
    • View Profile
Re: DFHack plugin embark-assistant
« Reply #106 on: September 14, 2019, 05:52:45 pm »

First of all: I really love this plugin!
Having very specific ideas about the ideal embark location (Volcano, aquifier or stream, sand, warm jungle biome, only friendly neighbors, ...) and being unwilling (for now) to use tools like "PerfectWorld" I rely heavily on batch generation of many worlds - my current run has 100 - and then finding the right one among them, which was quite time consuming in the past.
Now using the plugin and being able to save my search criteria it is much faster and also less involved, which allows me to be even more picky about the best spot.

But I'm wondering: How much of the results are getting cached during one "search session" (=> while searching repeatedly for matches in the same world without restarting the game or quitting the plugin)?
Having a 257x257 world and specifying my usual search criteria it takes between 8 and 10 minutes for the search to finish on my system. Repeating the same search takes almost as long.
So I did some science:
Running the above mentioned search the first time the shell outputs the following
Code: [Select]
matcher::find: Preliminarily matching World Tiles: 16307and searching takes 9 minutes, 25 seconds to finish.
Running it the again it outputs
Code: [Select]
matcher::find: Preliminarily matching World Tiles: 10421and takes 9 minutes and 3 seconds.
Adding an additional biome criterion we get
Code: [Select]
matcher::find: Preliminarily matching World Tiles: 1037and only very few world tiles get highlighted with the black "X" on yellow ground.
But the yellow "X" still iterates from the top of the world to the bottom, about a lot of unmarked tiles and it takes 8:35 to finish.
Running this refined search again took 8:35 to finish.
Would it be possible to only check/iterate the "preliminarily matching world tiles" in a refined search? That could speed up the whole process, couldn't it?

I had a look at the code on github, but my c++ is quite rusty, so the following is just me speculating:
If retaining all the tile info for matching in memory after the first complete search would be to costly memory-wise something like a skip list, a multimap or a database like index structure for the most significant region/world tile characteristics (biome types present, waterfalls, volcano ...) could be used for faster exclusion of tiles from the search space before starting the more detailed spatial checks.
This would make repeated/refined searches much faster.
What do you think?
I'm absolutely willing to help with test-cases and testing and design ideas, with some guidance I might even be able to produce some usable code...
Logged

PatrikLundell

  • Bay Watcher
    • View Profile
Re: DFHack plugin embark-assistant
« Reply #107 on: September 15, 2019, 02:59:45 am »

It's largely a matter of which situation you want to optimize for:
a) Minimize the time it takes to search a full set of potentially matching world tiles; or
b) Minimize the time it takes to search a sparse set of potentially matching world tiles.
Now, if the cost to a) of achieving b) is small, it may be worth aiming for b).

My original prototype (written in Lua, although I was fairly certain the script penalty would be too high to be practical) tried cashing everything, but the estimated memory requirement for that would be excessive: I don't remember the number, but something like 30 GB, which I also suspected would be the case. Therefore I changed to use the philosophy Toady uses, i.e. regenerate information rather than cashing all of it. The plugin stores all the world tile level information used plus some aggregate level info about mid level tiles, but not the mid level tile information itself. The mid level tile aggregate information is generated during the first search, and thus is available for the following searches.

The aggregate level information is of the type "no sand on any tile", which means a search for sand in an embark will skip this world tile when that field is true. Before the first pass this field is false, because we haven't scanned the mid level tiles yet. Similarly, if there's no river in a world tile, there's no waterfall either. In the same vein, this info contains the biomes of the current world tile as well as the surrounding 8 tiles, and if an embark requires a particular biome not on that list the world tile can be skipped (and this list is cut further if examination of the mid level tiles shows that some of those potential biomes are not present). In fact, the yellow X indicates that the tile has to be examined more closely exactly because the top level info collected does not rule out a match.

One complication is that DF uses a data structure with "feature shells", i.e. 16*16 world tile blocks, and loading those take a significant amount of time (about half of the total search time), which has caused me to ensure the world is processed one feature shell at a time. In addition to this, movement from tile to tile is done simulating single world tile movement key input, as I don't know of any other way to get DF to load the feature shells. It is possible to use the 10 tile movement key inputs instead to speed things up, as well as diagonal movement when the preliminary match set is sparse, but that adds (a possibly negligible) overhead to the case where you have to scan more or less every tile. Also of importance is that the movement pattern is complicated enough as it is (it took me a fair while to get it to work correctly). This doesn't rule out that it might be possible to use the current pattern for the first scan and one that tries to cut the number of number of steps down for subsequent searches when all the base data has been collected, though.

A further complication is that the next version of the plugin takes "incursions" into consideration, i.e. bits of neighboring mid level tiles' biomes jutting into embarks, which would allow you to find a single tile embark with 9 biomes on it (assuming one existed in the world, which is highly unlikely). That logic, however, requires info from neighboring world tiles in all directions to find matching embarks at the edges of world tiles, but all the required background info is still collected on the first search, so a different search logic for subsequent searches would still be possible.
Logged

DerMeister

  • Bay Watcher
    • View Profile
Re: DFHack plugin embark-assistant
« Reply #108 on: September 15, 2019, 04:53:48 am »

This plugin add ability to see buildings if I embark on site?
Logged

PatrikLundell

  • Bay Watcher
    • View Profile
Re: DFHack plugin embark-assistant
« Reply #109 on: September 15, 2019, 07:02:42 am »

This plugin add ability to see buildings if I embark on site?
Yes or no, depending on what you mean...

The smallest overlay allows you to see the presence of sites (caves, shrines, etc.) but not the buildings within those sites (display of caves can be enabled by advanced world gen, but the others are not displayed by DF). Thus, if you want to embark on a vault with the aim of digging down to it you can, but the search function does not provide any option to search for them: you're restricted to scour world tiles visually.
The easiest way to find a kind of site you're looking for is probably to write a script that identifies the world tiles where those are, and then use Embark Assistant to see where within that world tile the site is. The main purpose of the display is rather the opposite, i.e. avoiding accidentally embarking on a feature you don't want to mess with.
Logged

DerMeister

  • Bay Watcher
    • View Profile
Re: DFHack plugin embark-assistant
« Reply #110 on: September 15, 2019, 02:16:30 pm »

This plugin add ability to see buildings if I embark on site?
Yes or no, depending on what you mean...

The smallest overlay allows you to see the presence of sites (caves, shrines, etc.) but not the buildings within those sites (display of caves can be enabled by advanced world gen, but the others are not displayed by DF). Thus, if you want to embark on a vault with the aim of digging down to it you can, but the search function does not provide any option to search for them: you're restricted to scour world tiles visually.
The easiest way to find a kind of site you're looking for is probably to write a script that identifies the world tiles where those are, and then use Embark Assistant to see where within that world tile the site is. The main purpose of the display is rather the opposite, i.e. avoiding accidentally embarking on a feature you don't want to mess with.
I just want embark directly on underwold spire.
Logged

PatrikLundell

  • Bay Watcher
    • View Profile
Re: DFHack plugin embark-assistant
« Reply #111 on: September 15, 2019, 02:39:11 pm »

Candy spires are not sites, and thus not shown on the embark overlay. However, the plugin allows you to search for embarks with a given minimum number of spires, and the results will match only such sites.
There are 64 spires in each world tile, and they're randomly distributed within 2*2 mid level tile blocks aligned with the edges. Thus, a 2*2 embark flush to any corner will have exactly one spire, which randomly appears in one of the mid level tiles. If you're not aligned with the 2*2 grid the number is random, and a 3*3 embark will have 1-4 spires (it cannot align completely, so the number is random within that range.

The Region Manipulator tool allows you to shift spires within their 2*2 grids so you can increase (or decrease) the number of spires, e.g. 4 spires in a 2*2 non aligned embark (this also happens naturally, of course, but if you want it to match other search criteria as well it might not be present naturally.).
Logged

DerMeister

  • Bay Watcher
    • View Profile
Re: DFHack plugin embark-assistant
« Reply #112 on: September 15, 2019, 02:59:29 pm »

Candy spires are not sites, and thus not shown on the embark overlay. However, the plugin allows you to search for embarks with a given minimum number of spires, and the results will match only such sites.
There are 64 spires in each world tile, and they're randomly distributed within 2*2 mid level tile blocks aligned with the edges. Thus, a 2*2 embark flush to any corner will have exactly one spire, which randomly appears in one of the mid level tiles. If you're not aligned with the 2*2 grid the number is random, and a 3*3 embark will have 1-4 spires (it cannot align completely, so the number is random within that range.

The Region Manipulator tool allows you to shift spires within their 2*2 grids so you can increase (or decrease) the number of spires, e.g. 4 spires in a 2*2 non aligned embark (this also happens naturally, of course, but if you want it to match other search criteria as well it might not be present naturally.).
I want embark on dark fortress with candy spire in embark area.
Logged

RedDwarfStepper

  • Bay Watcher
    • View Profile
Re: DFHack plugin embark-assistant
« Reply #113 on: September 15, 2019, 05:44:27 pm »

Quote
It's largely a matter of which situation you want to optimize for:
a) Minimize the time it takes to search a full set of potentially matching world tiles; or
b) Minimize the time it takes to search a sparse set of potentially matching world tiles.
Now, if the cost to a) of achieving b) is small, it may be worth aiming for b).

Thank you for the fast reply.
Reading it I realized I need a much deeper practical understanding of how the plugin works - for example if all "attributes" describing a world tile are being extracted/loaded during a search run, even if there is no corresponding criteria that requires those attributes for matching.
So I'll set up the development environment and try to get the build/compile working with the latest version from git.
Then some light debugging ;D
That should help me to test and verify my assumptions - if they hold (probably a medium to big if) I might have an idea how to get a "cache" (=> actually an index) that can hold key information to speed up subsequent searches with a lot less than 30 GB of memory. Or I'll just realize that I was overly optimistic :D
I'll let you know as soon as there is something to share.
Logged

PatrikLundell

  • Bay Watcher
    • View Profile
Re: DFHack plugin embark-assistant
« Reply #114 on: September 16, 2019, 01:50:56 am »

Everything is not retrieved for every world tile. If the top level check rules out a match the tile is stepped into and out of after the first scan, without any processing. On the first one the data that's collated on the world tile level has to be collected, and that basically means collecting everything.
The real memory killer here is the geo biome derived info, as each mid level tile has one boolean vector for metals, one for economic materials, and one for any non organic material, and I think those vectors are 5-600 long.
Another thing to consider is that the memory usage shouldn't approach 2 GB, as that would crash the 32 bit DFHack.

However, stepping onto a world tile takes time, as DF has to generate all the mid level tile information for the all tiles in that world tile, so skipping 10 tiles can save some time, and even more time can be saved if you can skip loading a feature shell (through a diagonal movement instead of one horizontal and one vertical in either order).

It can only be good to have more eyes looking at the code and trying to improve it.

@DerMeister: If you search for candy spires and then look at tiles with dark fortresses (they're clearly visible, so you don't have to search for them), you can select embarks that have spires. Since dark fortresses tend to take up a whole world tile, there should be 64 spires the search can locate. You can also use Region Manipulator to get the spires displayed as an overlay, and thus clearly visible.
Note, however, that dark fortresses tend to be full of goblins, which not only means there's a risk of rather rapid extermination of the embark team, but also an extreme slowdown due to the excessive number of units at the site. Also you'd have to use DFHack's Embark Anywhere to be allowed to embark on top of a settlement.
Logged

DerMeister

  • Bay Watcher
    • View Profile
Re: DFHack plugin embark-assistant
« Reply #115 on: September 16, 2019, 07:57:56 am »

Everything is not retrieved for every world tile. If the top level check rules out a match the tile is stepped into and out of after the first scan, without any processing. On the first one the data that's collated on the world tile level has to be collected, and that basically means collecting everything.
The real memory killer here is the geo biome derived info, as each mid level tile has one boolean vector for metals, one for economic materials, and one for any non organic material, and I think those vectors are 5-600 long.
Another thing to consider is that the memory usage shouldn't approach 2 GB, as that would crash the 32 bit DFHack.

However, stepping onto a world tile takes time, as DF has to generate all the mid level tile information for the all tiles in that world tile, so skipping 10 tiles can save some time, and even more time can be saved if you can skip loading a feature shell (through a diagonal movement instead of one horizontal and one vertical in either order).

It can only be good to have more eyes looking at the code and trying to improve it.

@DerMeister: If you search for candy spires and then look at tiles with dark fortresses (they're clearly visible, so you don't have to search for them), you can select embarks that have spires. Since dark fortresses tend to take up a whole world tile, there should be 64 spires the search can locate. You can also use Region Manipulator to get the spires displayed as an overlay, and thus clearly visible.
Note, however, that dark fortresses tend to be full of goblins, which not only means there's a risk of rather rapid extermination of the embark team, but also an extreme slowdown due to the excessive number of units at the site. Also you'd have to use DFHack's Embark Anywhere to be allowed to embark on top of a settlement.
Spires is not visible. How make them visible?
Logged

PatrikLundell

  • Bay Watcher
    • View Profile
Re: DFHack plugin embark-assistant
« Reply #116 on: September 16, 2019, 08:33:33 am »

@DerMeister: As I said, spires are not displayed by this plugin. Instead, you search for matching embarks and embark in one of the matches.

The alternative, as mentioned as well, is to use the Region Manipulator, which does provide a display of spires: http://www.bay12forums.com/smf/index.php?topic=164136.msg7454345#msg7454345.
Logged

DerMeister

  • Bay Watcher
    • View Profile
Re: DFHack plugin embark-assistant
« Reply #117 on: September 16, 2019, 08:54:42 am »

@DerMeister: As I said, spires are not displayed by this plugin. Instead, you search for matching embarks and embark in one of the matches.

The alternative, as mentioned as well, is to use the Region Manipulator, which does provide a display of spires: http://www.bay12forums.com/smf/index.php?topic=164136.msg7454345#msg7454345.
And how make spires visible?
Logged

PatrikLundell

  • Bay Watcher
    • View Profile
Re: DFHack plugin embark-assistant
« Reply #118 on: September 16, 2019, 09:11:24 am »

@DerMeister: As I said, spires are not displayed by this plugin. Instead, you search for matching embarks and embark in one of the matches.

The alternative, as mentioned as well, is to use the Region Manipulator, which does provide a display of spires: http://www.bay12forums.com/smf/index.php?topic=164136.msg7454345#msg7454345.
And how make spires visible?
The script has a fair number of help screens. Read those. Hint: it's one of the overlays available through feature manipulation.
« Last Edit: September 16, 2019, 09:12:57 am by PatrikLundell »
Logged

RedDwarfStepper

  • Bay Watcher
    • View Profile
Re: DFHack plugin embark-assistant
« Reply #119 on: September 17, 2019, 04:46:24 pm »

@PatrikLundell
Got the compile, build and debug working.
But now I really need some sleep...
Logged
Pages: 1 ... 6 7 [8] 9 10 ... 24