>_
Screeps ai* Covered files only
The main goal of this project is to provide a flexible framework for the ai.
Go to screeps.com or you could try ๐๐ฉ.ws/๐ฏ๐ฎ๐๐๐๐ฑ๐ฉ๐ฐ
npm install -g grunt-cli
.git@github.com:avdg/screeps.git
.
npm install
to install dependencies.settings.js
in an editor (if the file is not available, run grunt
in console), fill in the options and save the file.grunt deploy
grunt codegen
: Build generated code
grunt deploy
: Pushes code to screeps.com
grunt run
: Run the bot in a fake and incomplete simulator
grunt test
: To make sure that the code is passing the checks
grunt
is currently set to grunt test
mocha
is available for testing purposes
Code
structureIn the current structure there are only 2 files generated for deployment. The first file is an auto generated main.js, which is the compiled version of all the extension directories sticked together. The second file contains settings, allowing to fine tune settings in-game.
scripts/main.js
is the boot file and is the first user code to be executed,
its being executed once a tick in the screeps sandbox.
Also note that not all code of my current ai are included in this repo. The private ai code I deploy are just other extensions.
noRole
event_settings.js
Drain for global AI settings.When the autogenerated main.js gets executed, it will expose an AI
object in global scope.
The AI object has _settings
included as AI.settings
, so there is no need to include this file.
It also includes code from extensions accessible from AI.extensions
.
_generated
is a generated file that only exists in the build/deploy
folder when using grunt deploy
or grunt codegen
After using require('_generated')
it will expose the extensions as
AI.extensions.<type>.<plugin>
.
These files are coming from the extensions/
directory with a structure as
extensions/<package>/<type>/<plugin>
.
These include all files ending with .js
, excluding the files starting with a .
like .thisFileWillBeIgnoredAnyway.js
or located in directories starting with a '.'.
When generating the extensions, all packages are virtually merged into a single package.
This is how it ends up using the AI.extensions.<type>.<plugin>
format.
Current extension types are:
extensions/<any directory>/commands/
extensions/tools/hooks/flags
or AI.exec(<command>, ...)
extensions/<any directory>/hooks/
firstTurn
: Called when the AI is doing its first turnpreController
: Called before giving spawns and creepers orderspostController
: Called before shutting down the AInoRole
: Called when a creep has no rolenoSpawn
: Called when a spawn has nothing to spawnAI[key]
extensions/<any directory>/roles/
Creep.memory.role
will be executedextensions/<any directory>/routines/
AI.get(target, options)
or Room.get(target, options)
for getting objectsAI.extensions.target.filter
contains customizable filtersAI.extensions.scripts.main
will be executed unless extensionsBootstrap
is set to false
at the code generatorscripts/main
is the boot file. From there it includes other files in the script/
directory.
Most of these scripts (called stages) utilizes code from extensions.
Set global.run
with a function at wish, and it will be executed after the turn.
For example, this code can be typed or pasted in to the console:
global.run = function() { console.log(JSON.stringify(Object.keys(AI))); }
// Or using the es6 arrow syntax
global.run = () => {console.log(JSON.stringify(Object.keys(AI))); }
`- Start timer
`- Run extensions/**/scripts/main.js and friends
| `- `stage_setup()` Prepares game state for AI
| `- `AI.emit("firstTurn") Triggers firstTurn hook if current turn reboots the AI
| `- `AI.emit("preController")` Triggers firstTurn hook
| `- `stage_creeps()` Iterates over every creep (give orders)
| `- `stage_spawners()` Iterates over every spawner (give spawn jobs)
| `- `AI.emit("postController")` Shutdown and triggers postController hook
`- Stop timer