Esempio n. 1
0
        public void TestConflictingActionPlan()
        {
            var gameObject = new GameObject();

            ReGoapTestsHelper.GetCustomAction(gameObject, "JumpIntoWater",
                                              new Dictionary <string, object> {
                { "isAtPosition", 0 }
            },
                                              new Dictionary <string, object> {
                { "isAtPosition", 1 }, { "isSwimming", true }
            }, 1);
            ReGoapTestsHelper.GetCustomAction(gameObject, "GoSwimming",
                                              new Dictionary <string, object> {
            },
                                              new Dictionary <string, object> {
                { "isAtPosition", 0 }
            }, 2);

            var hasAxeGoal = ReGoapTestsHelper.GetCustomGoal(gameObject, "Swim",
                                                             new Dictionary <string, object> {
                { "isSwimming", true }
            });

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

            memory.Init();

            var agent = PrepareAgent(gameObject);

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

            Assert.That(plan, Is.EqualTo(hasAxeGoal));
            // validate plan actions
            ReGoapTestsHelper.ApplyAndValidatePlan(plan, agent, memory);
        }
Esempio n. 2
0
        public void TestSimpleChainedPlan()
        {
            var planner    = GetPlanner();
            var gameObject = new GameObject();

            ReGoapTestsHelper.GetCustomAction(gameObject, "CreateAxe",
                                              new Dictionary <string, object> {
                { "hasWood", true }, { "hasSteel", true }
            },
                                              new Dictionary <string, object> {
                { "hasAxe", true }, { "hasWood", false }, { "hasSteel", false }
            }, 10);
            ReGoapTestsHelper.GetCustomAction(gameObject, "ChopTree",
                                              new Dictionary <string, object> {
            },
                                              new Dictionary <string, object> {
                { "hasRawWood", true }
            }, 2);
            ReGoapTestsHelper.GetCustomAction(gameObject, "WorksWood",
                                              new Dictionary <string, object> {
                { "hasRawWood", true }
            },
                                              new Dictionary <string, object> {
                { "hasWood", true }, { "hasRawWood", false }
            }, 5);
            ReGoapTestsHelper.GetCustomAction(gameObject, "MineOre",
                                              new Dictionary <string, object> {
            },
                                              new Dictionary <string, object> {
                { "hasOre", true }
            }, 10);
            ReGoapTestsHelper.GetCustomAction(gameObject, "SmeltOre",
                                              new Dictionary <string, object> {
                { "hasOre", true }
            },
                                              new Dictionary <string, object> {
                { "hasSteel", true }, { "hasOre", false }
            }, 10);

            var hasAxeGoal = ReGoapTestsHelper.GetCustomGoal(gameObject, "HasAxeGoal",
                                                             new Dictionary <string, object> {
                { "hasAxe", true }
            });

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

            memory.Init();

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

            agent.Init();

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

            Assert.That(plan, Is.EqualTo(hasAxeGoal));
            // validate plan actions
            ReGoapTestsHelper.ApplyAndValidatePlan(plan, memory);
        }
Esempio n. 3
0
        public void TestConflictingPrecondPlan()
        {
            var gameObject = new GameObject();

            ReGoapTestsHelper.GetCustomAction(gameObject, "PutUpAxe",
                                              new Dictionary <string, object> {
                { "isAtPosition", "Box" }, { "hasAxe", true }
            },
                                              new Dictionary <string, object> {
                { "PutUpAxe", true }, { "hasAxe", false }
            }, 2);
            ReGoapTestsHelper.GetCustomAction(gameObject, "GoToBox",
                                              new Dictionary <string, object> {
            },
                                              new Dictionary <string, object> {
                { "isAtPosition", "Box" }
            }, 4);
            ReGoapTestsHelper.GetCustomAction(gameObject, "CraftAxe",
                                              new Dictionary <string, object> {
                { "isAtPosition", "Workbench" }
            },
                                              new Dictionary <string, object> {
                { "hasAxe", true }
            }, 1);
            ReGoapTestsHelper.GetCustomAction(gameObject, "GotoWorkbench",
                                              new Dictionary <string, object> {
            },
                                              new Dictionary <string, object> {
                { "isAtPosition", "Workbench" }
            }, 4);

            var hasAxeGoal = ReGoapTestsHelper.GetCustomGoal(gameObject, "Crafter",
                                                             new Dictionary <string, object> {
                { "PutUpAxe", true }
            });

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

            memory.Init();

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

            agent.Init();

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

            Assert.That(plan, Is.EqualTo(hasAxeGoal));
            // validate plan actions
            ReGoapTestsHelper.ApplyAndValidatePlan(plan, memory);
        }
