Automating Base Planning in Screeps – A Step-by-Step Guide
Why Base Planning?
Planning the layout of your base in Screeps might seem unusual at first, but it’s a crucial step in automating your bot. It’s also one of the most challenging tasks to tackle on your oen from scratch. While you don’t necessarily need to fully understand the algorithms involved, you should at least know how to utilize them effectively. So, here’s a step-by-step guide on how I automate my base planning. Let’s dive into it.
The Process
- Utilize Distance Transform: Start by employing the distance transform algorithm to identify open spaces in the room. Typically, my bot requires a 5x5 square to begin, so I target positions with a distance of 3 or larger. Some bots, especially those employing bunker-style base planners, may require squares larger than 10x10. Plan ahead for the desired size of your base. The distance transform code is available here.
- Select Starting Position: Choose an open area you think the best for your base. I prefer close to both the controller and energy sources, especially proximity to the controller. But remember, everything is up to you!
- Place Core Structures: Begin by placing core structures such as spawn, storage, and terminal. I surround the starting position with core structures using a 5x5 stamp for efficiency. Some bots utilize a stamp called “fast filler” to quickly fill extensions. The choice of design is up to you!
- Designate Controller Upgrade Area: Allocate a 3x3 area near the core structures for upgrading the controller. I made a mistake in the screenshot below. I didn’t considered properly that every position should be within range 3 to the controller. Don’t make a mistake like me!
- Implement Floodfill Algorithm: Utilize the floodfill algorithm to categorize tiles by their accessibility. Lower numbers indicate proximity to core structures. The floodfill code is available here.
- Allocate Tile Usage: Assign tiles for essential structures such as extensions, labs, towers, factory, nuker, and observer. I personally prefer a grid layout similar to the “commie bot.”
- Position Labs: Identify 10 suitable tiles meeting specific criteria, ensuring that there are two source labs within range 2 of every other lab. If it seems too complicated, it’s fine to use stamp for labs
- Establish Infrastructure: Lay down roads from storage to energy sources and minerals. Place a container and a link at each source, and a container and an extractor at the mineral.
- Optimize Ramparts: Utilize the minimum cut algorithm to determine optimal rampart positions, then connect them with roads. At this stage, I noticed my mistake I mentioned earlier and made the controller upgrade area to be closer to controller. The minimum cut code is available here.
- Tower Placement: Position towers to maximize their coverage. Personally, I prioritize maximizing the minimum damage of towers over base boundaries.
- Place Additional Structures: Situate the factory, nuker, observer, and extensions. Placement for the observer is less critical, so anywhere works. At this stage, I changed lab position a bit and marked them as green square.
Examples and Visuals
Here are some examples created by my bot. The upgrade area is marked with a yellow square, labs with a green square, and towers with a red square.
Automating base planning streamlines your development process and lays a solid foundation for your Screeps bot to thrive.
Leave a comment