Giter Club home page Giter Club logo

behaviorlibrary's Introduction

Behavior Library

BehaviorLibrary is a framework for creating behavior trees for game AI. It is free to use, modify, and redestribute as covered under the attached License (FreeBSD).

It is simple to use and with that simplicity comes performance.

Example of a simple A* following AI on a tilemap

//setup all coniditionals and their delegate functions
Coniditional tooClose = new Conditional(isTooClose);
Coniditional targetMoved = new Conditional(hasTargetMoved);
Coniditional pathFound = new Conditional(hasPathBeenFound);
Coniditional reachedCell = new Conditional(hasReachedCell);
Coniditional reachedTarget = new Conditional(hasReachedTarget);
Coniditional isNewPath = new Conditional(hasNewPath);

//setup all actions and their delegate functions
BehaviorAction moveToCell = new BehaviorAction(moveTowardsCell);
BehaviorAction calcPath = new BehaviorAction(calculatePath);
BehaviorAction initPathfinder = new BehaviorAction(initializePathfinder);
BehaviorAction getNextCell = new BehaviorAction(getNextPathCell);
BehaviorAction setPath = new BehaviorAction(setNewPath);
BehaviorAction getPath = new BehaviorAction(getCurrentPath);
BehaviorAction updatePosition = new BehaviorAction(updateTargetPosision);
BehaviorAction reset = new BehaviorAction(resetPathfinder);
BehaviorAction animate = new BehaviorAction(updateAnimation);

//setup an initilization branch
ParallelSequence initialize = new ParallelSequence(initPathfinder, calcPath);

//if the target has moved, reset and calculate a new path
ParallelSelector ifMovedCreateNewPath = new ParallelSelector(new Inverter(targetMoved), new Inverter(reset), calcPath);
ParallelSelector ifPathFoundGetPath = new ParallelSelector(new Inverter(pathFound), getPath);
ParallelSelector ifPathNewUseIt = new ParallelSelector(new Inverter(isNewPath), setPath);
ParallelSelector ifReachedCellGetNext = new ParallelSelector(new Inverter(reachedCell), getNextCell);
ParallelSelector ifNotReachedTargetMoveTowardsCell = new ParallelSelector(reachedTarget, moveToCell);
        
//follow target so long as you're not too close and then animate
ParallelSequence follow = new ParallelSequence(new Inverter(tooClose), updatePosition, ifMovedCreateNewPath, ifPathFoundGetPath, ifPathIsNewUseIt, ifReachedCellGetNext, ifNotReachedTargetMoveTowardsCell, animate);

//setup root node, choose initialization phase or pathing/movement phase
RootSelector root = new RootSelector(switchBehaviors, initialize, follow);

//set a reference to the root
Behavior behavior = new Behavior(root);

//to execute the behavior
behavior.Behave();

behaviorlibrary's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

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