Esempio n. 4
0
        public void TestGatherGotoGather()
        {
            var gameObject = new GameObject();

            ReGoapTestsHelper.GetCustomAction(gameObject, "GatherApple",
                                              new Dictionary <string, object> {
                { "At", "Farm" }
            },
                                              new Dictionary <string, object> {
                { "hasApple", true }
            }, 1);
            ReGoapTestsHelper.GetCustomAction(gameObject, "GatherPeach",
                                              new Dictionary <string, object> {
                { "At", "Farm" }
            },
                                              new Dictionary <string, object> {
                { "hasPeach", true }
            }, 2);
            ReGoapTestsHelper.GetCustomAction(gameObject, "Goto",
                                              new Dictionary <string, object> {
            },
                                              new Dictionary <string, object> {
                { "At", "Farm" }
            }, 10);

            var theGoal = ReGoapTestsHelper.GetCustomGoal(gameObject, "GatherAll",
                                                          new Dictionary <string, object> {
                { "hasApple", true }, { "hasPeach", true }
            });

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

            memory.Init();

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

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

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

            Assert.That(plan, Is.EqualTo(theGoal));
            // validate plan actions
            ReGoapTestsHelper.ApplyAndValidatePlan(plan, memory);
        }
Esempio n. 5
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);
        }
Esempio n. 6
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);
        }
Esempio n. 7
0
        public void TestActionOverrideGoal()
        {
            var gameObject = new GameObject();

            ReGoapTestsHelper.GetCustomAction(gameObject, "Mine Ore",
                                              new Dictionary <string, object> {
            },
                                              new Dictionary <string, object> {
                { "hasMoney", true }
            }, 10);
            ReGoapTestsHelper.GetCustomAction(gameObject, "Buy Food",
                                              new Dictionary <string, object> {
                { "hasMoney", true }
            },
                                              new Dictionary <string, object> {
                { "hasFood", true }, { "hasMoney", false }
            }, 2);

            var theGoal = ReGoapTestsHelper.GetCustomGoal(gameObject, "PrepareFoodAndMoney",
                                                          new Dictionary <string, object> {
                { "hasMoney", true }, { "hasFood", true }
            });

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

            memory.Init();

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

            agent.Init();

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

            Assert.That(plan, Is.EqualTo(theGoal));
            // validate plan actions
            ReGoapTestsHelper.ApplyAndValidatePlan(plan, agent, memory);
        }
