Exemple #1
0
        /**
         * Tick method.
         *
         * @method tick
         * @param {Tick} tick A tick instance.
         **/
        protected override B3Status OnTick(Tick tick)
        {
            if (this._child == null)
            {
                return(B3Status.ERROR);
            }

            B3Status status = B3Status.SUCCESS;

            while (this._maxLoop < 0 || _loopTimes < this._maxLoop)
            {
                status = this._child.Execute(tick);

                if (status == B3Status.SUCCESS || status == B3Status.FAILURE)
                {
                    _loopTimes++;
                }
                else
                {
                    break;
                }
            }

            return(status);
        }
Exemple #2
0
        /**
         * This is the main method to propagate the tick signal to this node. This
         * method calls all callbacks: `enter`, `open`, `tick`, `close`, and
         * `exit`. It only opens a node if it is not already open. In the same
         * way, this method only close a node if the node  returned a status
         * different of `b3.RUNNING`.
         *
         * @method _execute
         * @param {Tick} tick A tick instance.
         * @returns {Constant} The tick state.
         * @protected
         **/
        public B3Status Execute(Tick tick)
        {
            /* ENTER */
            this.Enter(tick);

            /* OPEN */
            if (!_isOpen)
            {
                this.Open(tick);
            }

            /* TICK */
            B3Status status = this.Tick(tick);

            /* CLOSE */
            if (status != B3Status.RUNNING)
            {
                this.Close(tick);
            }

            /* EXIT */
            this.Exit(tick);

            return(status);
        }
Exemple #3
0
        /**
         * Tick method.
         *
         * @method tick
         * @param {b3.Tick} tick A tick instance.
         * @returns {Constant} A state constant.
         **/
        protected override B3Status OnTick(Tick tick)
        {
            for (var i = 0; i < this._children.Count; i++)
            {
                B3Status status = this._children[i].Execute(tick);

                if (status != B3Status.SUCCESS)
                {
                    return(status);
                }
            }
            return(B3Status.SUCCESS);
        }
Exemple #4
0
        /**
         * Tick method.
         *
         * @method tick
         * @param {b3.Tick} tick A tick instance.
         * @returns {Constant} A state constant.
         **/
        protected override B3Status OnTick(Tick tick)
        {
            for (var i = _runningChild; i < this._children.Count; i++)
            {
                B3Status status = this._children[i].Execute(tick);

                if (status != B3Status.SUCCESS)
                {
                    if (status == B3Status.RUNNING)
                    {
                        _runningChild = i;
                    }
                    return(status);
                }
            }

            return(B3Status.SUCCESS);
        }
Exemple #5
0
        /**
         * Tick method.
         *
         * @method tick
         * @param {Tick} tick A tick instance.
         * @returns {Constant} A state constant.
         **/
        protected override B3Status OnTick(Tick tick)
        {
            if (this._child == null)
            {
                return(B3Status.ERROR);
            }

            double currTime = LocalTime.NowMilliseconds;

            B3Status status = this._child.Execute(tick);

            if (currTime - _startTime > this._maxTime)
            {
                return(B3Status.FAILURE);
            }

            return(status);
        }
Exemple #6
0
        /**
         * Tick method.
         *
         * @method tick
         * @param {Tick} tick A tick instance.
         * @returns {Constant} A state constant.
         **/
        protected override B3Status OnTick(Tick tick)
        {
            if (this._child == null)
            {
                return(B3Status.ERROR);
            }

            if (_loopTimes < this._maxLoop)
            {
                B3Status status = this._child.Execute(tick);

                if (status == B3Status.SUCCESS || status == B3Status.FAILURE)
                {
                    _loopTimes++;
                }
                return(status);
            }

            return(B3Status.FAILURE);
        }
Exemple #7
0
        /**
         * Tick method.
         *
         * @method tick
         * @param {Tick} tick A tick instance.
         * @returns {Constant} A state constant.
         **/
        protected override B3Status OnTick(Tick tick)
        {
            if (this._child == null)
            {
                return(B3Status.ERROR);
            }

            B3Status status = this._child.Execute(tick);

            if (status == B3Status.SUCCESS)
            {
                status = B3Status.FAILURE;
            }
            else if (status == B3Status.FAILURE)
            {
                status = B3Status.SUCCESS;
            }

            return(status);
        }
Exemple #8
0
        /**
         * Propagates the tick signal through the tree, starting from the root.
         *
         * This method receives a target object of any type (Object, Array,
         * DOMElement, whatever) and a `Blackboard` instance. The target object has
         * no use at all for all Behavior3JS components, but surely is important
         * for custom nodes. The blackboard instance is used by the tree and nodes
         * to store execution variables (e.g., last node running) and is obligatory
         * to be a `Blackboard` instance (or an object with the same interface).
         *
         * Internally, this method creates a Tick object, which will store the
         * target and the blackboard objects.
         *
         * Note: BehaviorTree stores a list of open nodes from last tick, if these
         * nodes weren't called after the current tick, this method will close them
         * automatically.
         *
         * @method tick
         * @param {Object} target A target object.
         * @param {Blackboard} blackboard An instance of blackboard object.
         * @returns {Constant} The tick signal state.
         **/
        public B3Status Tick()
        {
            /* TICK NODE */
            B3Status state = this._root.Execute(_tick);

            /* CLOSE NODES FROM LAST TICK, IF NEEDED */
            //var lastOpenNodes = blackboard.get('openNodes', this.id);
            //var currOpenNodes = tick._openNodes.slice(0);

            //// does not close if it is still open in this tick
            //var start = 0;
            //for (var i=0; i<Math.min(lastOpenNodes.length, currOpenNodes.length); i++) {
            //    start = i+1;
            //    if (lastOpenNodes[i] !== currOpenNodes[i]) {
            //        break;
            //    }
            //}

            //// close the nodes
            //for (var i=lastOpenNodes.length-1; i>=start; i--) {
            //    lastOpenNodes[i]._close(tick);
            //}
            return(state);
        }