Compact Extension Arrays



  • EDIT:: Updated to reflect the fact you can only have 50 parts on a creep

    Hi all, I know this isn't necessarily a hot topic, but I figured it would be helpful and welcome in the General Discussion. I've sat and thought on the math behind depositing arrays efficiently, and I think I've come up with a good heuristic for depositing them.

    TLDR- This is an efficient and compact structure if your creeps deposit into extensions based on the empty ones closest to them:


    Defense follows:

    To start, we look at the base case for most efficient space to extension ratio, 1 extension per one space. Since we are working in a world where orthogonal and diagonal movement go hand in hand, we can say that our best base case is a situation where a creep is surrounded by extensions completely, meaning 8 extensions and a single creep inside them. This is of course silly, because the creep has no way to get energy to deposit. This means we have to have either a link or at least one space for the creep to exit by. Ignoring links, since we're trying to be as efficient as possible for our proof of concept, we make the first feasible base case:

    This allows a creep to enter and exit while depositing to 7 extensions concurrently if programmed to. A note: I'm measuring efficiency by number of ticks it takes to deposit completely, as well as number of ticks it takes to move in such a way you can make those deposits. The formula I'm using looks like this:

    total energy deposited / (number of deposit ticks + number of move ticks) = energy deposited average (I'll refer to this result as the EDA)

    The above image for our feasible base case requires two ticks to enter the center, then 7 ticks to deposit 350 energy (assuming beginning rates for extensions). This would give it an EDA of 38.8 repeated. Extending this principle we can get a structure like this:

    The colors there indicate concurrent deposits based on when a creep will come into contact with multiple extensions. We can see 4 distinct concurrent deposits here, and mapping out the moves from the first deposits on we count 15 deposit ticks and 4 moves. I'm up in the air abou counting the tick it takes for the creep to move into the space for the first deposit, but for consistency I'll be counting all moves from the first deposit from here on out. This gives the above structure an EDA of 39.47, but this structure highlights a problem: symmetrical designs can cause a creep to backtrack before it has deposited all of its energy, thus adding move ticks without also adding deposit ticks immediately afterwards. Working on this principle we can infer that, when making a deposit trip, we don't want to move backwards along roads until we have emptied our creep. This principle lends itself to the following design:

    If a creep has 15 carry, this tunnel is very efficient; with an EDA of 41.6 repeated. Still, this structure points to another flaw; the beginning deposits of 2 aren't nearly as efficient as the 4 concurrent deposits. Extending both the idea that deposits should follow this tunnel formation, with ends that always have 5 concurrent deposits, with a single deposit trip in mind, and with the idea that a creep should deposit a least to 4 extensions at a time, we get a structure like this:

    Note: From here on out I'll be trying to use all 60 extensions in my structures, as we want the most efficient structure with all 60 extensions inside it. This structure takes a small hit wth an EDA of 39.47 again, but the key here is that all 60 are used, the array is compact (at the cost of depositing three instead of four in some concurrent deposits), and the EDA is a good starting point while applying the principles we've discussed so far. But soon we realize no creep will ever be able to carry all of this energy at once; if you do in fact have 60 extensions, each one holds 200 energy. That's a total of 12000 energy in extensions alone and if you add the Spawn energy for the three spawns you can have at rcl 8 you reach 12900 energy, requiring 258 carry parts. We can't make a creep like that because the cost of a Carry part is 50 and it carries 50 energy on that part; this ratio inherently limits our creep to, at best, have 258 body parts total. If you use roads, the most a creep can carry and move without getting fatigued would be 86 Move to 172 Carry, meaning it could carry 8600 energy or 43 extensions' worth. This means a diagonal line containing 43 extensions with a road running down the middle is the most efficient for a creep with body parts as listed above, and that makes an EDA of 159.259, a big jump since now we're dealing with extensions with a higher capacity. That structure, however, has either an entrance or ending of only 3 extensions, and creating a single creep with the intention of depositing that much energy isn't a feasible plan; to expend all of your energy on a single creep designated to this task makes me uneasy, and to boot you're left with 17 extensions to deposit into on your second trip, meaning the creep we make is WAY overpowered for the job. Working on this, I tried to make a creep whose maximum efficiency is catered to depositing all energy across two trips efficiently. This would ideally be an even split of 30 extensions for each trip, and we can make a structure that generally follows this and our other guidelines:

    These tunnels have a great EDA at 165.71 each, but in order to achieve that we remove 2 extensions from the equation; dividing 30 among deposits of 4 ending in a deposit of 5 produces this problem. We can update the structure by making them a bit lopsided and accepting the fact that one deposit tunnel will be shorter than the other:

    The tunnel on the right has an EDA of 164.70, the one on the left an EDA of 164.10. I get these figures, again, by adding the amount of move ticks to the amount of deposit ticks and dividing the total energy deposited by that sum (5600/34 and 6400/39 respectively). Note the wall placement; it ensures the creep doesn't deposit until all four of the entrance extensions are in deposit range. I'm a bit confused as to why these numbers come out this way, except it seems the longer these tunnels get the less efficient they are despite the move to deposit ratio being similar. A creep built to deposit this energy would need to carry 6400 energy at most, so we give it 128 carry and 64 move, costing us 9600 energy. I'm still not happy with this figure though, because I want some kind of balance between the separate deposit runs; every time I deposit into the smaller, more efficient tunnel, I'm carrying too much energy and then will deposit into the next tunnel, throwing off the balance of the deposit runs and thus the actual efficiency. Back to the drawing board, I decided that we could get a series of shorter tunnels that are more efficient and divide the deposit runs evenly. Since the ultimate goal is simply to move the total 6k energy a couple of sources can produce in a single cycle of 300 ticks, as long as we achieve that goal in an efficient manner it shouldn't matter how many runs our creep needs to make. Plus I never like having a single creep dedicated to hauling energy to my extensions and spawns; since they are the lifeblood of a colony, if one dies and you don't have the energy to make another you're gonna have a bad time. Thinking of a structure with two creep dedicated to depositing energy evenly across two extension spawn arrays, I made this:

    And that quickly turned into this:



    Ok, I lied a bit at the beginning; I did in fact include a link here. Something really appealed to me about having an enclosed, compact, and efficient deposit array. This one includes all of the spaws, towers, and a storage consistent with the max number of those structures a room can hold. It also caps the ends of these tunnels with spawns, a nice touch for the efficiency. I'm pretty sure spawns follow the NW rule when placing new creep, so making sure you spawn your carrier from the right spawn orientation is feasible and necessary. If you have 2 creep working these extension arrays, they'll need to carry 3500 energy along each route, and the beauty of the shorter route is by capping it with storage you can simply drop excess off if you make it the last branch the creep deposits to. This would mean you need a creep with 70 carry, 35 move, and it would cost 5250, less than half the total energy pool per creep. If you don't want to lose the energy spent in a link, you could always program something to deposit the energy into the storage and work from that point, but it would be a waste of movement to start down that tunnel every time. Still, as long as you're capable of depositing 6k every 300 ticks ( a source's cycle), you've got all the efficiency you will reasonably need.

    In conclusion: the above structure is compact, efficient, and configurable regarding structures that require energy to be deposited into them, while allowing users to maintain such efficiency as they build it across multiple rcls. The EDA on the final structure is 205.88, a very nice EDA. I'm hesitant to say it's the best, but for the space required and the low cost of creep to maintain it, coupled with the fact that this structure could accommodate most of your energy deposit needs (labs aren't included in the figure above, and while you could reasonably include them I prefer to deposit to towers first), it's pretty good. I haven't actually considered a lot of cases here, including what I've termed the "priming" phase where the towers get filled, but mine generally stay full unless I'm being attacked or heavy repairs are necessary, so for this example I'm going to assume they stay topped off.

    For those of you that read this in full, I am sure you have suggestions, critiques, and even better ideas. I'd love to hear them, feel free to point out any glaring errors I've made in the comments below.

    ADDITION AFTER EDIT::

    Thanks to the cool guys on slack I remembered I can only have 50 parts on a creep, meaning we can at best carry 1650 energy with 33 carry and 17 move. Since I want nice round numbers, and since the extra 50 energy doesn't amount to much when doing the math, I have amended this guide to recommend you make two creep with 32 Carry 16 Move for the following structures:

    Note: use roads to make this possible with a creep that doesn't match it's carry parts one for one with move parts. With the layout on the left, you've got 4 branches of 8 extensions for an even 1600 energy on each branch, a full delivery for a creep with 32 carry and an EDA of 177.77 repeated per branch. You can optionally use towers to prevent the creep from depositing before it hits the extensions to ensure a deposit cycle of max efficiency, or you can use walls. I think I'll use it as a forward base. The building on the right is a bit trickier; it imitates the first except for one branch, that houses the spawns and storage. To give you an idea of the problem we face: max energy in a room is 12900, and dividing that by 1600 (the amount of energy our creep can carry) yields 8.0625, a tricky number to deal with since it represents the number of trips our creep will need to make. We'd like a nice round number for an even number of trips, but if we pretend for a minute that 100 of that energy isn't there we can divide 12800 by 16 for an even 8 trips, the number of branches we have in total among our layouts. In that sense, we can tack all 3 spawns into that last branch and take the hit of not being able to deliver the last 100 until a second round with this in mind: once the 100 energy gap is all that's left to deposit, the storage and terminal are RIGHT next to the last spawn, meaning we then get to deposit the excess 1500 directly into them. Fun fact: this also has an EDA of 177.77, since the creep can only carry 1600 and it deposits it all after one move once it has started depositing. The big thing I've learned by playing around with all of this is that 4 extensions in cascading V shapes as these corners indicate are definitely the most basic layout by which efficient extension layouts are built.



  • Hi! I think a "real world" implementation also should take into account that spawns/extensions are not equal. Some spawns/extensions will be used much more than others. With such a consideration you have to differ and rate use-cases depending on a concrete spawn-energy usage behaviour. Currently you only rate one use-case, where all structures are depleted. But for that case of course you have a good structure-configuration.



  • That was an interesting read. I like how Screeps is full of interesting problems like this that you can analyze to a pretty satisfying depth.  I recently planned out a new layout and it is interesting that it seems to have a similar shape at least for the extensions/towers.

    It seems to follow from the same ideas. I will actually only have a single creep delivering energy under most circumstances since in my experience this is more than enough. 

    The actual use ends up being a bit messier, extensions will become depleted at fairly unpredictable intervals and it is unlikely most deposit trips will follow the most efficient pattern. In the end, not many things will hinge on the efficiency of your spawn energy delivery, as long as it gets refilled before the spawns become available again it will not be a bottleneck. This will happen even with a relatively inefficient setup.



  • Good points made here: a lot of this problem is self imposed, as efficient energy deposits aren't going to make or break your colonies as long as your haulers manage to empty storage at a reasonable rate. I'm also fairly confident there are better philosophies that take in more nuanced looks at this problem as it relates to colony building and organization. Thanks for sharing your camp layout!



  • Updated after more consideration and lots of time. This has been an updated article on steam for a while, but I couldn't have the outdated version living on the web without amendments.

    👍