Screeps #24: Boosting to the Moon

by on under screeps
4 minute read

The article below describes the AI in its current state: I’m still expanding and refining my codebase. Here’s the GitHub repo if you’d like to follow along.

Labs and Boosts

In a previous article we began tackling labs, getting to the point that we could harvest minerals and run reactions to create compounds and eventually boosts. This was tabled for Botarena, but it’s time to pick this back up and finish the work we started.

First, we need to be able to source minerals when we don’t have a corresponding mine. We’ll update our market code to sell surplus minerals and use the credits to buy more of whatever we need.

Second, we need to create boosts. This is mostly the work from our previous post: the target boost quotas are hard-coded, so we’ll set each office to creating 10k units of ghodium acid (for controller upgrades).

Finally, we need to use the boosts. We’ll start with our Paralegals, boosting them to improve upgrade speed.

Market Mayhem

Playing with the market can be risky, and the complexity ceiling for a truly good implementation is high. But that’s not why we’re here today, so we must resist that urge. Instead, we’ll check two simple rules:

  1. If an Office has a surplus of a resource and no Office has a deficit, sell the surplus.
  2. If an Office has a deficit of a resource and no Office has a surplus, buy the deficit.

This has no real safeguards for market swings or temporary spikes, but it works. Surplus minerals get balanced to our offices, preferentially, and then the surplus is sold; when we have no mines to supply the minerals, they are purchased from the market instead. This gives us enough to get the labs up and running.

For now, we’re just buying the base minerals, not compounds. Eventually, we’ll need to do the math on which is the cheapest way to fill an order, and buy the compounds if we can get them more cheaply than making them from minerals.

Boosting Minions

This has several moving pieces. Let’s take it one step at a time.

Prep the Operating Theater

We need to clear out some labs for boosting. Each lab can only hold one kind of resource at a time, so if we need multiple boosts (to boost heal and attack, e.g.) we’ll need to reserve multiple labs. The remaining labs (if available) can keep working on reactions.

Currently we have the first two labs designated as input labs and the rest as output labs. We’ll keep a separate list of boosting labs, along with the compound they are currently using, and remove them from the input/output lists accordingly.

As part of our runLabs process, we’ll scan the list of boosts to prep. If there’s a boost that doesn’t have a corresponding boosting lab, we’ll set one aside.

Stock the Surgery

We’ll add boosts to the Scientist’s to-do list only when the minion in question is actually spawning. In most cases the minion should be large enough that this gives the Scientist plenty of time to empty the lab(s) and refill them. This will be the Scientist’s first priority - maintaining ingredients for reactions is not time-critical.

When a boosting lab has the wrong resource, the Scientist will empty it and ferry the resources back to the Terminal. When a boosting lab needs more boosts, the Scientist will fetch them from the Terminal and ferry them back to the lab. This is pretty similar to the default behavior for stocking labs for reactions, but a little simpler.

Boosting also requires energy, but we’ll handle that a little differently - we already have a role for filling structures with energy, so we’ll just tack the labs on to our RefillExtensions workload. We’ll put them at the front of the queue, not because they are more important but because waiting for all extensions to be filled in a high-spawn-rate situation may mean the labs never get attention.

Do the Boost

Now comes the test. The BoostOrders are generated by the creep that wants to be boosted. Once its spawning begins, it should check the Terminal’s inventory to see how many boosts are available. If there are enough, it will place a BoostOrder, and the Scientist will do its job.

Once spawning is complete, if the minion’s state is GET_BOOSTED, it will move to the labs and trigger its boosts. Then its state will reset and it will set about its normal tasks.

Our test case will be the Paralegal, our dedicated upgrader minion. We’ll boost the work parts with ghodium acid to increase upgrade effectiveness by 80%.

Results

I elected to test this in MMO rather than a private server as I haven’t gotten the private server market working to my liking. The MMO market means we have access to all the minerals we need for boosts, provided we have credits. And selling the extra minerals we harvest provides a good source for credits.

Currently we have three rooms on shard3, two at RCL6 and one at RCL5. This gives us a handful of labs to work with - three per RCL6 room.

And our results are decent - not perfect, there are still some efficiency kinks to work out, but we have successfully boosted upgraders!

comments powered by Disqus