The self-managing AI used by bonzaiferroni at screeps.com
This is the code running my AI on the MMO programming game Screeps. Back when I was learning screeps I was always looking for examples of other players' code, so hopefully this can be of some use. I'm still actively developing this code and using it on the MMO server. Searching the code to find vulnerabilities in my raiding/defense is fair game!
For people that are interested in using it on a private server or forking it, I've included some information on how it works. If it seems like people are using it, I will expand on this. If you have any problems or something seems really unclear, please raise an issue. You can also join the discussion in the slack channel #bonzai_public.
I had only been doing javascript/typescript for a few months when I started this. Any advice/guidance from experienced programmers is very welcome.
Using this code as-is on the MMO server could present some problems. First, the screeps world is most interesting when there are a diversity of ideas/approaches being tried. Second, there will no doubt be gaps in its functionality and undesired behavior. For example, the variable which defines your trading partners will be initialized to my own trading partner list.
For these reasons, I don't recommend using it that way without first going through the code and modifying its behavior to what you would like to see.
- All game decisions made by AI rather than user
- As a long term goal, decision-making that changes based on the results of previous decisions and through random mutations, resulting in novel behavior
At the moment, rooms are still chosen manually, although I've begun the process that the AI will eventually use. This can currently be found in AutoOperation, which will analyze nearby sources and the room layout and choose the best place to start building structures.
- Framework overview
- Quickstart: Write a couple classes that extends Operation and Mission to do all the basic creep behavior
If you aren't interested in modifying the typescript (perhaps you just want an opponent on a private server), you can save a lot of time by using the main.js file that you will find in the lastStableBuild folder (right click, save as). You can just drop this in your local folder.
Once you have the code pushed to a screeps server:
- Find a room and place a spawn
- If it has trouble determining a layout based on your room/spawn placement, it will let you know in the console. Just try again, perhaps a room with more space and don't place the spawn too close to a source.
- Place a flag with the name "quad_myBase"
Most of the tooling here has been taken directly from https://github.com/screepers/screeps-typescript-starter
- Run
npm installto install dependencies. - Create a copy of
config.example.jsonand rename it toconfig.json. - Then, on the
config.jsonfile, change theusernameandpasswordproperties with your Screeps credentials. Theconfig.jsonfile is where you set up your development environment. If you want to push your code to another branch, for example. - Run
gulp buildto compile/push your code. Rungulp copyLocalif you only need the code to go to the path set inconfig.json(like with a private server). Runninggulp watchUploadorgulp watchLocalwill have the code watch for changes and push code to the server or your local folder, respectively.
A variety of gulp tasks have been provided...
lintruns TSLint against /src/*compile-bundledcompiles the code into a single 'main.js' file in the /dist folder.compile-flattenedcompiles the code into the /dist folder but emits any folder structure (required for screeps)uploadcompiles according to your config.json file and uploads to the defaultTarget.copyLocalcompiles according to your config.json file and copies the result to the local directorywatchUploadcompiles and uploads to the server when a file is saved in your src directory.watchLocalcompiles and copies to your local path when a file is saved in your src directory.
you can run gulp tasks in the terminal... gulp copyLocal;
tasks are defined in gulpfile.js and you can read more about gulp here... http://gulpjs.com/
TSLint checks your TypeScript code for readability, maintainability, and functionality errors, and can also enforce coding style standards.
After each successful compiling of the project, TSLint will parse the TypeScript source files and display a warning for any issues it will find.
This project provides TSLint rules through a tslint.json file, which extends the recommended set of rules from TSLint github repository: https://github.com/palantir/tslint/blob/next/src/configs/recommended.ts
Some changes to those rules, which were considered necessary and/or relevant to a proper Screeps project:
- set the forin rule to
false, it was forcingfor ( ... in ...)loops to check if object members were not coming from the class prototype. - set the interface-name rule to
false, in order to allow interfaces that are not prefixed withI. - set the no-console rule to
false, in order to allow usingconsole. - in the variable-name rule, added
allow-leading-underscore.
More info about TSLint: https://palantir.github.io/tslint/