public async Task ShouldChooseHighestRatedGoal() { var planner = PlannerFactory.CreatePlanner(); var agent = new Agent(planner); var goal1 = new TestGoal{Weight = 0.2f}; var goal2 = new TestGoal{Weight = 0.5f}; agent.AddGoal(goal1); agent.AddGoal(goal2); await Assert.ThrowsAsync<InvalidOperationException>( async() => await agent.RunActionsAsync()); Assert.Equal(goal2, agent.CurrentGoal); }
public void SingleActionToGoal() { GameObject testGameObject = new GameObject(); Agent <string, bool> agent = testGameObject.AddComponent <StringBoolAgent>(); SortableGoal <string, bool> goal = new SortableGoal <string, bool> { { "TargetIsDead", true } }; goal.Priority = 1; agent.AddGoal(goal); agent.SetWorkingMemory(new WorldState <string, bool> { { "TargetIsDead", false } }); agent.AddAction(new ExecutableAction <string, bool>(_label: "Attack", _preconditions: null, _effects: new WorldStateModifier <string, bool> { { "TargetIsDead", true } }, _baseUtility: 5.0f)); GoalPlanPair <string, bool> generatedGoalPlanPair = m_StringBoolPlanner.GenerateGoalPlanPairForAgent(agent); Assert.True(generatedGoalPlanPair.PlanInstance.Count == 1); Assert.AreEqual("Attack", generatedGoalPlanPair.PlanInstance.Peek().GetLabel()); }
void Start() { Agent = GetComponent <Agent>(); Transform = transform; Agent.BlackBoard.IsPalyer = true; Agent.AddAction(E_GOAPAction.gotoPos); Agent.AddAction(E_GOAPAction.move); Agent.AddAction(E_GOAPAction.playAnim); Agent.AddAction(E_GOAPAction.weaponHide); Agent.AddAction(E_GOAPAction.weaponShow); Agent.AddAction(E_GOAPAction.orderAttack); Agent.AddGoal(E_GOAPGoals.E_PLAY_ANIM); Agent.AddGoal(E_GOAPGoals.E_GOTO); //Agent.AddGoal(E_GOAPGoals.E_IDLE_ANIM); //Agent.AddGoal(E_GOAPGoals.E_ORDER_ATTACK); Agent.InitializeGoap(); }
public async Task ShouldUseConsiderationToChooseBestGoal() { var planner = PlannerFactory.CreatePlanner(); var agent = new Agent(planner); var goal1 = new TestGoal{Weight = 1}; var goal2 = new TestGoal{Weight = 1}; goal1.AddConsideration(Consideration.FromFunc(d => 0.5f)); goal2.AddConsideration(Consideration.FromFunc(d => 0.2f)); agent.AddGoal(goal1); agent.AddGoal(goal2); await Assert.ThrowsAsync<InvalidOperationException>( async() => await agent.RunActionsAsync()); Assert.Equal(goal1, agent.CurrentGoal); }
public void MultipleLinearActionsToGoalWithBetterOption() { GameObject testGameObject = new GameObject(); Agent <string, bool> agent = testGameObject.AddComponent <StringBoolAgent>(); SortableGoal <string, bool> goal = new SortableGoal <string, bool> { { "TargetIsDead", true } }; goal.Priority = 1; agent.AddGoal(goal); agent.SetWorkingMemory(new WorldState <string, bool> { { "TargetIsDead", false } }); agent.AddAction(new ExecutableAction <string, bool>(_label: "Attack", _preconditions: new WorldStateModifier <string, bool> { { "WeaponIsLoaded", true } }, _effects: new WorldStateModifier <string, bool> { { "TargetIsDead", true } }, _baseUtility: 5.0f)); agent.AddAction(new ExecutableAction <string, bool>(_label: "Load Weapon", _preconditions: new WorldStateModifier <string, bool> { { "WeaponIsArmed", true } }, _effects: new WorldStateModifier <string, bool> { { "WeaponIsLoaded", true } }, _baseUtility: 5.0f)); agent.AddAction(new ExecutableAction <string, bool>(_label: "Quick Reload Weapon", _preconditions: new WorldStateModifier <string, bool> { { "WeaponIsArmed", true } }, _effects: new WorldStateModifier <string, bool> { { "WeaponIsLoaded", true } }, _baseUtility: 10.0f)); agent.AddAction(new ExecutableAction <string, bool>(_label: "Draw Weapon", _preconditions: null, _effects: new WorldStateModifier <string, bool> { { "WeaponIsArmed", true } }, _baseUtility: 5.0f)); GoalPlanPair <string, bool> generatedGoalPlanPair = m_StringBoolPlanner.GenerateGoalPlanPairForAgent(agent); Assert.True(generatedGoalPlanPair.PlanInstance.Count == 3); Assert.AreEqual("Draw Weapon", generatedGoalPlanPair.PlanInstance.Pop().GetLabel()); Assert.AreEqual("Quick Reload Weapon", generatedGoalPlanPair.PlanInstance.Pop().GetLabel()); Assert.AreEqual("Attack", generatedGoalPlanPair.PlanInstance.Pop().GetLabel()); }
// Use this for initialization void Start() { Agent.BlackBoard.IsPlayer = true; Agent.BlackBoard.Rage = 0; Agent.BlackBoard.Dodge = 0; Agent.BlackBoard.Fear = 0; SpriteEffectsManager.Instance.CreateShadow(Transform.Find("root").gameObject, 1.3f, 1.3f); Agent.AddAction(E_GOAPAction.gotoPos); Agent.AddAction(E_GOAPAction.move); Agent.AddAction(E_GOAPAction.gotoMeleeRange); Agent.AddAction(E_GOAPAction.weaponShow); Agent.AddAction(E_GOAPAction.weaponHide); Agent.AddAction(E_GOAPAction.orderAttack); Agent.AddAction(E_GOAPAction.orderDodge); Agent.AddAction(E_GOAPAction.rollToTarget); Agent.AddAction(E_GOAPAction.useLever); Agent.AddAction(E_GOAPAction.playAnim); Agent.AddAction(E_GOAPAction.teleport); Agent.AddAction(E_GOAPAction.injury); Agent.AddAction(E_GOAPAction.death); Agent.AddGoal(E_GOAPGoals.E_GOTO); Agent.AddGoal(E_GOAPGoals.E_ORDER_ATTACK); Agent.AddGoal(E_GOAPGoals.E_ORDER_DODGE); Agent.AddGoal(E_GOAPGoals.E_ORDER_USE); Agent.AddGoal(E_GOAPGoals.E_ALERT); Agent.AddGoal(E_GOAPGoals.E_CALM); Agent.AddGoal(E_GOAPGoals.E_USE_WORLD_OBJECT); Agent.AddGoal(E_GOAPGoals.E_PLAY_ANIM); Agent.AddGoal(E_GOAPGoals.E_TELEPORT); Agent.AddGoal(E_GOAPGoals.E_REACT_TO_DAMAGE); Agent.InitializeGOAP(); Agent.BlackBoard.AddActionHandle(this); }
public void WorldStateAlreadyFulfilsGoal() { GameObject testGameObject = new GameObject(); Agent <string, bool> agent = testGameObject.AddComponent <StringBoolAgent>(); SortableGoal <string, bool> goal = new SortableGoal <string, bool> { { "TargetIsDead", true } }; goal.Priority = 1; agent.AddGoal(goal); agent.SetWorkingMemory(new WorldState <string, bool> { { "TargetIsDead", true } }); GoalPlanPair <string, bool> generatedGoalPlanPair = m_StringBoolPlanner.GenerateGoalPlanPairForAgent(agent); Assert.True(generatedGoalPlanPair.PlanInstance.Count == 0); Assert.True(agent.GetWorkingMemory().Equals(goal)); }
public async Task CancellationOfRunningActionsShouldWork() { var goal = new TestGoal{Weight = 1}; var action = new InfiniteRunAction(); var planner = PlannerFactory.CreatePlanner(); var agent = new Agent(planner); var source = new CancellationTokenSource(); agent.AddGoal(goal); agent.AddAction(action); var agentTask = agent.RunActionsAsync(source.Token); var cancelTask = Task.Run(() => source.Cancel()); await Task.WhenAll(agentTask, cancelTask); Assert.Equal(action, agent.CurrentAction); }
public void GoToMushroomTest() { GameObject testGameObject = new GameObject(); Agent <string, bool> agent = testGameObject.AddComponent <StringBoolAgent>(); SortableGoal <string, bool> goal = new SortableGoal <string, bool> { { "AtTargetPosition", true }, { "TargetIsMushroom", true } }; goal.Priority = 1; agent.AddGoal(goal); agent.SetWorkingMemory(new WorldState <string, bool> { }); agent.AddAction(new ExecutableAction <string, bool>(_label: "LookForMushroom", _preconditions: new WorldStateModifier <string, bool> { }, _effects: new WorldStateModifier <string, bool> { { "HasTargetPosition", true }, { "AtTargetPosition", false }, { "TargetIsMushroom", true } }, _baseUtility: 5.0f)); agent.AddAction(new ExecutableAction <string, bool>(_label: "MoveToPosition", _preconditions: new WorldStateModifier <string, bool> { { "HasTargetPosition", true }, { "AtTargetPosition", false } }, _effects: new WorldStateModifier <string, bool> { { "HasTargetPosition", false }, { "AtTargetPosition", true } }, _baseUtility: 5.0f)); GoalPlanPair <string, bool> generatedGoalPlanPair = m_StringBoolPlanner.GenerateGoalPlanPairForAgent(agent); Assert.True(generatedGoalPlanPair.PlanInstance.Count == 2); Assert.AreEqual("LookForMushroom", generatedGoalPlanPair.PlanInstance.Pop().GetLabel()); Assert.AreEqual("MoveToPosition", generatedGoalPlanPair.PlanInstance.Pop().GetLabel()); }
public void MushroomGathererStringObjectPerformance() { GameObject testGameObject = new GameObject(); Agent <string, object> agent = testGameObject.AddComponent <StringObjectAgent>(); SortableGoal <string, object> goal = new SortableGoal <string, object> { { "HasEnoughMushrooms", true } }; goal.Priority = 1; agent.AddGoal(goal); agent.SetWorkingMemory(new WorldState <string, object> { }); agent.AddAction(new ExecutableAction <string, object>(_label: "LookForMushroom", _preconditions: new WorldStateModifier <string, object> { }, _effects: new WorldStateModifier <string, object> { { "HasTargetPosition", true }, { "AtTargetPosition", false }, { "TargetIs", "Mushroom" } }, _baseUtility: 5.0f)); agent.AddAction(new ExecutableAction <string, object>(_label: "PickupMushroom", _preconditions: new WorldStateModifier <string, object> { { "AtTargetPosition", true }, { "TargetIs", "Mushroom" } }, _effects: new WorldStateModifier <string, object> { { "CarriesMushroom", true }, { "HasTargetPosition", true }, { "AtTargetPosition", false } }, _baseUtility: 5.0f)); agent.AddAction(new ExecutableAction <string, object>(_label: "MoveToPosition", _preconditions: new WorldStateModifier <string, object> { { "HasTargetPosition", true }, { "AtTargetPosition", false } }, _effects: new WorldStateModifier <string, object> { { "HasTargetPosition", false }, { "AtTargetPosition", true } }, _baseUtility: 5.0f)); agent.AddAction(new ExecutableAction <string, object>(_label: "DropOffMushroomAtHome", _preconditions: new WorldStateModifier <string, object> { { "CarriesMushroom", true }, { "AtTargetPosition", true } }, _effects: new WorldStateModifier <string, object> { { "AtTargetPosition", false }, { "HasEnoughMushrooms", true }, { "CarriesMushroom", false } }, _baseUtility: 5.0f)); agent.AddAction(new ExecutableAction <string, object>(_label: "LookForFish", _preconditions: new WorldStateModifier <string, object> { }, _effects: new WorldStateModifier <string, object> { { "HasTargetPosition", true }, { "AtTargetPosition", false }, { "TargetIs", "Fish" } }, _baseUtility: 5.0f)); agent.AddAction(new ExecutableAction <string, object>(_label: "PickupFish", _preconditions: new WorldStateModifier <string, object> { { "AtTargetPosition", true }, { "TargetIs", "Fish" } }, _effects: new WorldStateModifier <string, object> { { "CarriesFish", true }, { "HasTargetPosition", true }, { "AtTargetPosition", false } }, _baseUtility: 5.0f)); agent.AddAction(new ExecutableAction <string, object>(_label: "DropOffFishAtHome", _preconditions: new WorldStateModifier <string, object> { { "CarriesFish", true }, { "AtTargetPosition", true } }, _effects: new WorldStateModifier <string, object> { { "AtTargetPosition", false }, { "HasEnoughFish", true }, { "CarriesFish", false } }, _baseUtility: 5.0f)); GoalPlanPair <string, object> generatedGoalPlanPair = m_StringObjectPlanner.GenerateGoalPlanPairForAgent(agent); Assert.True(generatedGoalPlanPair.PlanInstance.Count == 5); }
public void MushroomGathererEnumObjectPerformance() { GameObject testGameObject = new GameObject(); Agent <GathererKeys, object> agent = testGameObject.AddComponent <EnumObjectAgent>(); SortableGoal <GathererKeys, object> goal = new SortableGoal <GathererKeys, object> { { GathererKeys.HAS_ENOUGH_MUSHROOMS, true } }; goal.Priority = 1; agent.AddGoal(goal); agent.SetWorkingMemory(new WorldState <GathererKeys, object> { }); agent.AddAction(new ExecutableAction <GathererKeys, object>(_label: "LookForMushroom", _preconditions: new WorldStateModifier <GathererKeys, object> { }, _effects: new WorldStateModifier <GathererKeys, object> { { GathererKeys.HAS_TARGET_POSITION, true }, { GathererKeys.AT_TARGET_POSITION, false }, { GathererKeys.TARGET_IS, "Mushroom" } }, _baseUtility: 5.0f)); agent.AddAction(new ExecutableAction <GathererKeys, object>(_label: "PickupMushroom", _preconditions: new WorldStateModifier <GathererKeys, object> { { GathererKeys.AT_TARGET_POSITION, true }, { GathererKeys.TARGET_IS, "Mushroom" } }, _effects: new WorldStateModifier <GathererKeys, object> { { GathererKeys.CARRIES_MUSHROOM, true }, { GathererKeys.HAS_TARGET_POSITION, true }, { GathererKeys.AT_TARGET_POSITION, false } }, _baseUtility: 5.0f)); agent.AddAction(new ExecutableAction <GathererKeys, object>(_label: "MoveToPosition", _preconditions: new WorldStateModifier <GathererKeys, object> { { GathererKeys.HAS_TARGET_POSITION, true }, { GathererKeys.AT_TARGET_POSITION, false } }, _effects: new WorldStateModifier <GathererKeys, object> { { GathererKeys.HAS_TARGET_POSITION, false }, { GathererKeys.AT_TARGET_POSITION, true } }, _baseUtility: 5.0f)); agent.AddAction(new ExecutableAction <GathererKeys, object>(_label: "DropOffMushroomAtHome", _preconditions: new WorldStateModifier <GathererKeys, object> { { GathererKeys.CARRIES_MUSHROOM, true }, { GathererKeys.AT_TARGET_POSITION, true } }, _effects: new WorldStateModifier <GathererKeys, object> { { GathererKeys.AT_TARGET_POSITION, false }, { GathererKeys.HAS_ENOUGH_MUSHROOMS, true }, { GathererKeys.CARRIES_MUSHROOM, false } }, _baseUtility: 5.0f)); agent.AddAction(new ExecutableAction <GathererKeys, object>(_label: "LookForFish", _preconditions: new WorldStateModifier <GathererKeys, object> { }, _effects: new WorldStateModifier <GathererKeys, object> { { GathererKeys.HAS_TARGET_POSITION, true }, { GathererKeys.AT_TARGET_POSITION, false }, { GathererKeys.TARGET_IS, "Fish" } }, _baseUtility: 5.0f)); agent.AddAction(new ExecutableAction <GathererKeys, object>(_label: "PickupFish", _preconditions: new WorldStateModifier <GathererKeys, object> { { GathererKeys.AT_TARGET_POSITION, true }, { GathererKeys.TARGET_IS, "Fish" } }, _effects: new WorldStateModifier <GathererKeys, object> { { GathererKeys.CARRIES_FISH, true }, { GathererKeys.HAS_TARGET_POSITION, true }, { GathererKeys.AT_TARGET_POSITION, false } }, _baseUtility: 5.0f)); agent.AddAction(new ExecutableAction <GathererKeys, object>(_label: "DropOffFishAtHome", _preconditions: new WorldStateModifier <GathererKeys, object> { { GathererKeys.CARRIES_FISH, true }, { GathererKeys.AT_TARGET_POSITION, true } }, _effects: new WorldStateModifier <GathererKeys, object> { { GathererKeys.AT_TARGET_POSITION, false }, { GathererKeys.HAS_ENOUGH_FISH, true }, { GathererKeys.CARRIES_FISH, false } }, _baseUtility: 5.0f)); GoalPlanPair <GathererKeys, object> generatedGoalPlanPair = m_EnumObjectPlanner.GenerateGoalPlanPairForAgent(agent); Assert.True(generatedGoalPlanPair.PlanInstance.Count == 5); }