Not a Go veteran, but I implememted a behavior tree in a little simulation game prototype. Looked very similar structurally but your version is nicer.
As an aside:
I don’t particularly like behavior trees. Not sure why, but they feel brute-force-y to me, and I find them much harder to reason about than state machines. Once you express state machines as data, they can become just as powerful and feel less fiddly.
A different thought I have that I couldn’t get around exploring is to implement behavior trees with channels (no go routines). But that’s just a vague notion.
There was a article from Russ Cox „Storing Data in Control Flow“. Maybe there‘s something there?
jenniferhooley 44 minutes ago [-]
Yeah, I agree with you. My experience has been very similar, when the actual game logic gets complex, BT's become a bit of a maintenance nightmare, making it super hard to reason about the system flow.
I ultimately landed on a flag-driven, hierarchical state machine. Instead of implementing a full tree traversal, which requires complex flow control nodes, I use bit flags to define my system's entire set of rulesets or invariants.
A state doesn't need to ask "what do I do next?" but rather "are my activation conditions met?" These conditions are defined as bitwise flags evaluated through standard bit-masking operations (AND, OR, XOR, etc.). For example, a state might only become active if flags IN_RANGE & GOAL_IS_NPC & PATH_BLOCKED. The flags allow me to mathematically encode complex prerequisite combinations as simple integer comparisons.
I found this approach makes the transition logic nice and clean. It shifts the burden from managing the flow (which is complex) to managing the data state (which is simple and deterministic). The system still feels like a full BT - it has hierarchy and sequential logic - but the decision process is purely data-driven, which makes it really easy to reason about even when there's a many of layers of complexity for each state/substate.
emanuele-em 3 hours ago [-]
The clock injection for testing temporal nodes is a really nice touch. Most BT libraries force you to actually wait or mock everything yourself. This would work well for orchestrating retries and fallback logic in microservices, not just game AI. Any plans for parallel composite nodes?
redoh 2 hours ago [-]
[dead]
Rendered at 18:33:51 GMT+0000 (Coordinated Universal Time) with Vercel.
As an aside:
I don’t particularly like behavior trees. Not sure why, but they feel brute-force-y to me, and I find them much harder to reason about than state machines. Once you express state machines as data, they can become just as powerful and feel less fiddly.
A different thought I have that I couldn’t get around exploring is to implement behavior trees with channels (no go routines). But that’s just a vague notion.
There was a article from Russ Cox „Storing Data in Control Flow“. Maybe there‘s something there?
I ultimately landed on a flag-driven, hierarchical state machine. Instead of implementing a full tree traversal, which requires complex flow control nodes, I use bit flags to define my system's entire set of rulesets or invariants.
A state doesn't need to ask "what do I do next?" but rather "are my activation conditions met?" These conditions are defined as bitwise flags evaluated through standard bit-masking operations (AND, OR, XOR, etc.). For example, a state might only become active if flags IN_RANGE & GOAL_IS_NPC & PATH_BLOCKED. The flags allow me to mathematically encode complex prerequisite combinations as simple integer comparisons.
I found this approach makes the transition logic nice and clean. It shifts the burden from managing the flow (which is complex) to managing the data state (which is simple and deterministic). The system still feels like a full BT - it has hierarchy and sequential logic - but the decision process is purely data-driven, which makes it really easy to reason about even when there's a many of layers of complexity for each state/substate.