meniku / NPBehave

Event Driven Behavior Trees for Unity 3D
MIT License
1.15k stars 195 forks source link

Added Randomized Selector and Sequence #18

Closed Wokarol closed 5 years ago

Wokarol commented 5 years ago

Added Randomized Selector and Randomized Sequence. Randomized Sequence runs children in random order until one until one fails and fail (succeeds if non of the children fails). Randomized Selector runs children in random order until one succeeds and succeed (succeeds if one of the children succeeds).

Selector is not biased and picks totally random order RandomDistributionBetter

While the previous method of using Random decorator on each child chooses 1st option more often RandomDistribution

Wokarol commented 5 years ago

It also doesn't produce garbage and isn't expensive

meniku commented 5 years ago

Thanks a lot, those look handy indeed. I'll be able to integrate it in about 10 days

Wokarol commented 5 years ago

When I was making it I realised that some kind of Random Composite that chooses random node only once would be cool too. But I have no idea how to do it. Right know Selector + Succeeder on each child will do the trick.

meniku commented 5 years ago

I've merged it and added some tests. One thing that's a bit unclear to me right now is what should happen with the child priorities for the stops rules. Right now I kept it the original order (not the randomized one), but one could argue that the children priorities should change to the randomized order...