MoonBit native behavior tree and agent decision toolkit for games, robotics, and WASM apps.
| 项目 | 状态 |
|---|---|
| 包名 | liu666789987/moonbtkit |
| 版本 | 0.1.3 |
| MoonBit 实现 | 核心功能均由 MoonBit 实现 |
| 代码规模 | 有效 MoonBit 代码超过 5000 行 |
| 测试 | 117 个测试,覆盖核心路径、错误路径、fixture、recipe、可视化、coverage、matrix、profile、audit 和白盒 helper |
| 示例 | cmd/main、examples/basic、examples/export 均可运行 |
| CI | GitHub Actions 覆盖检查、构建、测试、JS 目标、示例和包清单 |
| 许可证 | Apache-2.0 |
moon add liu666789987/moonbtkitimport {
"liu666789987/moonbtkit",
}let source =
"root root\n" +
"blackboard enemy_visible true\n" +
"blackboard ammo 2\n" +
"selector root engage patrol\n" +
"sequence engage see_enemy has_ammo aim fire\n" +
"condition see_enemy enemy_visible eq true\n" +
"condition has_ammo ammo gt 0\n" +
"action aim aim_weapon running,success mode=aiming\n" +
"action fire fire_weapon success ammo=1 result=hit\n" +
"action patrol patrol_area success mode=patrol\n"
match @moonbtkit.parse_dsl(source) {
Ok(doc) => {
let engine = @moonbtkit.new_engine(doc.tree, blackboard=doc.blackboard)
match engine.run_until_done(max_ticks=6) {
Ok(result) => println(result.summary())
Err(err) => println(err.message())
}
}
Err(err) => println(err.message())
}moon run cmd/main
moon run examples/basic
moon run examples/export| 分类 | API |
|---|---|
| 黑板 | new_blackboard, blackboard_from_pairs, Blackboard::set, Blackboard::get_* |
| 节点 | node, sequence, selector, condition, set_value, wait, action_success |
| 树 | new_tree, tree_from_nodes, BehaviorTree::add, BehaviorTree::validate |
| 引擎 | new_engine, BtEngine::tick, BtEngine::run_until_done, BtEngine::trace_digest |
| DSL | parse_dsl, parse_tree_dsl, serialize_tree, parse_blackboard_dsl |
| 分析 | analyze_tree, lint_tree, tree_markdown_report, smoke_run |
| 测试 | run_case, run_cases, fixture_cases, recipe_cases, assert_* |
| 示例 | fixture_catalog, run_fixture, recipe_catalog, run_recipe_catalog |
| Timeline | timeline_from_trace, timeline_text, summarize_trace, compact_trace |
| Visualization | tree_to_dot, tree_to_mermaid, trace_to_mermaid_sequence, visualization_bundle |
| Coverage | coverage_from_trace, fixture_coverage, fixture_catalog_coverage |
| Matrix | run_matrix, boolean_matrix, int_sweep_matrix, fixture_matrix_report |
| Profile | profile_trace, profile_fixture, fixture_profile_report, profile_markdown |
| Audit | audit_fixture, audit_fixture_catalog, audit_catalog_markdown |
moon check
moon build
moon test
moon check --target js
moon build --target js
moon test --target js
moon run cmd/main
moon run examples/basic
moon run examples/export
moon package --listpub(all) struct AuditReport {
name : String
run : RunSummary
coverage : TraceCoverage
profile : ProfileReport
lint : LintReport
visual_assets : Int
} derive(Eq, Debug)pub(all) struct BtEngine {
tree : BehaviorTree
blackboard : Blackboard
config : TickConfig
tick_count : Int
memory : Array[NodeMemory]
trace : Array[TickEvent]
} derive(Eq, Debug)pub(all) struct CaseReport {
name : String
parsed : Bool
run : RunSummary
assertions : AssertionReport
} derive(Eq, Debug)pub(all) struct CaseSpec {
name : String
dsl : String
expectation : CaseExpectation
} derive(Eq, Debug)pub(all) struct DslDocument {
tree : BehaviorTree
blackboard : Blackboard
warnings : Array[String]
} derive(Eq, Debug)pub(all) struct ProfileReport {
name : String
profiles : Array[NodeProfile]
total_events : Int
total_ticks : Int
} derive(Eq, Debug)pub(all) struct RecipeBundle {
name : String
description : String
tree : BehaviorTree
blackboard : Blackboard
expected : BtStatus
max_ticks : Int
} derive(Eq, Debug)fn TreeBuilder::action(self : TreeBuilder, id : String, name : String, statuses : Array[BtStatus], writes? : Array[(String, BtValue)]) -> Result[TreeBuilder, BtError]fn TreeBuilder::condition(self : TreeBuilder, id : String, key : String, op : CompareOp, expected : BtValue) -> Result[TreeBuilder, BtError]fn TreeBuilder::decorator(self : TreeBuilder, id : String, kind : NodeKind, child : String) -> Result[TreeBuilder, BtError]fn TreeBuilder::emit(self : TreeBuilder, id : String, label : String) -> Result[TreeBuilder, BtError]fn TreeBuilder::parallel_all(self : TreeBuilder, id : String, children : Array[String]) -> Result[TreeBuilder, BtError]fn TreeBuilder::parallel_any(self : TreeBuilder, id : String, children : Array[String]) -> Result[TreeBuilder, BtError]fn TreeBuilder::selector(self : TreeBuilder, id : String, children : Array[String]) -> Result[TreeBuilder, BtError]fn TreeBuilder::sequence(self : TreeBuilder, id : String, children : Array[String]) -> Result[TreeBuilder, BtError]fn TreeBuilder::set(self : TreeBuilder, id : String, key : String, value : BtValue) -> Result[TreeBuilder, BtError]fn assert_board_value(board : Array[(String, BtValue)], key : String, value : BtValue) -> BtAssertionfn boolean_matrix(name : String, source : String, key : String, true_expected : BtStatus, false_expected : BtStatus, max_ticks? : Int) -> MatrixReportfn int_sweep_matrix(name : String, source : String, key : String, values : Array[Int], expected : BtStatus, max_ticks? : Int) -> MatrixReportfn smoke_run(name : String, tree : BehaviorTree, board : Blackboard, expected : BtStatus, max_ticks? : Int) -> RunSummaryfn variant(name : String, overrides : Array[(String, BtValue)], expected? : BtStatus, max_ticks? : Int) -> VariantSpecMoonBit native behavior tree and agent decision toolkit for games, robotics, and WASM apps.