public void Restart()
    {
        // Init BB

        m_Blackboard = new Blackboard();
        m_Blackboard.Trans = transform;
        m_Blackboard.Player = GameObject.FindGameObjectWithTag("Player").transform;
        m_Blackboard.Destination = transform.position + new Vector3(10, 0, 5);

        m_Bt = new BehaviorTree();
        m_Bt.m_Blackboard = m_Blackboard;

        // Init tree
        Repeat repeat = new Repeat(ref m_Bt, -1);
        Sequence randomMove = new Sequence(ref m_Bt);
        PickRandomTarget pickTarget = new PickRandomTarget();
        MoveToPoint moveBehavior = new MoveToPoint();

        randomMove.m_Children.Add(moveBehavior);
        randomMove.m_Children.Add(pickTarget);

        // Try out Chase behavior
        m_Chase = new Chase(moveBehavior, m_Bt);
        m_Flee = new Flee(moveBehavior, m_Bt);

        repeat.m_Child = randomMove;

        m_Bt.Start(repeat, this.SequenceComplete);
    }
Example #2
0
        protected override Status Update(Blackboard blackboard)
        {
            // Check if any child up to our current child can execute
            // if so, it becomes our new current child
            for (int i = 0; i < currentChild; i++) {
                var child = Children[i];
                var status = child.Tick(blackboard);
                if (status != Status.Failure) {
                    // Reset the previous child
                    Children[currentChild].Reset();
                    currentChild = i;
                    return status;
                }
            }

            // Otherwise execute children in order until we
            // reach the end or one succeeds
            while (currentChild < Children.Count) {
                var status = Children[currentChild].Tick(blackboard);

                if (status != Status.Failure)
                    return status;

                currentChild ++;
            }

            return Status.Failure;
        }
Example #3
0
File: Parallel.cs Project: fry/refw
        protected override Status Update(Blackboard blackboard)
        {
            var success_count = 0;
            var failure_count = 0;

            // Tick all children that haven't succeeded yet
            foreach (var child in Children) {
                var status = child.IsFinished ? child.Status : child.Tick(blackboard);
                if (status == Status.Success) {
                    success_count ++;
                    if (SuccessPolicy == Policy.One)
                        return Status.Success;
                } else if (status == Status.Failure) {
                    failure_count ++;
                    if (FailurePolicy == Policy.One)
                        return Status.Failure;
                }
            }

            // Succeed/Fail depending on Policy.All
            if (FailurePolicy == Policy.All && failure_count == Children.Count)
                return Status.Failure;

            if (SuccessPolicy == Policy.All && success_count == Children.Count)
                return Status.Success;

            return Status.Running;
        }
Example #4
0
 protected override void OnEnter( Actor actor, Blackboard local )
 {
     if ( m_subtree == null )
     {
         m_subtree = BehaviorCache.GetBehavior( m_id );
     }
 }
    public override NeuTreeCB Run(IBlackBoard _blackboard)
    {
        blackboard = new Blackboard ();

        NeuTreeCB answer = new NeuTreeCB();
        answer.blackboard = blackboard;
        blackboard.Project(_blackboard);
        NeuTreeCB lowerAnswer = new NeuTreeCB ();
        for (int i = 0; i < lowerNodes.Count; i++) {
            lowerAnswer = lowerNodes[i].Run(blackboard);
            float fv = lowerAnswer.fireVal;
            if(lowerAnswer.replyFire == ReplyFire.Fail){
                answer.replyFire = ReplyFire.Fail;
                return answer;
            }
            else{
        //				for (int p = 0; p < lowerAnswer.blackboard.baseElementsPriority.Length; p++) {
        //					Debug.Log("before Lower AND Pririty "+lowerAnswer.blackboard.baseElementsPriority[p]);
        //				}
        //				for (int p = 0; p < blackboard.baseElementsPriority.Length; p++) {
        //					Debug.Log("before AND Pririty "+blackboard.baseElementsPriority[p]);
        //				}
                blackboard.Blend(lowerAnswer.blackboard, 1.0f);
        //				for (int p = 0; p < blackboard.baseElementsPriority.Length; p++) {
        //					Debug.Log("AND Pririty "+blackboard.baseElementsPriority[p]);
        //				}
            }
        }
        answer.replyFire = ReplyFire.Success;
        //		Debug.Log ("AND operator answer "+answer.replyFire);
        return answer;
    }
