Ejemplo n.º 1
0
        public void TestNegativePlan1()
        {
            var planner    = GetPlanner();
            var gameObject = new GameObject();

            ReGoapTestsHelper.GetCustomAction(gameObject, "CollectRes",
                                              new Dictionary <string, object> {
            },
                                              new Dictionary <string, object> {
                { "NFloatRisk", 10f }, { "IntGold", 10 }
            },
                                              3);
            ReGoapTestsHelper.GetCustomAction(gameObject, "ReduceRisk",
                                              new Dictionary <string, object> {
                { "IntGold", -10 }
            },
                                              new Dictionary <string, object> {
                { "NFloatRisk", -20f }, { "IntGold", -10 }
            },
                                              5);

            var goal = ReGoapTestsHelper.GetCustomGoal(gameObject, "GetGold",
                                                       new Dictionary <string, object> {
                { "NFloatRisk", 10f }
            });

            var memory = gameObject.AddComponent <ReGoapTestMemory>();

            memory.Init();
            memory.SetStructValue("NFloatRisk", StructValue.CreateFloatArithmetic(50f));
            memory.SetStructValue("IntGold", StructValue.CreateFloatArithmetic(10));

            var agent = gameObject.AddComponent <ReGoapTestAgent>();

            agent.Init();
            agent.debugPlan = true;

            var plan = planner.Plan(agent, null, null, null);

            Assert.That(plan, Is.EqualTo(goal));
            Assert.That(plan.GetPlan().Count, Is.EqualTo(5));
            // validate plan actions
            ReGoapTestsHelper.ApplyAndValidatePlan(plan, memory);
        }
Ejemplo n.º 2
0
        public void TestReGoapStateAddOperator()
        {
            var state = ReGoapState <string, object> .Instantiate();

            state.Set("var0", true);
            state.SetStructValue("var1", StructValue.CreateIntArithmetic(10));
            state.SetStructValue("var2", StructValue.CreateFloatArithmetic(100f));
            var otherState = ReGoapState <string, object> .Instantiate();

            otherState.SetStructValue("var1", StructValue.CreateIntArithmetic(20)); // 2nd one replaces the first
            otherState.SetStructValue("var2", StructValue.CreateFloatArithmetic(-20f));
            otherState.Set("var3", 10.1f);
            Assert.That(state.Count, Is.EqualTo(3));
            state.AddFromState(otherState);
            Assert.That(otherState.Count, Is.EqualTo(3));
            Assert.That(state.Count, Is.EqualTo(4));
            Assert.That(state.Get("var0"), Is.EqualTo(true));
            Assert.That(state.Get("var1"), Is.EqualTo(30));
            Assert.That(state.Get("var2"), Is.EqualTo(80f));
            Assert.That(state.Get("var3"), Is.EqualTo(10.1f));
        }
Ejemplo n.º 3
0
 private static void _AddIntoReGoapState(ReGoapState <string, object> st, string key, object v)
 {
     if (key.StartsWith("Int"))
     {
         st.SetStructValue(key, StructValue.CreateIntArithmetic((int)v));
     }
     else if (key.StartsWith("Float"))
     {
         st.SetStructValue(key, StructValue.CreateFloatArithmetic((float)v));
     }
     else if (key.StartsWith("NInt"))
     {
         st.SetStructValue(key, StructValue.CreateIntArithmetic((int)v, neg: true));
     }
     else if (key.StartsWith("NFloat"))
     {
         st.SetStructValue(key, StructValue.CreateFloatArithmetic((float)v, neg: true));
     }
     else
     {
         st.Set(key, v);
     }
 }