This is the AI I'm using (2016-10-25) for screeps. I managed to reach Top 10 from November 2015 - March 2016. Main Goal is to automated everything, no manual interaction needed. Some attacking creeps can be steared via flags.
The AI automatically generated a layout for the room and builds the structures
for the current RCL. With a scout
creep external harvest rooms are explored
and used. (SK rooms somwhow implemented, not enabled right now)
If the number of rooms are less than the GCL a new room
is acquired and build up. Also fallen rooms will be survived and basically
defended.
Some basic autoattacking is implemented, currently not enabled. Minerals
are fetched from the extractor and transported to the terminal. Reactions
are implemented (one reaction at a time, currently disabled). Depending on
a threshold minerals are sold on the market.
This is not a good example for code quality or structure, many LOC are written while fighting or other occasions which needed quick fixes or in the ingame editor. But I think there are a couple of funny ideas. Every contribution is welcome.
npm install
export email=EMAIL
export password=PASSWORD
grunt screeps
grunt jshint
grunt jsbeautifier
Positions:
builder
creep next to thecontroller
storage
structure next to thebuilder
filler
creep next to thestorage
pathStart
position next to thestorage
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. Link
s are placed next to the sources and at
the paths to the exits. Three layers of walls are placed at the exits, positions
within the precalculated paths are replaced by ramparts.
The number of structures are checked and if applicable new constructionSites
are places. Links are triggered to transfer energy to link near the storage.
Tower 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 enought 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 simple
queue is used.
builder
get energy from the storage, puts it into the controllerfiller
get energy from a link and transfers it to the tower or storagesourcer
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
reservs an external controller and callssourcer
carry
gets energy from the target container and fills structures and storage on the way back. If there is a creep in front the energy is transfered.scout
randomly walk in some room range and tries to find an unreserved room.harvester
moves on the harvester path, and transfers energy to free structures on the path. On low energy in storage, theharvester
gets energy from the sources builds structures and fills structures, ignoring precalculated paths. This is the fallback especially for the first roomnextroomer
moves to target room, gets energy from source, build structuresrepairer
build walls and ramparts
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 theroutePos
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 isStart
and the second the room to move to. - Last room (
routePos == route.length -1
): thetargetId
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 thetargetId
. - 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 be invalidate the cache.
- First room (