Example #6
0
 public CreatureAI(Creature creature,
     string name,
     EnemySensor sensor,
     PlanService planService)
     : base(name, creature.Physics)
 {
     Movement = new CreatureMovement();
     GatherManager = new GatherManager(this);
     Blackboard = new Blackboard();
     Creature = creature;
     CurrentPath = null;
     DrawPath = false;
     PlannerTimer = new Timer(0.1f, false);
     LocalControlTimeout = new Timer(5, false);
     WanderTimer = new Timer(1, false);
     Creature.Faction.Minions.Add(this);
     DrawAIPlan = false;
     WaitingOnResponse = false;
     PlanSubscriber = new PlanSubscriber(planService);
     ServiceTimeout = new Timer(2, false);
     Sensor = sensor;
     Sensor.OnEnemySensed += Sensor_OnEnemySensed;
     Sensor.Creature = this;
     CurrentTask = null;
     Tasks = new List<Task>();
     Thoughts = new List<Thought>();
     IdleTimer = new Timer(15.0f, true);
     SpeakTimer = new Timer(5.0f, true);
     XPEvents = new List<int>();
 }
Example #7
0
 public override Common.NodeExecuteState Execute(Blackboard blackboard)
 {
     if (Check(blackboard))
         return Common.NodeExecuteState.kSuccess;
     else
         return Common.NodeExecuteState.kFailure;
 }
Example #8
0
        protected override BehaviorTree.ResultCode OnAct( Actor actor, Blackboard local )
        {
            int executing = 0;
            
            if ( !local.GetValue< int >( INDEX_FIELD_NAME, out executing ) )
            {
                return BehaviorTree.ResultCode.Error;
            }

            if ( Children.Count <= executing )
            {
                return BehaviorTree.ResultCode.Error;
            }

            BehaviorTree.ResultCode result = BehaviorTree.ResultCode.Failure;

            while ( result == BehaviorTree.ResultCode.Failure && executing < Children.Count )
            {
                result = Children[ executing ].Act( actor );

                if ( result == BehaviorTree.ResultCode.Failure )
                {
                    executing++;
                    local.SetValue<int>( INDEX_FIELD_NAME, executing );
                }
            }

            return result;
        }
Example #9
0
 protected override void CustomStart()
 {
     animator = GetComponent<Animator>();
     energyPointPrefab = Resources.Load<GameObject>("Prefabs/EnergyDrop");
     blackBoard = new Blackboard(this.gameObject);
     EnemyStart();
 }
Example #10
0
 // Use this for initialization
 void Start()
 {
     blackBoard = new Blackboard(this.gameObject);
     Node root = new Priority(
         new Node[]
         {
             new Sequence(
                 new Node[]
                 {
                     new ButtonPressed("X"),
                     new MemSequence(
                         new Node[]
                         {
                             new ChangeColor(Color.blue),
                             new Wait(1.0f),
                             new ChangePosition(Vector3.zero, Vector3.one*10.0f)
                            // new ChangeColor(Color.red)
                         }
                     )
                 }
             ),
             new ChangeColor(Color.red)
         }
     );
     behaviourTree = new BehaviourTree.Tree(root);
 }
Example #11
0
File: Set.cs Project: fry/refw
 protected override Status Update(Blackboard blackboard)
 {
     if (Func != null)
         blackboard.Set(Destination, Func());
     else
         blackboard.Set(Destination, FuncBlackboard(blackboard));
     return Status.Success;
 }
Example #12
0
 protected override Status Update(Blackboard blackboard)
 {
     if (Predicate.GetValue(blackboard)) {
         if (Child != null)
             return Child.Tick(blackboard);
         return Status.Success;
     }
     return Status.Failure;
 }
Example #13
0
 public void BoolTest()
 {
     string code = "(And True False)";
     LispCompiler<Blackboard> lispCompiler = new LispCompiler<Blackboard>();
     Blackboard blackboard = new Blackboard();
     LispOperator<Blackboard> func = lispCompiler.Compile(blackboard, code);
     Debug.WriteLine(func.BuildParseTree().ToCode());
     Debug.WriteLine(func.TryEvaluateToBool());
 }
