Exemplo n.º 1
0
        public NodeState Tick(int index, INodeBlob blob, IBlackboard blackboard)
        {
            if (blob.GetState(index) == NodeState.Running)
            {
                var childIndex = blob.FirstOrDefaultChildIndex(index, state => state == NodeState.Running);
                return(childIndex != default ? VirtualMachine.Tick(childIndex, blob, blackboard) : 0);
            }

            var weightIndex      = 0;
            var currentMaxWeight = int.MinValue;
            var maxChildIndex    = 0;

            foreach (var childIndex in blob.GetChildrenIndices(index))
            {
                var weight = Weights[weightIndex];
                if (weight > currentMaxWeight)
                {
                    maxChildIndex    = childIndex;
                    currentMaxWeight = weight;
                }

                weightIndex++;
            }

            return(VirtualMachine.Tick(maxChildIndex, blob, blackboard));
        }
Exemplo n.º 2
0
        public static NodeState Tick(int index, INodeBlob blob, IBlackboard blackboard)
        {
            if (blob.GetState(index) == NodeState.Running)
            {
                var childIndex = blob.GetChildrenIndices(index, state => state == NodeState.Running).FirstOrDefault();
                return(childIndex != default ? VirtualMachine.Tick(childIndex, blob, blackboard) : 0);
            }

            ref var data             = ref blob.GetNodeData <PrioritySelectorNode>(index);
Exemplo n.º 3
0
        public static NodeState Tick(int index, INodeBlob blob, IBlackboard blackboard)
        {
            if (blob.GetState(index) == NodeState.Running)
            {
                var childIndex = blob.GetChildrenIndices(index, state => state == NodeState.Running).FirstOrDefault();
                return(childIndex != default ? VirtualMachine.Tick(childIndex, blob, blackboard) : 0);
            }

            var     chosenIndex = 0;
            uint    maxNumber   = 0;
            ref var random      = ref blackboard.GetDataRef <BehaviorTreeRandom>().Value;
Exemplo n.º 4
0
        public static IEnumerable <NodeState> TickChildren(
            this INodeBlob blob
            , int index
            , IBlackboard bb
            , Predicate <NodeState> breakCheck
            , Predicate <NodeState> tickCheck
            )
        {
            foreach (var childIndex in blob.GetChildrenIndices(index))
            {
                var prevState    = blob.GetState(childIndex);
                var currentState = tickCheck(prevState) ? VirtualMachine.Tick(childIndex, blob, bb) : 0;
                yield return(currentState);

                if (breakCheck(currentState == 0 ? prevState : currentState))
                {
                    yield break;
                }
            }
        }
Exemplo n.º 5
0
 public static IEnumerable <int> GetChildrenIndices(this INodeBlob blob, int parentIndex, Predicate <NodeState> predicate)
 {
     return(blob.GetChildrenIndices(parentIndex).Where(childIndex => predicate(blob.GetState(childIndex))));
 }