ai-behavior-trees-utility-ai
Skill này làm gì
Skill này xây dựng code cho hai kiểu hệ thống ra quyết định AI trong game: behavior tree và chấm điểm utility. Nó dành cho nhà phát triển game muốn kẻ thù hoặc nhân vật có lựa chọn có cấu trúc và đáng tin.
Khi nào nên dùng
- ✓Khi bạn muốn xây dựng một behavior tree dùng lại được cho kẻ thù hoặc nhân vật không do người chơi điều khiển.
- ✓Khi bạn cần nhân vật cân nhắc nhiều lựa chọn và chọn ra cái tốt nhất vào thời điểm đó.
- ✓Khi bạn muốn điều chỉnh mức độ kẻ thù ưu tiên hành động này hơn hành động kia.
Liên kết skill
https://github.com/gamedev-skills/awesome-gamedev-agent-skills/blob/main/skills/disciplines/ai-behavior-trees-utility-ai/SKILL.mdSao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.
Cách dùng
Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.
Tin nhắn có sẵn để dán
Dành cho Claude Code, Codex hoặc Cursor: chạy lệnh trong thư mục dự án của bạn và skill sẽ được cài đặt.
Tải tệp SKILL.md về và thả vào thư mục skill của agent.
Ví dụ cách nhờ AI
“Tôi muốn kẻ thù dùng behavior tree để tuần tra và đuổi theo, còn dùng điểm utility để chọn đòn tấn công nào sẽ dùng.”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
Agent xây dựng blackboard để lưu dữ liệu dùng chung, các node hành động và điều kiện, cùng các node tổng hợp như sequence và selector. Nó cũng xây dựng bộ đánh giá utility chấm điểm từng hành động bằng các đường cong phản hồi, và có thể kết hợp cả hai.
Nội dung kỹ thuật (SKILL.md gốc)
Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.
Behavior Trees & Utility AI
Two complementary ways to structure NPC decision-making, plus how to combine them. A behavior tree (BT) expresses structured, prioritized, reactive logic as a tree that is "ticked" each step. Utility AI answers "how much do I want each option right now?" by scoring actions with normalized curves and picking the best. Ship believable agents by using a BT for structure and Utility AI where graded trade-offs matter.
This skill is the implementation companion to game-ai (which helps you choose between
FSM / BT / steering / pathfinding). Read game-ai to pick a model; read this to build the
runtime.
When to use
- Use to build a reusable BT runtime: a
Blackboard,Nodebase, action/condition leaves,Sequence/Selector/Parallelcomposites, and decorators (Inverter, Cooldown, Repeat). - Use to build a Utility AI decider: response curves, considerations, and an evaluator that scores and selects actions (max, softmax, or weighted-random for variety).
- Use to build hybrid AI — a BT whose leaf delegates the "which attack / which target" choice to a utility evaluator.
When not to use: to choose between FSM, BT, steering, or pathfinding, and for A*/navmesh
routing, use game-ai. For Unreal's asset-based BehaviorTree/Blackboard, BTTask/BTService
and AIController, use unreal-behavior-trees. For the navmesh agent that moves the NPC, use
unity-navmesh or the engine's navigation node.
Core workflow
- Pick the model. Structured, prioritized, interruptible behavior → BT. Continuous "score every option" decisions (targeting, needs, item choice) → Utility. Both → hybrid.
- Design the Blackboard first. One typed key/value store per agent is the shared memory that decouples nodes; leaves read/write it and never hold references to each other.
- Write leaves. Conditions return
Success/Failureimmediately; actions returnRunningacross frames until they finish. Keep leaves small and side-effect-explicit. - Compose.
Selector= OR/fallback (first non-failure wins);Sequence= AND (stop at first non-success);Parallelfor concurrent branches. Wrap with decorators for policy (invert, cooldown, repeat, force-success). - For Utility: enumerate considerations, map each raw fact through a normalized 0..1 curve, combine (weighted product with compensation, or weighted sum), then select the max — add hysteresis so agents don't flip-flop on ties.
- Tick deliberately. Tick the tree/evaluator once per decision step (often slower than
render). Preserve
Runningstate between ticks; verify by drawing the active path and the per-action scores on screen while tuning.
Architecture at a glance
A behavior tree evaluates top-down, left-to-right; each node returns a status up to its parent:
flowchart TD
Root["Selector (root)"] --> Combat["Sequence: Combat"]
Root --> Patrol["Action: Patrol"]
Combat --> See["Condition: CanSeePlayer?"]
Combat --> InRange{"Selector: Reach"}
Combat --> Attack["Action: Attack (Running)"]
InRange --> Close["Condition: InAttackRange?"]
InRange --> MoveTo["Action: MoveToPlayer (Running)"]
Utility AI is a scoring pipeline — every candidate action is scored, then one is selected:
facts (distance, health, ammo…)
│ each fact → a normalized 0..1 response curve (consideration)
▼
score(action) = weight · combine(consideration_1 … consideration_n) # product+compensation or sum
▼
select: argmax · or softmax / weighted-random for variety · + hysteresis to avoid jitter
Status is a three-value enum shared by every node — this is the contract that makes the tree composable:
public enum Status { Success, Failure, Running }
public abstract class Node
{
public abstract Status Tick(Blackboard bb, float dt);
public virtual void Reset() { } // called when a parent abandons this subtree
}
// Selector = fallback/OR: return the first child that is not Failure.
// `Current` (from Composite) remembers a Running child so the next tick resumes there.
public sealed class Selector : Composite
{
public override Status Tick(Blackboard bb, float dt)
{
for (; Current < Children.Count; Current++)
{
var s = Children[Current].Tick(bb, dt);
if (s == Status.Running) return Status.Running;
Câu hỏi thường gặp
Behavior tree khác utility AI ở điểm nào?
Behavior tree đưa ra các bước có cấu trúc và có thứ tự ưu tiên, còn utility AI chấm điểm từng lựa chọn để chọn ra cái tốt nhất.
Tôi có phải chọn một hệ thống không?
Không. Skill bao quát cách kết hợp, trong đó behavior tree gọi bộ đánh giá utility cho một số lựa chọn nhất định.
Skill này có dành cho cây tài nguyên có sẵn của Unreal không?
Không. Các cây dựa trên asset của Unreal được một skill Unreal riêng bao quát.
Chi tiết
Mô tả gốc của tác giả
Build a production behavior-tree runtime (Blackboard, action/condition leaves, sequence/selector/parallel composites, decorators) and a Utility AI system (response curves — linear, exponential, sigmoid, quadratic — considerations, and action evaluators), plus hybrid BT-drives-Utility agents. Use when implementing a reusable behavior-tree or utility-based decision system, or tuning enemy/NPC decisions beyond a simple FSM, or when the user mentions behavior tree, blackboard, decorator, selector, sequence, tick status, utility AI, response/scoring curve, or consideration. For choosing between FSM
Độ phổ biến
- Sao GitHub
- 6.6k
- Vị trí xếp hạng
- #13791
- Giấy phép
- Apache-2.0
- Cập nhật
- 28/10/2026
Bình luận
- …
Thêm skill từ kho mã này
router
6.6kGiúp agent của bạn chọn đúng skill phát triển game cho yêu cầu, dựa trên engine bạn dùng và loại công việc cần làm.
audio-design
6.6kDạy agent cách trộn âm thanh game: bus, âm lượng theo decibel, hạ nhạc khi có thoại, nhạc thích ứng và biến thể hiệu ứng âm thanh.
camera-systems
6.6kGiúp agent của bạn xây dựng camera game bám theo mượt, giữ trong phạm vi màn chơi, và xoay quanh hoặc nhìn quanh trong 3D.
create-game-assets
6.6kGiúp agent của bạn lập kế hoạch và kiểm tra một bộ hình ảnh game nhất quán, từ hướng dẫn phong cách và danh sách sprite đến quy tắc kích thước và đặt tên.
Skill tương tự
diffs
394kGiúp agent của bạn tạo một diff có thể chia sẻ về các chỉnh sửa, dưới dạng liên kết xem hoặc file ảnh, thay vì một bản tóm tắt viết tay.
coding-agent
394kGiúp agent của bạn giao một việc lập trình lớn cho Codex, Claude Code hoặc OpenCode chạy nền, rồi theo dõi tiến độ của nó.
gh-issues
394kGiúp agent của bạn tìm issue trên GitHub, chọn những issue cần xử lý và mở pull request với bản sửa, kể cả theo dõi nhận xét đánh giá.