没有合适的资源?快使用搜索试试~ 我知道了~
Java Behaviour Trees
需积分: 5 0 下载量 191 浏览量
2023-12-21
17:04:10
上传
评论
收藏 519KB PDF 举报
温馨提示
试读
31页
JBS开发手册
资源推荐
资源详情
资源评论
Java Behaviour Trees, User Guide
Ricardo Juan Palma Dur´an
August 23, 2010
Contents
1 Introduction 2
2 JBT, an Overview 3
2.1 Model Driven by Ticks . . . . . . . . . . . . . . . . . . . . . . . . 3
2.2 Model Independent from Execution . . . . . . . . . . . . . . . . . 3
2.3 Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.4 BT Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.4.1 Execution Context . . . . . . . . . . . . . . . . . . . . . . 5
2.4.2 Native Tasks . . . . . . . . . . . . . . . . . . . . . . . . . 7
3 Step 1: Defining Low Level Actions and Conditions 9
4 Step 2: Implementing Low Level Actions and Conditions 13
5 Step 3: Creating BTs with the JBT Editor 21
6 Step 4: Creating a Java Declaration of the BTs 26
7 Step 5: Running the Behaviour Trees 29
1
1 Introduction
Java Behaviour Trees (JBT) is a Java framework for building and running be-
haviour trees (BTs). In the past few years, BTs have been widely accepted as
a tool for defining the behaviour of video games characters. However, to the
best of our knowledge, there is no free-software Java implementation of such
technology. With JBT we intend to provide a solid framework to build and run
BTs in Java.
JBT has two main parts. On the one hand, there is the JBT Core (it is the
Eclipse SDK project under the ”./JBTCore” directory of the repository), which
implements all the classes needed to create and run BTs. JBT Core basically
lets the user create BTs in pure Java and then run them. In order to ease
the task of creating BTs, JBT Core includes several tools that automatize the
process of creating BTs. In particular, it can create the Java source code of
a BT from its description in an XML format. By doing so, the user of this
framework basically has to worry only about defining BTs in XML files and
implementing the low level actions and conditions that his trees will use, which
are domain-dependant (that is, they depend on the game being played). We
provide a .jar file with all the JBT Core classes. Of course, in order to get the
last version of the JBT Core the repository can be accessed.
On the other hand, there is the JBT Editor (which is composed of two Eclipse
SDK projects under the ”./JBTEditor” directory of the repository). The JBT
Editor is a GUI application that can be used for defining BTs, and then export-
ing them into XML files in the format that the JBT Core understands. The
JBT Editor offers a set of standard nodes
1
for building BTs. It includes nodes
such as sequences, parallels, decorators, etc. For low level actions and condi-
tions, the user can provide their conceptual definition through Make Me Play
Me (MMPM) domain files (for more information on MMPM, see the Source-
forge page of the project ”Darmok 2”). The JBT Editor is an Eclipse RCP
application, so you must use Eclipse SDK in order to run it. An alternative to
run it is to use the executable files provided for each platform. Of course, if
order to get the last version of the JBT Editor the repository can be accessed.
JBT implements a BT model which is mainly based on that of the book
”Artificial Intelligence for Games”, second edition, by Ian Millington and John
Funge. JBT also includes the concept of ”guard” and static and dynamic prior-
ity lists, which make use of guards. JBT BTs are driven by ticks, which means
that, in order for them to have CPU time, they need to be externally ticked.
By following this pattern, the user can control how much CPU time the BT
consumes.
In this document we explain how JBT can be used to build and run BTs.
This process has the following steps:
• Defining low level actions and conditions to be used in the trees. These
actions and conditions are defined in the MMPM format.
• Implementing the low level actions and conditions. The user has to define
how the low level actions and conditions work. JBT does not know how
these domain-dependent actions and conditions work, so the user has to
provide a Java implementation of them.
1
Note that, when talking about BTs, node and task are used interchangeably.
2
• Creating BTs with the JBT Editor. Here, the user creates BTs that are
exported into generic XML files.
• Creating the Java declaration of the BTs that were declared in the XML
files. This is automatically done by one of JBT’s tools.
• Running the BTs by using the core classes of JBT.
In the next sections we will describe all of these steps. Also, we will con-
ceptualize them through a real example on a real game, since we will build a
tree that is able to control a Terran Marine of the Real Time Strategy Game
StarCraft.
2 JBT, an Overview
In this section we describe the JBT architecture as well as the main features
that BTs have.
2.1 Model Driven by Ticks
JBT implements a BT model driven by ticks. A BT must be evaluated through
ticks, so every game cycle an external caller ticks the tree in order for the tree
to update its status. A tick is just a way of giving the tree some CPU time
to update their status; in particular, ticks are used to give the nodes of the
tree some time to evaluate whether they have finished or not, and consequently
make the tree evolve.
The simplest approach to BTs driven by ticks is that of ticking the root node
and then letting each node recursively tick its children according to its semantics.
However, this is a very inefficient process, since in general the major part of the
nodes of the tree are just waiting for their children to finish. Therefore, they
should not receive ticks, since unless their children are done they will do nothing
useful when receiving the tick. Therefore, in general only very few nodes should
be ticked at a game cycle, and as a result JBT implements a model in which
there is a list of tickable nodes. Only the nodes in the list can be ticked.
2.2 Model Independent from Execution
When running a BT, there should be a clear distinction between the tree that
is being run (the model) and how it is actually being run (the execution). For
each particular behaviour, we distinguish between the Model BT that defines it
and how it is being run. The how is what the BT Executor does. Basically, for
every entity in the game that wants to run a behaviour (Model BT), there is a
BT Executor. The BT Executor takes the Model BT and processes it (without
modifying it), simulating the behaviour that is represented by the Model BT.
This choice implies that, apart from the Model BT, there is another type of
tree, the Execution BT. When an entity wants to execute a behaviour, the BT
Executor takes the Model BT and creates an Execution BT to execute the
behaviour. The BT Executor along with the Execution BT know how to run
the behaviour that the Model BT represents.
3
BT Executor
Control module
BT Executor BT Executor
Entity 1 Entity 2
Entity N
Model BT
Execution BT
Game AI
tick
Figure 1: Overview of the BT architecture
2.3 Architecture
Figure 1 shows an overview of the JBT Core architecture. There is a Model
BT that represents a particular behaviour. Also, there is a BT Executor for
every entity that wants to run the Model BT. Each BT Executor makes use of
the Model BT and builds an Execution BT that actually runs the behaviour
conceptualized by the Model BT. An external Game AI ticks the BT Executors,
in order for them to update the trees that they are running.
The user of the framework does not have to know all the details about how
JBT internally works. However, since he has to implement some classes in order
to run his own trees, at least he should know the general architecture of JBT.
2.4 BT Model
Before even starting to explain all the steps required to build and run BTs with
JBT, we have to first think about what BT model JBT offers. JBT implements
a BT model that is mainly based on that of [2]. Our model also include guards
and static and dynamic priority lists, as described in [1]. With this model the
user can implement a wide range of behaviours.
For instance, the tree of figure 2 represents a simple tree that is used by a
game character that wants to open a door. First of all, it checks if the door is
closed (condition DoorClosed). If so, then it tries to open it by executing the
action OpenDoor.
4
Figure 2: a simple behaviour tree
In the tree of figure 2 we can see four nodes. The node called Root is just
the root of the tree, and it has no actual meaning apart from it. Then there is
a Sequence node, which runs in sequence both of its children, the DoorClosed
condition and the OpenDoor action. The Sequence node is a standard node,
but both the DoorClosed and the OpenDoor nodes are domain dependent, that
is, they have been defined by the user so they have a useful meaning within the
context of the game being played.
The tree of figure 3 represents the behaviour of a character that is trying
to enter a room. The topmost selector succeeds as long as one of its children
succeed. The first child tries to enter the room when the door is locked. In such
case, the character tries several tactics to open the door. First, if it has the key,
it uses it to open the door. If it does not have the key, but it has a grenade, then
it uses the grenade in order to blow the door up. Finally, if none of the above
conditions are met, the character will try to enter the room through its window
(note that here a Subtree Lookup node is used. This node just runs a tree that is
already defined; in this case, the tree that will be run is EnterThroughWindow).
On the other hand, if the door is not locked and it is closed, the character will
just open it up.
2.4.1 Execution Context
All nodes in a BT have an execution context, which is usually shared by all of
them. The execution context, or context for short, acts as a blackboard that
can be used by nodes in order to write and read variables. For instance, a node
may write a variable into the context, under a name MyVariable. This variable
can be read then by using its name, MyVariable. This way, the context can be
seen as a way for the nodes of a BT to communicate.
However, not always all the nodes share the same context. In general, the
context of a BT is passed down from parents to children. Thus, the initial
context is that of the root of the tree, which will pass it to its children. The root’s
children will pass the context to their own children, and so on. Nevertheless,
some nodes do not pass their own context to their children, but another one
instead. This new context may be empty or not, and it may be of a different
type. JBT supports the following types:
• Basic Context: this is just a normal context, with no especial features. It
is the context that the user of the framework can create. Other types of
contexts are managed through decorator tasks, and the user cannot create
them.
5
剩余30页未读,继续阅读
资源评论
Key-N
- 粉丝: 8
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 技术面试最后反问面试官的话 校招面试非技术问题有哪些 非技术问题如何回答.png
- NB-IOT-BC26全网通模块Altium+ CADENCE +PADS三种格式(原理图SCH+PCB封装库)文件.zip
- 基于微信小程序开发的校园失物招领系统源码毕业设计(优质项目源码).zip
- 词向量是一种将自然语言中的单词转换为数值向量的技术,它能够捕捉词义和上下文信息
- nmap与masscan的简单使用
- MyBatis动态SQL.pdf
- 基于stm32单片机protues仿真的温湿度控制系统设计(仿真图、源代码)
- 词向量:自然语言处理的基石
- mybatis动态sql
- 40G微信小程序开发教程(工具插件+视频教程)
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功