Example #14
0
 public void Test()
 {
     string code = "(+ 7 10 (* 2 8))";
     LispCompiler<Blackboard> lispCompiler = new LispCompiler<Blackboard>();
     Blackboard blackboard = new Blackboard();
     LispOperator<Blackboard> func = lispCompiler.Compile(blackboard, code);
     Debug.WriteLine(func.BuildParseTree().ToCode());
     Debug.WriteLine(func.TryEvaluateToFloat());
 }
Example #15
0
 public void Test(string code, float extected)
 {
     LispCompiler<Blackboard> lispCompiler = new LispCompiler<Blackboard>();
     Blackboard blackboard = new Blackboard();
     LispOperator<Blackboard> func = lispCompiler.Compile(blackboard, code);
     float result = func.TryEvaluateToFloat();
     Debug.WriteLine(func.BuildParseTree().ToCode() + " => " + result);
     result.Should().Be(extected);
 }
Example #16
0
File: IsSet.cs Project: fry/refw
 protected override Status Update(Blackboard blackboard)
 {
     if (blackboard.Contains(Source) && blackboard.Get<object>(Source) != null) {
         if (Child != null)
             return Child.Tick(blackboard);
         return Status.Success;
     }
     return Status.Failure;
 }
Example #17
0
        protected override BehaviorTree.ResultCode OnAct( Actor actor, Blackboard local )
        {
            if ( m_subtree == null )
            {
                return BehaviorTree.ResultCode.Failure;
            }

            return m_subtree.Act( actor );
        }
Example #18
0
        protected override BehaviorTree.ResultCode OnAct( Actor actor, Blackboard local )
        {
            if ( m_success )
            {
                return BehaviorTree.ResultCode.Success;
            }

            return BehaviorTree.ResultCode.Failure;
        }
Example #19
0
        protected override void OnEnter( Actor actor, Blackboard local )
        {
            if ( m_random )
            {
                // Shuffle children
                Children.Sort( ( a, b ) => { return Random.Range( -1, 3 ); } );
            }

            local.SetValue< int >( INDEX_FIELD_NAME, 0 );
        }
Example #20
0
File: Inverter.cs Project: fry/refw
        protected override Status Update(Blackboard blackboard)
        {
            var result = Child.Tick(blackboard);

            if (result == Status.Failure)
                return Status.Success;
            else if (result == Status.Success)
                return Status.Failure;

            return result;
        }
    public override NeuTreeCB Run(IBlackBoard _blackboard)
    {
        blackboard = new Blackboard ();

        NeuTreeCB answer = new NeuTreeCB();
        answer.blackboard = blackboard;
        blackboard.Project(_blackboard);
        NeuTreeCB lowerAnswer = new NeuTreeCB ();
        blackboard.GetFunction(functionType).val += 1.0f * inputThreshold;
        answer.replyFire = ReplyFire.Success;
        return answer;
    }
Example #22
0
File: Selector.cs Project: fry/refw
        protected override Status Update(Blackboard blackboard)
        {
            while (true) {
                var status = CurrentChild.Current.Tick(blackboard);

                if (status != Status.Failure)
                    return status;

                if (!CurrentChild.MoveNext())
                    return Status.Failure;
            }
        }
