Crates.io | piston-ai_behavior |
lib.rs | piston-ai_behavior |
version | 0.33.0 |
source | src |
created_at | 2014-12-11 21:00:49.581536 |
updated_at | 2021-11-03 08:55:34.689543 |
description | AI behavior tree |
homepage | https://github.com/pistondevelopers/ai_behavior |
repository | https://github.com/pistondevelopers/ai_behavior.git |
max_upload_size | |
id | 530 |
size | 31,162 |
AI behavior tree
You can serialize the behavior tree using Serde and e.g. Ron.
An AI behavior tree is a kind of state machine logic for processes.
Many things that a game logic does, e.g. controlling AI characters, fits the pattern of AI behavior trees.
An AI behavior tree is a very generic way of organizing interactive logic.
It has built-in semantics for processes that signals Running
, Success
or
Failure
.
For example, if you have a state A
and a state B
:
A
to state B
if A
succeeds: Sequence([A, B])
A
first and then try B
if A
fails: Select([A, B])
B
repeatedly while A
runs: While(A, [B])
A
, B
forever: While(WaitForever, [A, B])
A
and B
to complete: WhenAll([A, B])
A
or B
to complete: WhenAny([A, B])
See the Behavior
enum for more information.
This library has parallel semantics for AI behavior trees. It means that multiple processes can happen at the same time and the logic can be constructed around how these processes runs or terminate.
For example, While(A, [B])
runs both A
and B
at the same time.
If either A
or B
fails, then the whole while-behavior fails.
A property of AI behavior trees with parallel semantics is that you can control termination conditions externally, as opposed to most programming languages where termination condition is controlled internally:
while A() {
// This inner loop will never terminate unless `B` fails.
while true {
B(); // Runs `B` forever.
}
}
// This will terminate if `A` stops running, which also stops `B`.
WhenAny([A,
While(WaitForever, [
B
])
])