Ejemplo n.º 1
0
        private void Start()
        {
            // 1. Create the AI planner.
            // -------------------------
            var planner = new AntAIPlanner();

            // Load scenario for planner.
            A.Assert(scenario == null, "Scenario not selected!");
            planner.LoadScenario(scenario);

            // 2. Create world state.
            // ----------------------
            var worldState = new AntAICondition();

            worldState.BeginUpdate(planner);
            worldState.Set("Is Cargo Delivered", false);
            worldState.Set("See Cargo", false);
            worldState.Set("Has Cargo", false);
            worldState.Set("See Base", false);
            worldState.Set("Near Base", false);
            worldState.EndUpdate();

            // 3. Build plan.
            // --------------
            var plan = new AntAIPlan();

            planner.MakePlan(ref plan, worldState, planner.GetDefaultGoal());

            // Output plan.
            Debug.Log("<b>Plan:</b>");
            for (int i = 0; i < plan.Count; i++)
            {
                Debug.Log((i + 1) + ". " + plan[i]);
            }

            // 4. Change world state and rebuild plan.
            // ---------------------------------------
            worldState.BeginUpdate(planner);
            worldState.Set("Has Cargo", true);
            worldState.EndUpdate();

            planner.MakePlan(ref plan, worldState, planner.FindGoal("Delivery"));

            // Output plan.
            Debug.Log("<b>Plan:</b>");
            for (int i = 0; i < plan.Count; i++)
            {
                Debug.Log((i + 1) + ". " + plan[i]);
            }
        }
Ejemplo n.º 2
0
    /// <summary>
    /// This method will be called automaticaly each time when AntAIAgent decide to update the plan.
    /// You should attach this script to the same object where is AntAIAgent.
    /// </summary>
    public void CollectConditions(AntAIAgent aAgent, AntAICondition aWorldState)
    {
        // 1. Classic setup of the World Conditions for planner.
        // -------------------------------------------------------
        // aWorldState.BeginUpdate(aAgent.planner);
        // {
        //  aWorldState.Set("Is Cargo Delivered", false);
        //  aWorldState.Set("See Cargo", IsSeeCargo());
        //  aWorldState.Set("Has Cargo", _control.HasCargo);
        //  aWorldState.Set("See Base", IsSeeBase());
        //  aWorldState.Set("Near Base", IsNearBase());
        // }
        // aWorldState.EndUpdate();

        // 2. Optimized setup of the World Conditions for the planner.
        // -----------------------------------------------------------
        aWorldState.BeginUpdate(aAgent.planner);
        {
            aWorldState.Set(DeliveryBot.IsCargoDelivered, false);
            aWorldState.Set(DeliveryBot.SeeCargo, IsSeeCargo());
            aWorldState.Set(DeliveryBot.HasCargo, _control.HasCargo);
            aWorldState.Set(DeliveryBot.SeeBase, IsSeeBase());
            aWorldState.Set(DeliveryBot.NearBase, IsNearBase());
        }
        aWorldState.EndUpdate();

        // HINT: When you have finished the AI Scenario, just export all conditions
        // as enum and use it to set conditions from the code.
    }