Example #23
0
    void Awake()
    {
        string cleanedDate = "Conversation_" + MiscUtils.GetCleanFilename (System.DateTime.Today.ToString()).Split ('_')[0];
            int counter = 0;
        do
        {
            filename = cleanedDate + "_" + counter + ".txt";
            counter++;
        }
        while ( File.Exists( filename ) );

        playerBoard = GameObject.Find("Blackboard Player").GetComponent<Blackboard>();
        socratesBoard = MiscUtils.GetComponentSafely<Blackboard>("Blackboard Socrates");
    }
    public Status Tick(ref Blackboard bb)
    {
        if (m_Status == Status.BH_INVALID) {
            OnInitialize();
        }

        m_Status = Update(ref bb);

        if (m_Status != Status.BH_RUNNING)
        {
            OnTerminate(m_Status);
        }

        return m_Status;
    }
        /// <summary>
        /// Loads a set of shared variables from an XmlDocument
        /// </summary>
        /// <param name="doc">The XML document which contains the shared variable set</param>
        /// <param name="blackboard">The blackboard in which shared variables will be loaded</param>
        public void FromDocument(XmlDocument doc, Blackboard blackboard)
        {
            if (blackboard == null)
                throw new ArgumentNullException("blackboard");
            if (doc == null)
                throw new ArgumentNullException("doc");

            // First extract structures
            LoadStructures(doc);
            // Check all field types are known
            if(!ValidateNames())
                throw new ArgumentException("Unknown types defined");
            LoadVariables(doc);
            //blackboard.VirtualModule.SharedVariables.Add();
        }
    public override Status Update(ref Blackboard bb)
    {
        int xDist = Random.Range(-15, 15);
        int zDist = Random.Range(-15, 15);

        Vector3 newLocation = new Vector3(xDist, bb.Trans.position.y, zDist);

        if ((newLocation - bb.Trans.position).sqrMagnitude >= 8) {
            bb.Destination = newLocation;
            Debug.Log("PickRandomPoint found new point");
            return Status.BH_SUCCESS;
        }

        Debug.Log("PickRandomPoint failed to find point");
        return Status.BH_RUNNING;
    }
    public override Status Update(ref Blackboard bb)
    {
        int xDist = Random.Range(-12, 12);
        int yDist = Random.Range(-12, 12);

        Vector3 newLocation = new Vector3(xDist + bb.StartPoint.x, yDist + bb.StartPoint.y, bb.Trans.position.z);

        if ((newLocation - bb.Trans.position).sqrMagnitude >= 5) {
            //Debug.Log("PickRandomPoint found new point");

            bb.SetDestinationAndPath(newLocation);
            return Status.BH_SUCCESS;
        }

        //Debug.Log("PickRandomPoint failed to find point");
        return Status.BH_RUNNING;
    }
    public override Status Update(ref Blackboard bb)
    {
        Vector3 toMe = bb.Trans.position - bb.Player.position;
        toMe.z = 0;

        if (toMe.sqrMagnitude >= 70.0f)
        {
            // don't actually return, just stop running
            return Status.BH_RUNNING;
            //return Status.BH_SUCCESS;
        }

        toMe.Normalize();
        toMe *= 2.5f;
        bb.Destination = toMe + bb.Trans.position;

        return Status.BH_RUNNING;
    }
    public override Status Update(ref Blackboard bb)
    {
        int xDist = Random.Range(-10, 10);
        int zDist = Random.Range(-10, 10);

        Vector3 newLocation = new Vector3(xDist, bb.Trans.position.y, zDist);

        if ((newLocation - bb.Trans.position).sqrMagnitude >= 8) {
            Debug.Log("PickRandomPoint found new point");

            bb.Destination = newLocation;
            bb.MovementPath = NavGraphConstructor.Instance.FindPathToLocation(bb.Trans.position, newLocation);
            bb.PathCurrentIdx = 0;
            return Status.BH_SUCCESS;
        }

        Debug.Log("PickRandomPoint failed to find point");
        return Status.BH_RUNNING;
    }
    public override NeuTreeCB Run(IBlackBoard _blackboard)
    {
        blackboard = new Blackboard ();

        NeuTreeCB answer = new NeuTreeCB();
        answer.blackboard = blackboard;
        blackboard.Project(_blackboard);
        NeuTreeCB lowerAnswer = new NeuTreeCB ();

        float nomDist = Mathf.ClosestPowerOfTwo(blackboard.subject.elProperties[PropertyType.Range].val);
        bool success = false;
        float thresholld = 0.01f;
        if (upperNode != null)
            thresholld = upperNode.inputThreshold;

        Debug.Log ("Checking distance of " + blackboard.functionStimuls[FunctionType.Movement].Keys.Count);
        List <int> el = new List<int> (blackboard.functionStimuls[FunctionType.Movement].Keys);

        for (int i = 0; i < el.Count; i++) {
            float dist  = Vector3.Magnitude(ElementsManager.gameElements[el[i]].transform.position - blackboard.subject.transform.position) / nomDist;

            Debug.Log("element id "+el[i]+" didtance to element "+dist+" threshold value "+thresholld);

            if(dist <= thresholld){
                blackboard.functionStimuls[FunctionType.Movement][el[i]] = 1 - dist;
                success = true;
            }
        }

        //		for (int p = 0; p < blackboard.baseElementsPriority.Length; p++) {
        //			Debug.Log("Distance Pririty "+blackboard.baseElementsPriority[p]);
        //		}

        if(!success){
            answer.replyFire = ReplyFire.Fail;
        }
        else{
            answer.replyFire = ReplyFire.Success;
        }
        //		Debug.Log ("Diastance filter answer "+answer.replyFire);
        return answer;
    }
    protected Node MonitorCheckNotSeeAcquaintance(Blackboard blackboard)
    {
        Func <bool> notSeeEachOther = () => (!checkSee(heroAgent, speaker));

        return(new DecoratorForceStatus(RunStatus.Success, new Sequence(new LeafAssert(notSeeEachOther), SetNotSeeAcquaintance(blackboard))));
    }
    protected Node checkMeetAcquaintance(Blackboard blackboard)
    {
        Func <bool> meetAcquaintance = () => (blackboard.meetAcquaintance == true);

        return(new DecoratorForceStatus(RunStatus.Success, new Sequence(new LeafAssert(meetAcquaintance), SetMeetAcquaintance(blackboard))));
    }
