1 Star 0 Fork 0

DJ / BehaviorLibrary

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
BSD-2-Clause

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();
Copyright (c) 2012, Thomas H. Jonell All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. The views and conclusions contained in the software and documentation are those of the authors and should not be interpreted as representing official policies, either expressed or implied, of the FreeBSD Project.

简介

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). Enjoy! 展开 收起
C#
BSD-2-Clause
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/dang050/BehaviorLibrary.git
git@gitee.com:dang050/BehaviorLibrary.git
dang050
BehaviorLibrary
BehaviorLibrary
master

搜索帮助