コード例 #1
0
ファイル: AntAICondition.cs プロジェクト: BantamJoe/GOAP-1
        public bool Has(AntAIPlanner aPlanner, string aAtomName)
        {
            int index = aPlanner.GetAtomIndex(aAtomName);

            return((index >= 0 && index < values.Length)
                                ? values[index]
                                : false);
        }
コード例 #2
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]);
            }
        }
コード例 #3
0
 public bool Set(AntAIPlanner aPlanner, string aAtomName, bool aValue)
 {
     return(Set(aPlanner.GetAtomIndex(aAtomName), aValue));
 }
コード例 #4
0
ファイル: AntAICondition.cs プロジェクト: BantamJoe/GOAP-1
 public void EndUpdate()
 {
     _currentPlanner = null;
 }
コード例 #5
0
ファイル: AntAICondition.cs プロジェクト: BantamJoe/GOAP-1
 public void BeginUpdate(AntAIPlanner aPlanner)
 {
     _currentPlanner = aPlanner;
 }
コード例 #6
0
 /// <summary>
 /// Extracts condition index by condition name.
 /// </summary>
 /// <param name="aPlanner">Reference to the planner.</param>
 /// <param name="aAtomName">Name of the condition</param>
 /// <returns>Index of the condition.</returns>
 public int GetValue(AntAIPlanner aPlanner, string aAtomName)
 {
     return(aPlanner.GetAtomIndex(aAtomName));
 }
コード例 #7
0
 /// <summary>
 /// Ends updating of the condition.
 /// </summary>
 public void EndUpdate()
 {
     _planner = null;
 }
コード例 #8
0
 /// <summary>
 /// Begins updating of the condition.
 /// Useful to use when you want change many conditions in the same time.
 /// </summary>
 /// <param name="aPlanner">Ref to the AIPlanner.</param>
 public void BeginUpdate(AntAIPlanner aPlanner)
 {
     _planner = aPlanner;
 }