behavior_tree 0.1.3 copy "behavior_tree: ^0.1.3" to clipboard
behavior_tree: ^0.1.3 copied to clipboard

A behavior tree implementation written in Dart. This package is designed to be used for implementing AI in games.

example/behavior_tree_example.dart

import 'package:behavior_tree/behavior_tree.dart';

bool isHungry = true;

void main() {
  // Create a sequence of tasks
  final treeRoot = Sequence(
    children: [
      Condition(() => isHungry),
      Task(goToShop),
      Task(buyFood),
      Task(goToHome),
      Task(eatFood),
    ],
  );

  // Tick the tree
  treeRoot.tick();
}

NodeStatus goToShop() {
  // Go to the shop
  return NodeStatus.success;
}

NodeStatus buyFood() {
  // Buy food
  return NodeStatus.success;
}

NodeStatus goToHome() {
  // Go home
  return NodeStatus.success;
}

NodeStatus eatFood() {
  // Eat food
  return NodeStatus.success;
}
2
likes
160
pub points
71%
popularity

Publisher

unverified uploader

A behavior tree implementation written in Dart. This package is designed to be used for implementing AI in games.

Repository (GitHub)
View/report issues
Contributing

Documentation

API reference

Funding

Consider supporting this project:

opencollective.com
github.com
patreon.com

License

MIT (license)

Dependencies

meta

More

Packages that depend on behavior_tree