Esempio n. 8
0
        public void TestTwoPhaseChainedPlan(IGoapPlanner <string, object> planner)
        {
            var gameObject = new GameObject();

            ReGoapTestsHelper.GetCustomAction(gameObject, "CCAction",
                                              new Dictionary <string, object> {
                { "hasWeaponEquipped", true }, { "isNearEnemy", true }
            },
                                              new Dictionary <string, object> {
                { "killedEnemy", true }
            }, 4);
            ReGoapTestsHelper.GetCustomAction(gameObject, "EquipAxe",
                                              new Dictionary <string, object> {
                { "hasAxe", true }
            },
                                              new Dictionary <string, object> {
                { "hasWeaponEquipped", true }
            }, 1);
            ReGoapTestsHelper.GetCustomAction(gameObject, "GoToEnemy",
                                              new Dictionary <string, object> {
                { "hasTarget", true }
            },
                                              new Dictionary <string, object> {
                { "isNearEnemy", true }
            }, 3);
            ReGoapTestsHelper.GetCustomAction(gameObject, "CreateAxe",
                                              new Dictionary <string, object> {
                { "hasWood", true }, { "hasSteel", true }
            },
                                              new Dictionary <string, object> {
                { "hasAxe", true }, { "hasWood", false }, { "hasSteel", false }
            }, 10);
            ReGoapTestsHelper.GetCustomAction(gameObject, "ChopTree",
                                              new Dictionary <string, object> {
            },
                                              new Dictionary <string, object> {
                { "hasRawWood", true }
            }, 2);
            ReGoapTestsHelper.GetCustomAction(gameObject, "WorksWood",
                                              new Dictionary <string, object> {
                { "hasRawWood", true }
            },
                                              new Dictionary <string, object> {
                { "hasWood", true }, { "hasRawWood", false }
            }, 5);
            ReGoapTestsHelper.GetCustomAction(gameObject, "MineOre", new Dictionary <string, object> {
            },
                                              new Dictionary <string, object> {
                { "hasOre", true }
            }, 10);
            ReGoapTestsHelper.GetCustomAction(gameObject, "SmeltOre",
                                              new Dictionary <string, object> {
                { "hasOre", true }
            },
                                              new Dictionary <string, object> {
                { "hasSteel", true }, { "hasOre", false }
            }, 10);

            var readyToFightGoal = ReGoapTestsHelper.GetCustomGoal(gameObject, "ReadyToFightGoal",
                                                                   new Dictionary <string, object> {
                { "hasWeaponEquipped", true }
            }, 2);

            ReGoapTestsHelper.GetCustomGoal(gameObject, "HasAxeGoal",
                                            new Dictionary <string, object> {
                { "hasAxe", true }
            });
            var killEnemyGoal = ReGoapTestsHelper.GetCustomGoal(gameObject, "KillEnemyGoal",
                                                                new Dictionary <string, object> {
                { "killedEnemy", true }
            }, 3);

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

            memory.Init();

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

            agent.Init();

            // first plan should create axe and equip it, through 'ReadyToFightGoal', since 'hasTarget' is false (memory should handle this)
            var plan = planner.Plan(agent, null, null, null);

            Assert.That(plan, Is.EqualTo(readyToFightGoal));
            // we apply manually the effects, but in reality the actions should do this themselves
            //  and the memory should understand what happened
            //  (e.g. equip weapon action? memory should set 'hasWeaponEquipped' to true if the action equipped something)
            // validate plan actions
            ReGoapTestsHelper.ApplyAndValidatePlan(plan, memory);

            // now we tell the memory that we see the enemy
            memory.SetValue("hasTarget", true);
            // now the planning should choose KillEnemyGoal
            plan = planner.Plan(agent, null, null, null);

            Assert.That(plan, Is.EqualTo(killEnemyGoal));
            ReGoapTestsHelper.ApplyAndValidatePlan(plan, memory);
        }
