Giter VIP home page Giter VIP logo

behavior3js's Introduction

BEHAVIOR3JS

Behavior3JS is the original implementation and official javascript version of the Behavior3 library. It provides structures and algorithms that assist you in the task of creating intelligent agents for your game or application.

Main features

  • Based on the work of (Marzinotto et al., 2014), in which they propose a formal, consistent and general definition of Behavior Trees;

  • Optimized to control multiple agents: you can use a single behavior tree instance to handle hundreds of agents;

  • It was designed to load and save trees in a JSON format, in order to use, edit and test it in multiple environments, tools and languages;

  • A cool visual editor which you can access online;

  • Several composite, decorator and action nodes available within the library. You still can define your own nodes, including composites and decorators;

  • Completely free, the core module and the visual editor are all published under the MIT License, which means that you can use them for your open source and commercial projects;

  • Lightweight!

Usage

Install the library

npm install behavior3js

You can use the online visual editor to design your behavior tree.

It is very recommended that you take a look into the user guide, for both core and editor, where you will find examples and descriptions of features in the library:

Contents

Core Classes

This library include the following core structures...

  • BehaviorTree: the structure that represents a Behavior Tree;
  • Blackboard: represents a "memory" in an agent and is required to to run a BehaviorTree;
  • Composite: base class for all composite nodes;
  • Decorator: base class for all decorator nodes;
  • Action: base class for all action nodes;
  • Condition: base class for all condition nodes;
  • Tick: used as container and tracking object through the tree during the tick signal;
  • BaseNode: the base class that provide all common node features;

Nodes

Composite Nodes:

  • Sequence;
  • Priority;
  • MemSequence;
  • MemPriority;

Decorators:

  • Inverter;
  • Limiter
  • MaxTime;
  • Repeater;
  • RepeaterUntilFailure;
  • RepeaterUntilSuccess;

Actions:

  • Succeeder;
  • Failer;
  • Error;
  • Runner;
  • Wait.

Building

In order to build the library or generate the documentation you must have NodeJS and gulp, and install the proper dependencies:

npm install

By using

gulp build

you get the concatenated and minified version of the library as well the documentation folder and compacted version.

Through the development, you can use

gulp dev

in order to watch the source files and run jshint automatically.

behavior3js's People

Contributors

danielepolencic avatar dennis1000 avatar renatopp avatar

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

behavior3js's Issues

Usage in node.js produces error unless I define b3 in the global namespace first

I am using behaviro3js in node.js, and it works, except that I have to declare an empty b3 object in the global scope first.

This works:

b3 = {}
var behavior3js = require('behavior3js');

However, if I just do this:

var behavior3js = require('behavior3js');

without the "b3" declaration I receive this error:

