Git Product home page Git Product logo

aivo's Introduction

aivo

Aivo is a simple C# Code Driven library for implementing game AI. It uses .Net 3.5 and is compatible with Unity. It is inspired by Fluent-Behaviour-Tree & Java Behaviour Trees. The goal of this library is to make it easy to compose different kinds of behaviours by reusing the pieces as much as possible.

Introduction to Behaviour Trees can be found from here about behaviour trees for game AI.

Currently Aivo implements the only basic set of Behaviour Tree Node types.

Installation

Get release dll from here.

Usage

Example for creating a behaviour for a bot AI for Clash Royale kind of game.

Creating the behaviour tree:

using AivoTree;
...
var tree = new SelectorNode<BotContext>(
                new SequenceNode<BotContext>(enoughManaToDeployUnit,
                                             lessUnitsThanOpponent,
                                             bestTargetToAttack,
                                             bestUnitToAttack,
                                             deploySelectedUnit));

Calling the behaviour tree in every game tick:

var context = new BotContext();
var status = tree.tick(tickTime, context);
// Do something with status

Statuses

public enum AivoTreeStatus
{
    Success, // The node has finished what it was doing and succeeded.
    Failure, // The node has finished, but failed.
    Running  // The node is still working on something.
}

Composite Nodes

Sequence

A sequence will visit each child node in order. If any child node fails it will immediately return failure to the parent node. If the last child node in the sequence succeeds, then the sequence will return success to its parent node.

new SequenceNode<Context>(node1, node2, node3);

Selector

A selector visits child nodes in sequence until it finds one that succeeds. For child nodes that fail it moves forward to the next child node. Returns a failure if none of the child nodes succeed.

new SelectorNode<Context>(choice1, choice2, choice3);

Inverter

A invertor inverts the result of the node. If the node beeing inverted returns running inverter returns running too.

new InverterNode<Context>(node);

Leaf Nodes

ActionNode

Action nodes run a single command, update the state in context and return the Tree status. Command is defined as a function that takes in a game tick (see Game Time later on) and the context (see Data Context later).

var lessUnitsThanOpponent = new ActionNode<Context>((timeTick, ctx) =>
{
    var playerUnits = ctx.gameModel.PlayerUnits();
    var opponentUnits = ctx.gameModel.OpponentUnits();

    if (playerUnits.Count() < opponentUnits.Count())
    {
        return AivoTreeStatus.Success;
    }
        return AivoTreeStatus.Failure;
});

Data Context

As the goal of the library is to make it easy to reuse parts of trees it is not encouraged to access global variables from the nodes. Instead the user defined context object is passed to all the nodes . The node should read the latest state from the context object and update the context accordingly.

Data context is highly dependent on the case so there are no limits for it. It is just class that you can define.

For example:

public class MyContext
{
    public String selectedTargetToAttack;
    public GameModel gameModel;
}

Game time

You should pass game time for every Tick call. The time can be absolute time (for example in ms) or game frame number. This depends on your implementation. However, Aivo expects that number increases with every tick at least by one.

Roadmap

The short term goal is to add support for random order selectors and sequences. Also the current version is not performance optimized yet.

Contribute

Use GitHub issues and Pull Requests.

License

Copyright (C) 2017 Markus Hjort

Distributed under the MIT License.

aivo's People

Contributors

mhjort avatar

Watchers

James Cloos 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.