Coder Social home page Coder Social logo

bonzai's Introduction

bonzAI

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.

I had only been doing javascript/typescript for a few months when I started this, so if you are wondering why I'm doing certain things it is probably because I don't know any better. Any advice/guidance from experienced programmers is very welcome.

Installation

Install typescript and some system for compiling as you code (eg Webstorm) run npm install to setup grunt for pushing code up.

Once you have the code pushed to a screeps server:

  1. 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.
  1. Place a flag with the name "quad_myBase"

Goals of bonzAI

  • 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

Current status on goals

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.

Overview

Files in this codebase can be neatly separated into two categories:

  1. Framework: Abstract classes like Operation and Mission along with the supporting classes SpawnGroup and Empire
  2. Implementation: Concrete classes that extend Operation and Mission and make up the of game mechanics / creep behavior.

Overview of framework

Depending on whether you want to write code using this framework or just understand my own code so you can easily take down my rooms, it will help to know about the framework.

The archictecture of the framework is best understood by looking at main.ts and the code within module.exports.loop. The following figure shows how phases (init, roleCall, actions, finalize) are executed within the loop.

framework overview

Each phase is executed completely for each operation before moving on to the next phase. This allows you to assume, for example, that every initOperation() and initMission() function has been executed before any roleCall() function is executed.

Creep behavior is always defined in a mission, which also defines the spawning conditions and data-gathering necessary for that class of creeps. Operations are really just a collection of missions that get bootstrapped by placement of a flag in the screep world.

Additional framework topics:

  • Spawn Order
  • Persistent data (memory)
  • Phase functions
  • SpawnGroup (coming soon)
  • Empire (coming soon)
  • Cache invalidation (coming soon)
  • Tutorial: Write a couple classes that extends Operation and Mission to do all the basic creep behavior (harvesting, building construction, etc.) (coming soon)

Overview of AI implementation

This repository includes all the missions/operations that make up the bonzaiferroni AI. Players looking to write a completely original AI can simply take the framework and write their own concrete classes that extend Operation and Mission.

The following is a summary of the Operations/missions you can find in this repository:

Operations

  • QuadOperation: Manages all missions relative to an owned room, including upgrading, tower defense, spawn refilling, and more
  • FlexOperation: All the functions of QuadOperation but uses a flexible layout that is compatible with a wider variety of rooms
  • MiningOperation: Remote harvesting in non-SK rooms
  • KeeperOperation: Remote harvesting in SK rooms
  • ConquestOperation: Spawn creeps to be used to settle a new owned-room.

Missions

  • Defense
    • BodyguardMission: Protect creeps working in non-owned rooms from invaders
    • EnhancedBodyguardMission: Protect creeps from boosted invaders in SK-rooms and cores
  • Infrastructure
    • PaverMission: Keep roads repaired
    • TerminalNetworkMission: Trade resources with other rooms and with ally rooms
    • LinkNetworkMission: Send resources around an owned-room
    • BuildMission: Build structures in an owned-room
    • RemoteBuildMission: Build structures in a non-owned-room
    • RefillMission: Refill spawns and extensions with energy
    • IgorMission: Manage labs and special resource use
  • Resource gathering
    • MiningMission: Conducts energy mining activities relative to a single energy source
    • LinkMiningMission: Uses a link to fire energy mined from a source to a storage in an owned-room.
    • EmergencyMiningMission: Builds miners small enough to resume energy in a room that has suffered some critical failure
    • GeologyMission: Like MiningMission, but manages a Mineral source
  • Progress
    • UpgradeMission: Upgrade controllers

bonzai's People

Contributors

bonzaiferroni avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.