_filename, __dirname) { this.b3=this.b3||{},function(){"use strict";b3.VERSION
                                                                    ^
ReferenceError: b3 is not defined

Feature request: Node that detects when it was interrupted

What about a node type (I guess this would be a decorator) that detects if it was interrupted (i.e., not executed in two successive evaluations of the tree in a row) and then calls some kind of "resume" function that can be overwritten by children?

Example where this could be useful: In my game an entity walks along a path towards some goal, all of which is implemented in one sub tree in the behavior tree. But along the way, an enemy might come into sight and the entity might decide to fight that enemy instead of following the path, which is implemented in another sub-tree. When the enemy is dead, the entity wants to return to the path, which requires some re-pathing now (since walking towards the enemy might have made the current path un-optimal). This could happen in the "resume" function.

Currently I would have to implement this by checking (every time the tree is processed), if the entity is still on the current path (by checking if the entity is still inside the current polygon of the nav mesh) or if it has diverged from it too much. This is wasted performance.

Also note that this is just one example. I actually think there will be many more concrete cases where I could use this type of decorator in the library.

About implementation: Every time the tree is processed, you could increment some hidden counter variable after each evaluation of the behavior tree. A node has been executing continuously and uninterrupted if the counter c_n is equal to c_(n-1)+1 when the node is executing, and has been interrupted if c is something else.

edit: By the way, great library and great editor. Easy to use and extend.

Add bower install to README.md

Great work!
Seems that the bower install command is missing in the building section. Otherwise, the application gets stuck on the Starting Application...Have Fun! phase.

deploy to npm

Seems like the project is not deployed to npm... that would make it easier to adopt in other projects

Modernize the codebase

JavaScript has moved on and so should this awesome codebase.

I plan to use this fork ( https://github.com/yagl/behavior3 ) for my project because it uses ES2015 and a Babel workflow, it's a pity I can't use the original version of the library ๐Ÿ˜‰

add custom node

In the original branch, the add custom node function existed, but now it is gone

bower.json not well formed

Line 19 of the bower.json file has a trailing comma, which I believe is causing problems when trying to retrieve the framework using bower.

Simple implementation example [$20 awarded]

Could you please write a simple implementation example ? For example an agent behavior that roam randomly and eat when it's hungry ?

I'm very interested in learning and implementing tree behavior in js but must say I don't clearly see how to implement it in a basic architecture.

Thanks :)

--- The **[$20 bounty](https://www.bountysource.com/issues/25025597-simple-implementation-example?utm_campaign=plugin&utm_content=tracker%2F18331363&utm_medium=issues&utm_source=github)** on this issue has been claimed at [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F18331363&utm_medium=issues&utm_source=github).

Use ES6 classes

Hello,

Javascript classes have been released in June 2015 under the EcmaScript 6 specification. It would be great if behavior3js use them instead of its own class utility.

To ensure compatibility with browsers, we'll need to use something like babel to transpile ES6 to ES5.

This change will be heavy, but since there is a test suit we can do it without breaking features.

Question: Selector node

@renatopp: From everything I've read about behavior trees, probably the main logic node is the Selector. But in this library I don't see such class. Is it called something else? I'm new to this, sorry if this is a stupid question.
In the linked paper it is stated as well and I thought the library is supposed to be consistent with it.

Anyway, thank you for a great library. I'm gonna try to build something great with it. :)

Zoom reverse in the editor

The zoom short cut seems to be reversed in chrome and firefox. ctrl + scroll up and ctrl + scroll down work fine in chrome but have the opposite effect in firefox

Documentation

Please refer to behavior3/behavior3editor#18

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/27363212-documentation?utm_campaign=plugin&utm_content=tracker%2F18331363&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F18331363&utm_medium=issues&utm_source=github).

MemSequence bug?

Hi,

Thanks so much for a VERY comprehensive library. It's a work of art. We like it a lot.

i wonder if there's a bug in MemSequence, when it uses the open() method to reset the 'runningChild' index.

consider a MemSequence with 3 actions children.

  1. action1 starts, return RUNNING for a few ticks
  2. MemSequence is opened (stored at the open node list)
  3. action1 ends, return SUCCESS.
  4. MemSequence is closed
  5. action2 starts, return RUNNING
  6. MemSequence is opened
  7. runningChild is reset to 0!

if thats indeed a bug, i wondered where and when runningChild should be reset? is it a functional decision, based on some other parameters, or should it reset always when it reaches the end of the sequence?

also, what is the use for the openNode list?

thank you for any idea
Lior

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/40606176-memsequence-bug?utm_campaign=plugin&utm_content=tracker%2F18331363&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F18331363&utm_medium=issues&utm_source=github).

Wishlist for behavior3

this is my wish list for behavior3:

behavior3js:

  • second generation bt (event-driven)
  • subtree support

behavior3editor:

  • hierarchical nodes
  • subtree support
  • display title in the nodes (just a symbol is a bit uninformative)
  • comment area (coloured rectangle with nodes "inside")

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/36164291-wishlist-for-behavior3?utm_campaign=plugin&utm_content=tracker%2F18331363&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F18331363&utm_medium=issues&utm_source=github).

Build tasks combines classes in wrong order, breaking inheritanc

The gulp build task does not explicitly specify the order of inclusion of the main classes (BaseNode, etc), when concatenating. The result may have the child classes defined first before the parent classes which results in them inheriting from "null" when calls b3.Class(...)

Build tasks combines classes in wrong order, breaking inheritance

The gulp build task does not explicitly specify the order of inclusion of the main classes (BaseNode, etc), when concatenating. The result may have the child classes defined first before the parent classes which results in them inheriting from "null" when calls b3.Class(...)

This fix just specifies the scripts in the correct order when building.

about Tick._openNodes

When I define parallel nodes, tick._openNodes and lastOpenNodes have some problems
(my english is poor)

var start = 0;
var i;
for (i = 0; i < Math.min(lastOpenNodes.length, currOpenNodes.length); i++) {
  start = i + 1;
  if (lastOpenNodes[i] !== currOpenNodes[i]) {
    break;
  }
}

There are problems with this comparison


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

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.