Esempio n. 9
0
        public void TestSimpleChainedPlan(IGoapPlanner <string, object> planner)
        {
            var gameObject = new GameObject();

            ReGoapTestsHelper.GetCustomAction(gameObject, "CreateAxe",
                                              new Dictionary <string, object> {
                { "hasWood", true }, { "hasSteel", true }
            },
                                              new Dictionary <string, object> {
                { "hasAxe", true }, { "hasWood", false }, { "hasSteel", false }
            }, 10);
            ReGoapTestsHelper.GetCustomAction(gameObject, "ChopTree",
                                              new Dictionary <string, object> {
            },
                                              new Dictionary <string, object> {
                { "hasRawWood", true }
            }, 2);
            ReGoapTestsHelper.GetCustomAction(gameObject, "WorksWood",
                                              new Dictionary <string, object> {
                { "hasRawWood", true }
            },
                                              new Dictionary <string, object> {
                { "hasWood", true }, { "hasRawWood", false }
            }, 5);
            ReGoapTestsHelper.GetCustomAction(gameObject, "MineOre",
                                              new Dictionary <string, object> {
            },
                                              new Dictionary <string, object> {
                { "hasOre", true }
            }, 10);
            ReGoapTestsHelper.GetCustomAction(gameObject, "SmeltOre",
                                              new Dictionary <string, object> {
                { "hasOre", true }
            },
                                              new Dictionary <string, object> {
                { "hasSteel", true }, { "hasOre", false }
            }, 10);

            var hasAxeGoal = ReGoapTestsHelper.GetCustomGoal(gameObject, "HasAxeGoal",
                                                             new Dictionary <string, object> {
                { "hasAxe", true }
            });
            var greedyHasAxeAndOreGoal = ReGoapTestsHelper.GetCustomGoal(gameObject, "GreedyHasAxeAndOreGoal",
                                                                         new Dictionary <string, object> {
                { "hasAxe", true }, { "hasOre", true }, { "isGreedy", true }
            },
                                                                         2);

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

            memory.Init();

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

            agent.Init();

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

            Assert.That(plan, Is.EqualTo(hasAxeGoal));
            // validate plan actions
            ReGoapTestsHelper.ApplyAndValidatePlan(plan, agent, memory);

            // now we set the agent to be greedy, so the second goal can be activated
            memory.SetValue("isGreedy", true);
            // now the planning should choose KillEnemyGoal
            plan = planner.Plan(agent, null, null, null);

            Assert.That(plan, Is.EqualTo(greedyHasAxeAndOreGoal));
            ReGoapTestsHelper.ApplyAndValidatePlan(plan, agent, memory);
        }
Esempio n. 10
0
        public void TestCollectResource1()
        {
            var planner = GetPlanner();

            var gameObject = new GameObject();

            ReGoapTestsHelper.GetCustomAction(gameObject, "GatherTree",
                                              new Dictionary <string, object> {
                { "At", "Tree" }
            },
                                              new Dictionary <string, object> {
                { "IntTree", 1 }
            },
                                              3);
            ReGoapTestsHelper.GetCustomAction(gameObject, "GatherOre",
                                              new Dictionary <string, object> {
                { "At", "Ore" }
            },
                                              new Dictionary <string, object> {
                { "IntOre", 1 }
            },
                                              5);
            ReGoapTestsHelper.GetCustomAction(gameObject, "GoToTree",
                                              new Dictionary <string, object> {
            },
                                              new Dictionary <string, object> {
                { "At", "Tree" }
            },
                                              7);
            ReGoapTestsHelper.GetCustomAction(gameObject, "GoToOre",
                                              new Dictionary <string, object> {
            },
                                              new Dictionary <string, object> {
                { "At", "Ore" }
            },
                                              7);
            ReGoapTestsHelper.GetCustomAction(gameObject, "GoToBench",
                                              new Dictionary <string, object> {
            },
                                              new Dictionary <string, object> {
                { "At", "Bench" }
            },
                                              7);
            ReGoapTestsHelper.GetCustomAction(gameObject, "MakeTool",
                                              new Dictionary <string, object> {
                { "At", "Bench" }, { "IntWood", 1 }, { "IntOre", 2 }
            },
                                              new Dictionary <string, object> {
                { "IntTool", 1 }, { "IntWood", -1 }, { "IntOre", -2 }
            },
                                              6);
            ReGoapTestsHelper.GetCustomAction(gameObject, "MakeWood",
                                              new Dictionary <string, object> {
                { "At", "Bench" }, { "IntTree", 2 }
            },
                                              new Dictionary <string, object> {
                { "IntWood", 1 }, { "IntTree", -2 }
            },
                                              6);


            var miningGoal = ReGoapTestsHelper.GetCustomGoal(gameObject, "MakeTool",
                                                             new Dictionary <string, object> {
                { "IntTool", 1 }
            });

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

            memory.Init();

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

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

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

            Assert.That(plan, Is.EqualTo(miningGoal));
            // validate plan actions
            ReGoapTestsHelper.ApplyAndValidatePlan(plan, memory);
        }