Example #1
0
        public void TestImpossiblePlanDynamicActions()
        {
            var planner = new ReGoapPlanner <string, object>(
                new ReGoapPlannerSettings {
                PlanningEarlyExit = false, UsingDynamicActions = true, MaxIterations = 100, MaxNodesToExpand = 20
            }
                );

            var gameObject = new GameObject();

            ReGoapTestsHelper.GetCustomAction(gameObject, "BuyFood",
                                              new Dictionary <string, object> {
                { "IntGold", 10 }
            },
                                              new Dictionary <string, object> {
                { "IntGold", -10 }, { "IntFood", 1 }
            },
                                              3);
            ReGoapTestsHelper.GetCustomAction(gameObject, "GoMine",
                                              new Dictionary <string, object> {
                { "IntFood", 1 }
            },
                                              new Dictionary <string, object> {
                { "IntGold", 5 }, { "IntFood", -1 }
            },
                                              5);

            ReGoapTestsHelper.GetCustomGoal(gameObject, "GetGold",
                                            new Dictionary <string, object> {
                { "IntGold", 30 }
            });

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

            memory.Init();
            memory.SetStructValue("IntGold", StructValue.CreateIntArithmetic(10));
            memory.SetStructValue("IntFood", StructValue.CreateIntArithmetic(3));

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

            agent.Init();

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

            Assert.That(plan, Is.Null);
        }
Example #2
0
        public void TestPlan3()
        {
            var planner    = GetPlanner();
            var gameObject = new GameObject();

            ReGoapTestsHelper.GetCustomAction(gameObject, "BuyFood",
                                              new Dictionary <string, object> {
                { "IntGold", 5 }
            },
                                              new Dictionary <string, object> {
                { "IntGold", -5 }, { "IntFood", 2 }
            },
                                              3);
            ReGoapTestsHelper.GetCustomAction(gameObject, "GoMine",
                                              new Dictionary <string, object> {
                { "IntFood", 2 }
            },
                                              new Dictionary <string, object> {
                { "IntFood", -2 }, { "IntGold", 20 }
            },
                                              5);

            var miningGoal = ReGoapTestsHelper.GetCustomGoal(gameObject, "Mine",
                                                             new Dictionary <string, object> {
                { "IntGold", 40 }
            });

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

            memory.Init();
            memory.SetStructValue("IntGold", StructValue.CreateIntArithmetic(20));
            memory.SetStructValue("IntFood", StructValue.CreateIntArithmetic(20));

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

            agent.Init();

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

            Assert.That(plan, Is.EqualTo(miningGoal));
            // validate plan actions
            ReGoapTestsHelper.ApplyAndValidatePlan(plan, memory);
        }
Example #3
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));
        }
Example #4
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);
     }
 }