R-O-C-K-E-T / Factorio-SAT

Enhancing the Factorio experience with SAT solvers
GNU General Public License v3.0
627 stars 16 forks source link

Extending support to Space Exploration's Deep Space underground belts #17

Open xane256 opened 2 months ago

xane256 commented 2 months ago

Space Exploration adds "Deep Space Transport Belts," splitters, and underground belts, which are expensive end-game belts that operate at twice the speed of vanilla blue belts. There are 8 different colors of belts but the actual belt / splitter items are functionally equivalent / interchangeable. The underground belts however only link to their own color, so you can have multiple underground segments in the same linear space where they would otherwise conflict. Additionally the underground belt range is 17 tiles where blue belts are only 9.

As a proof of concept I manually shrunk an 8-8 balancer using the alternative colors. Left: Traditional 8-8 balancer, not TU, color-coded for structure Middle: Shortened version with matching colors Right: re-colored with 2 colors.

image

I've forked the repo to explore the possibility of improving other balancer designs with new constraints for the additional colors. I'd love some guidance on where I might start, or if you foresee any large hurdles I might run into.

Finally, as a separate issue, I got an error when running an example from the readme. I ran calculate_optimal compute --threads 1 8 length and got ValueError: Wrong bound: 17 which I suspect is related to the DS belts. Thanks for any advice on this too!

ignaloidas commented 2 months ago

This seems like a fairly interesting space to explore. I've looked at longer underground ranges with the announcement of a new belt tier with 10 tile range, but it seems like there's not that much benefit on going with longer - I checked lengths up to 10 and also unlimited range undergrounds, but that doesn't give any improvements for balancers up to 8-8, without using some wonky grid sizes.

Undergrounds with multiple levels(I'll refer to space exploration's colors as levels because the color is used in the project for a different meaning) are a lot more interesting though, and should be fairly easy to add as a quick hack. In solver.py you would essentially want to duplicate the variables in the tile template for each underground - that would be variables is_underground_in, is_underground_out representing underground inputs/outputs, underground representing underground paths under a tile, and colour_ux, colour_uy representing the underground "color" for undergrounds in each cardinal axis. Color in the project is essentially tracking the "identity" of a belt as it relates to a balancer network. Then you'll want to ensure that only one level of underground_in/underground_out is allowed, and then essentially duplicate all of the existing clauses for undergrounds in solver.py for each level of underground. After that, you'll want to update tile.py so that it could properly export the underground level information into factorio blueprints. You might also want to update the various optimizations to support multiple underground levels, though it's not strictly needed to just get some balancers out.

That's the quick and hacky way of getting support - it would probably not be fit for merging as is, but maybe something a bit better could be worked out.

R-O-C-K-E-T commented 1 week ago

Even in the current version of vanilla Factorio multiple levels of underground are used in the current best 128-128 and 64-64 designs and with the new belt tier in 2.0 this will be even more powerful. So this is definitely something that Factorio-SAT will need to support at some point.

To expand on the previous comment, to avoid creating too much copy-pasta you could represent each level of underground as an element in an array. Then loop through all the levels where required. Setting this up will require modifying the template defined in the Grid class to include an updated 'underground' type (e.g. ArrayTemplate(CompositeTemplate(...), (underground_level_count,))).