avdg / screeps

NOT MAINTAINED - Helper scripts for screeps.com - Unstable api and tools
https://trello.com/b/j475gMCU/avdg-screeps
MIT License
45 stars 10 forks source link

>_ Screeps ai

Join the chat at https://gitter.im/avdg/screeps

Build Status Code Climate Coverage Status* Dependency Status Dev dependency Status

* Covered files only

The main goal of this project is to provide a flexible framework for the ai.

Don't know anything about screeps?

Go to screeps.com or you could try ๐Ÿ•๐Ÿ’ฉ.ws/๐Ÿฏ๐Ÿ”ฎ๐Ÿ‘Š๐Ÿ‹๐Ÿ˜œ๐Ÿฑ๐Ÿฉ๐Ÿฐ

Install checklists

First install

Build configuration

AI build tricks

Code structure

In 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.

Ai rules / Ai constrains

AI script files

AI Object

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

Extensions folder structure

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:

Ai code

scripts/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.

Bonus: run code after turn

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))); }

Call hierarchy

 `- 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

Notes