示例#1
0
    public void TestSimpleChainedPlan(IGoapPlanner planner)
    {
        var gameObject = new GameObject();

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

        var hasAxeGoal = ReGoapTestsHelper.GetCustomGoal(gameObject, "HasAxeGoal",
                                                         new Dictionary <string, bool> {
            { "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);
    }
示例#2
0
        public void TestPlan2(IGoapPlanner <string, object> planner)
        {
            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));

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

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

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

            Assert.That(plan, Is.EqualTo(miningGoal));
            // validate plan actions
            ReGoapTestsHelper.ApplyAndValidatePlan(plan, memory);
        }
示例#3
0
    public void TestTwoPhaseChainedPlan(IGoapPlanner planner)
    {
        var gameObject = new GameObject();

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

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

        ReGoapTestsHelper.GetCustomGoal(gameObject, "HasAxeGoal",
                                        new Dictionary <string, bool> {
            { "hasAxe", true }
        });
        var killEnemyGoal = ReGoapTestsHelper.GetCustomGoal(gameObject, "KillEnemyGoal",
                                                            new Dictionary <string, bool> {
            { "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);
    }
示例#4
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);
        }