GithubHelp home page GithubHelp logo

yuanchong1989 / objc-behaviortree Goto Github PK

View Code? Open in Web Editor NEW

This project forked from andoco/objc-behaviortree

0.0 0.0 0.0 381 KB

Behavior Tree implementation in Objective-C

License: Other

Objective-C 99.35% C 0.65%

objc-behaviortree's Introduction

Introduction

obj-behaviortree is an implementation of a behavior tree for iOS. Supported tasks include:

  • Selector
  • Sequence
  • Concurrent
  • Condition

Behavior trees can be built programatically, or by reading from a JSON file.

Requirements

The project currently builds and runs successfully with:

  • Xcode 4.5
  • iOS 5.0+

Setup

Clone the repository to a location on your machine, then:

$ git submodule init
$ git submodule update

Open BehaviorTree.xcworkspace

Test scenarios are available in the BehaviorTree project, which can be run in the usual way (CMD+U).

A demo project is available in the BehaviorTreeDemo project.

JSON Reader

A behavior tree can be built from a JSON representation:

{"type":"Selector","children":[
    {"type":"ShouldFlee","task":
    	{"type":"Flee"}
	},
	{"type":"ShouldSeek":"task":
		{"type":"Seek"}
	}
]}

The JSON is read by AOBehaviorReader which builds an instance of AOBehaviorTree:

NSString *json;
...
AOBehaviorReader *reader = [[AOBehaviorReader alloc] init];
AOBehaviorTree *behavior = [reader buildTreeWithFile:json];

The reader supports setting properties on task instances:

{"type":"MyAction","someBoolean":true}

If you want to set a property of type "Class", you can use the syntax:

{"type":"Flee","fromClassType":"class:MyEnemy"}

Task Class Prefixes

Task types read in from JSON are used to instantiate an objective-c class. To avoid polluting the JSON with class prefixes, you can register your own class prefixes that will be automatically searched when attempting to instantiate a task.

For example, if you register the prefix "AB" with the BehaviorReader:

AOBehaviorReader *reader = [[AOBehaviorReader alloc] init];
[reader registerPrefix:@"AB"];

and your JSON contains the task:

{"type":"MyTask"}

then the BehaviorReader will first attempt to find a class named "MyTask", and then if that class does not exist it will attempt to find a class named "ABMyTask".

Logging

Logging can be enabled by setting preprocessor macro flags on the BehaviorTree target.

BTree_NSLog

Logs to console window using standard NSLog

BTree_NSLogger

Logs to an NSLogger client using the NSLogger client library, which is much faster than using NSLog.

objc-behaviortree's People

Contributors

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