Example #33
0
 public Task(Blackboard blackboard)
 {
     this._blackboard = blackboard;
 }
    protected Node checkReportSuccess(Blackboard blackboard)
    {
        Func <bool> reportSuccess = () => (blackboard.ReportedSuccess == 2 && blackboard.fighterEscaped == false);

        return(new DecoratorForceStatus(RunStatus.Success, new Sequence(new LeafAssert(reportSuccess), SetReportSuccess(blackboard))));
    }
    protected Node selectNotReportYet(Blackboard blackboard)
    {
        Func <bool> NotReportYet = () => (blackboard.currentArc == (int)CurrentArc.none);

        return(new SelectorParallel(new DecoratorInvert(new DecoratorLoop(new LeafAssert(NotReportYet))), ST_Yawn(policeman)));
    }
    protected Node selectReportPolice(Blackboard blackboard)
    {
        Func <bool> act = () => (blackboard.currentArc == (int)CurrentArc.seeThePolice);

        return(new SelectorParallel(new DecoratorInvert(new DecoratorLoop(new LeafAssert(act))), randomResPonse(blackboard)));
    }
 protected Node SetSeeAcquaintance(Blackboard blackboard)
 {
     return(new LeafInvoke(
                () => (blackboard.meetAcquaintance = true)
                ));
 }
 protected Node SetUnckeckArc(Blackboard blackboard)
 {
     return(new LeafInvoke(
                () => (blackboard.currentArc = (int)CurrentArc.none)
                ));
 }
    protected Node checkReportPolice(Blackboard blackboard)
    {
        Func <bool> act2 = () => (blackboard.seePolice == true && blackboard.ReportedSuccess == 0);

        return(new DecoratorForceStatus(RunStatus.Success, new Sequence(new LeafAssert(act2), SetArc(blackboard))));
    }
 protected Node SetReportSuccess(Blackboard blackboard)
 {
     return(new LeafInvoke(
                () => (blackboard.currentArc = (int)CurrentArc.ReportConfirmed)
                ));
 }
 protected Node SetHasNoClues(Blackboard blackboard)
 {
     return(new LeafInvoke(
                () => (blackboard.currentArc = (int)CurrentArc.hasNoClues)
                ));
 }
Example #42
0
 public override void Tick()
 {
     base.Tick();
     Move = Blackboard.GetData <BTInputMoveData>().Value;
 }
