Home - rfsjim/Screeps-Nooby-Typescript-Code GitHub Wiki
-
AI optimized for Shard 3 (low CPU)
-
This AI will quickly upgrade the controller level to 2. At which point, it will laydown a network a roads, and build extensions near the sources. When the controller level upgrades, it will check if it can build towers and more extensions. As the room's energy capacity increases, creepers spawned will become more powerful
-
The AI automatically generates a layout for the room and builds the structures for the current RCL. A scout creep or observer explores external harvest rooms. If the current number of rooms is less than the GCL, the AI will acquire new rooms. Fallen rooms will be survived and basically defended. The AI sends some waves of auto attacks. Minerals are fetched from the extractor and transported to the terminal. Reactions are basically implemented. Depending on a threshold minerals are sold on the market.
Routing
The routing from start to end is first done on room level:
- Find Game.map.findRoute(start, end) plus the start room added as first entry in the array. This is stored together with the routePos in memory of the creep.
- Inside a single room:
- First room (routePos == 0): Own rooms have a layout set with a path to each exit pre-calculated. The first part of the path name is Start and the second the room to move to.
- Last room (routePos == route.length -1): the targetId is stored in the memory of the creep. So the first part of the path name is the previous room and the second part is the targetId.
- Rooms on the path: The previous room is the first part of the path name, the next room is the second part of the path name. The path is cached in the memory of the room with a created attributes to allow invalidation.
AI Strategy
The AI employs a number of strategies to achieve both room objectives and game objectives.
Room Objective 1: Spawning in a New Room
The following directives are set in order build an extensive Road network, build Extensions, and build Containers.
- Start spawning creeps to be self-sufficient.
- Queue up road construction orders to make way for larger and slower creeps.
- Build Containers by the Sources.
- Upgrade the Controller in order to build Extensions.
- Build Extensions.
Room Objective 2: Establish Regular Colony Behavior
The following directives are added in order to establish regular colony behavior and build a Tower.
- Spawn Miners, that do nothing be harvest Sources and transfer energies to nearby Containers and Storage structures.
- All other creeps will try to get energy from these containers and storage structures.
- If a container becomes full, build another container next to it. (?)
- Continue to upgrade the Controller.
- Build towers near Sources and then Controllers. (game objective should be triggered when a room has two towers)
Room Objective 3: Defense
The following directives are added in order to establish defense:
- Builder creeps no longer repair. Towers repair.
- Find each exit and build walls and ramparts around it
- Spawn defenders when enemies enter the room.
Room Objective 4: Mature Room Behavior
The following directive are added once the controller reaches level eight:
- Minimize unneeded Creeps (?)
Game Objective 1: Expansion Into Other Rooms
This game objective should be triggered when a room has two towers.
- Send Scouts to discover other rooms, avoiding enemy rooms. Periodically recheck the room to see if other players have laid claim. Spawned Settlers will go two rooms away to reserve a room with two Sources and a Controller. Sending a defender and two harvesters along the way.
Game Objective 2: Aggressive Expansion
This game objective should be triggered when there are no more unexplored safe rooms.
- Build an army and send it to a room at the top of the desirable room queue that has an enemy.
Features
- Cities will use market to trade for minerals and sell excess resources for credits.
- Cities use labs to make max power boosts for military and upgraders from minerals.
- Cities mine power for power creeps.
- Cities mine commodities and will attempt to create high level products with available factories and sell them.
- All structures and roads are placed automatically
- If the current number of rooms is less than the GCL, the AI will acquire new rooms.
- New rooms will be claimed automatically (private server only)
Roles
- scout Breadth-first search based room exploring.
- harvester moves on the harvester path, and transfers energy to free structures on the path. On low energy in storage, the harvester falls back to the start up phase without relying on anything (storage, links, other creeps).
- filler get energy from a link and transfers it to the tower or storage.
- nextroomer moves to target room and builds up that room.
- repairer build walls and ramparts.
- sourcer get energy from source.
- Controlled room: Transfers the energy to the link.
- External room: Builds container, fills container, calls carry to get the energy.
- reserver reserves an external controller and calls sourcer.
- carry A carry transports energy from the target to the storage in the base (From sources, energy piles or storages in other rooms) They use fixed precalculated paths While moving they try to transfer energy to the next creep or if in base to other structures (tower, link, extension) So carries move forward if they have 'no' energy, backwards if the 'have' energy 'no' or 'have' is defined differently for different rooms
The idea behind that is:
- If the carry is in the target room, they should have a proper amount of energy to move all the way back
- If the carry is in an intermediate room, they should have at least a mediocre amount of energy to move back
- If the carry is in the base it should empty itself before moving back.
Carries are spawned by:
- sourcer: if the energy pile or container is over a certain threshold
- structurer: if the enrgy pile is over a certain threshold
- rooms: if the storage is below a certain threshold to get energy from another room
Core Roles
- Builder - build buildings from constructions sites, repair roads/walls
- Remote Miner - source of energy. mine energy sources in the room or neighboring rooms
- Runner - bring energy from miners to base
- Transporter - redistribute energy in base. load extensions, spawns, towers, factory, labs, and nuker
- Upgrader - upgrade base level, get energy from the storage, puts it into the controller.
- Ferry - miscellaneous task operator. tasks include; lab work, factory, terminal management etc.
Military
- Breaker - destroys enemy buildings. Pair with healer.
- Medic - heals other military units
- Quad - ranged group of 4 units. units heal each other and focus attacks.
- Defender - Defend against enemy invaders.
- Harasser - Ranged attacking unit for cheap damage to enemy remote miners and protecting highways
- Robber - takes resources from enemy rooms
Other
- Claimer - claim rooms for new cities (GCL 2 or above) below can reserve a room
- Deposit Miner - mine deposits in nearby highway rooms
- Mineral Miner - mine mineral source in the room
- Power Creep - boost other creeps/resources/structures in a room
- Power Miner - mine power in nearby highway rooms
- Spawn Builder - build initial buildings in a new city
- Scout - scout nearby rooms
- Un-claimer - attack enemy controllers
Room Setup
Positions:
- upgrader creep next to the controller
- storage structure next to the upgrader
- filler creep next to the storage
- pathStart position next to the storage From pathStart all (sources, controller, mineral, mid of each exit) paths are calculated and saved. The longest path is used to place structures (spawn, extension, lab, observer, terminal, tower) next to it. Next to filler a link, tower and power_spawn is located. Links are placed next to the sources and at the paths to the exits. Layers of walls are placed at the exits, positions within the pre-calculated paths are replaced by ramparts.
Logic
The number of structures are checked and if applicable new constructionSites are places. Links are triggered to transfer energy to link near the storage. Towers attack incoming creeps or heal my creeps. If no spawn is available nextroomer from other rooms are called, to build up the room.
The basic creep is the harvester which can make sure, that enough energy will be available to build the rest of the creeps. For this we check if a harvester is within the room, otherwise spawn it. For the rest a priority queue is used.