Example #43
0
 protected override void UpdateBlackboard(Blackboard context)
 {
     base.UpdateBlackboard(context);
     context.GetState <TargetEntityState>().SetValue(Target);
 }
 protected Node SetSeeFighter(Blackboard blackboard)
 {
     return(new LeafInvoke(
                () => (blackboard.seeFighter = true)
                ));
 }
 protected Node SetNotSeePolice(Blackboard blackboard)
 {
     return(new LeafInvoke(
                () => (blackboard.seePolice = false)
                ));
 }
 protected Node SetSeekTheFighter(Blackboard blackboard)
 {
     return(new LeafInvoke(
                () => (blackboard.currentArc = (int)CurrentArc.seekFighter)
                ));
 }
    protected Node checkSeeFighter(Blackboard blackboard)
    {
        Func <bool> seeFighter = () => (blackboard.seeFighter == true && blackboard.fighterEscaped == false);

        return(new DecoratorForceStatus(RunStatus.Success, new Sequence(new LeafAssert(seeFighter), SetSeeTheFighter(blackboard))));
    }
Example #48
0
        public WfcGraphSpace(Model.Graph graph, List <WfcGraphTile <TTileData> > availableModules, Blackboard blackboard,
                             string wfcComponentName     = "WfcComponent",
                             string wfcCellPropertyName  = "WfcCell",
                             string wfcNeighborLayerName = "WfcNeighborLayer")
            : base(blackboard)
        {
            _graph                = graph;
            _wfcComponentName     = wfcComponentName;
            _wfcCellPropertyName  = wfcCellPropertyName;
            _wfcNeighborLayerName = wfcNeighborLayerName;

            InitializeEntities(availableModules);
        }
 protected override bool Check(Blackboard blackboard) => blackboard.target != null &&
 Vector3.Distance(blackboard.treeTicker.transform.position,
                  blackboard.target.position) < range;
 protected override void Initialise(Blackboard blackboard)
 {
 }
    protected Node uncheckReportPolice(Blackboard blackboard)
    {
        Func <bool> notSeePolice = () => ((blackboard.seePolice == false && blackboard.ReportedSuccess == 0) && blackboard.meetAcquaintance == false);

        return(new DecoratorForceStatus(RunStatus.Success, new Sequence(new LeafAssert(notSeePolice), SetUnckeckArc(blackboard))));
    }
    protected Node checkFindFighter(Blackboard blackboard)
    {
        Func <bool> findFighter = () => (blackboard.seeFighter == true && blackboard.ReportedSuccess == 2 && blackboard.fighterEscaped == true);

        return(new DecoratorForceStatus(RunStatus.Success, new Sequence(new LeafAssert(findFighter), SetFindTheFighter(blackboard))));
    }
Example #53
0
 public BehaviorTree(Task rootTask, Blackboard blackboard)
 {
     root        = rootTask;
     pBlackboard = blackboard;
 }
 protected Node SetArc(Blackboard blackboard)
 {
     return(new LeafInvoke(
                () => (blackboard.currentArc = (int)CurrentArc.seeThePolice)
                ));
 }
 protected override void Terminate(Blackboard blackboard)
 {
 }
    protected Node MonitorCheckSecondSeePoliceman(Blackboard blackboard)
    {
        Func <bool> seeEachOther = () => (checkSee(heroAgent, policeman) && blackboard.hasArrived == true);

        return(new DecoratorForceStatus(RunStatus.Success, new Sequence(new LeafAssert(seeEachOther), SetSecondSeePoliceman(blackboard))));
    }
Example #57
0
 protected override void Awake()
 {
     _blackboard       = GetComponent <Blackboard>();
     _hitboxController = GetComponent <NPCHitBoxController>();
     base.Awake();
 }
    protected Node MonitorCheckSeeFighter(Blackboard blackboard)
    {
        Func <bool> seeEachOther = () => (checkSee(heroAgent, fighter));

        return(new DecoratorForceStatus(RunStatus.Success, new Sequence(new LeafAssert(seeEachOther), SetSeeFighter(blackboard))));
    }
 protected Node InteractiveBehaviorTree(Blackboard blackboard)
 {
     return(new SequenceParallel(Story(blackboard), MonitorUserInput(blackboard), MonitorStoryState(blackboard)));
 }
 protected Node SetMeetAcquaintance(Blackboard blackboard)
 {
     return(new LeafInvoke(
                () => (blackboard.currentArc = (int)CurrentArc.greetAcquaintance)
                ));
 }