public Method FindSatisfiedMethod(GameController.WorldState WorkingWS) { foreach (Method m in this.methods) { if (m.PreconditionsSatisfied(WorkingWS)) { return(m); } } return(null); }
public override bool PrimitiveConditionsMet(GameController.WorldState WorkingWS) { if (WorkingWS.aiTeleportsRemaining <= 0) { return(false); } else { return(true); } }
public override bool PrimitiveConditionsMet(GameController.WorldState WorkingWS) { if (WorkingWS.aiPreviousTarget == null) { return(false); } else { return(true); } }
public override bool PreconditionsSatisfied(GameController.WorldState gameState) { if (gameState.aiPreviousTarget == null) { return(false); } else { return(true); } }
public override bool ApplyEffects(AIController ai, GameController.WorldState WorkingWS) { if (WorkingWS.aiTeleportsRemaining <= 0) { return(false); } else { // WorkingWS.aiTeleportsRemaining--; return(true); } }
public override bool ApplyEffects(AIController ai, GameController.WorldState WorkingWS) { if (WorkingWS.aiPreviousTarget != null) { // WorkingWS.aiPreviousTarget = WorkingWS.AITarget; return(true); } else { return(false); } }
public override bool PrimitiveConditionsMet(GameController.WorldState WorkingWS) { if (WorkingWS.nearestAlcove == null) { return(false); } else if (WorkingWS.aiMovingTowardEnemy) { return(false); } else { return(true); } }
public override bool PreconditionsSatisfied(GameController.WorldState gameState) { if (gameState.enemyCloseToAITarget) { return(false); } else if (gameState.aiMovingTowardEnemy) { return(false); } else { return(true); } }
public override bool PreconditionsSatisfied(GameController.WorldState gameState) { if (gameState.aiTeleportsRemaining <= 0) { return(false); } else if (gameState.distToClosestEnemy <= 5 || (gameState.playerCloserToTargetItem && gameState.playerIsNearestAgent)) { // An enemy is dangerously close, or the player is going to beat the AI to its target item return(true); } else { return(false); } }
// Update is called once per frame void Update() { if (timer >= 2) { GameController.WorldState currentState = game.GetCurrentState(); plan(currentState); PlayMove(); agent.SetDestination(target.position); timer = 0; } else { timer++; } }
public override bool PreconditionsSatisfied(GameController.WorldState gameState) { // There are still items remaining if (gameState.numItemsRemaining <= 0) { return(false); } // No enemies are nearby else if (gameState.distToClosestEnemy <= 10) { return(false); } else { return(true); } }
public override bool PrimitiveConditionsMet(GameController.WorldState WorkingWS) { if (WorkingWS.numItemsRemaining <= 0) { return(false); } else if (WorkingWS.closestItemToAI == null) { return(false); } else if (WorkingWS.aiMovingTowardEnemy) { return(false); } else { return(true); } }
public void plan(GameController.WorldState currentWorldState) { finalPlan = new Stack <PrimitiveTask>(); Stack <PlannerState> decompHistory = new Stack <PlannerState>(); GameController.WorldState WorkingWS = currentWorldState.Copy(); tasksToProcess.Push(new PlayGame()); while (tasksToProcess.Count > 0) { Task CurrentTask = tasksToProcess.Pop(); if (CurrentTask.GetType().IsSubclassOf(typeof(CompoundTask))) { CompoundTask CurrentCompoundTask = (CompoundTask)CurrentTask; Method SatisfiedMethod = CurrentCompoundTask.FindSatisfiedMethod(WorkingWS); if (SatisfiedMethod != null) { //PlannerState currentState = new PlannerState(CurrentCompoundTask, finalPlan, tasksToProcess, SatisfiedMethod); // decompHistory.Push(currentState); SatisfiedMethod.subTasks.Reverse(); foreach (Task t in SatisfiedMethod.subTasks) { tasksToProcess.Push(t); } SatisfiedMethod.subTasks.Reverse(); } else if (decompHistory.Count > 0) { //RestoreToLastDecomposedTask(): PlannerState lastState = decompHistory.Pop(); CompoundTask lastCompoundTask = lastState.currentTask; finalPlan = lastState.finalPlan; tasksToProcess = lastState.tasksToProcess; // Remove the failed method and return CompoundTask to the stack. On the next iteration, it will be checked again for a valid method. lastCompoundTask.InvalidateMethod(lastState.currentMethod); tasksToProcess.Push(lastCompoundTask); } } else//Primitive Task { PrimitiveTask CurrentPrimitiveTask = (PrimitiveTask)CurrentTask; if (CurrentPrimitiveTask.PrimitiveConditionsMet(WorkingWS)) { // CurrentPrimitiveTask.ApplyEffects(this, WorkingWS); // Add this PrimitiveTask to the bottom of the finalPlan Stack <PrimitiveTask> temp = new Stack <PrimitiveTask>(); for (int i = 0; i < finalPlan.Count; i++) { PrimitiveTask nextTask = finalPlan.Pop(); temp.Push(nextTask); } temp.Push(CurrentPrimitiveTask); finalPlan = new Stack <PrimitiveTask>(); for (int i = 0; i < temp.Count; i++) { PrimitiveTask nextTask = temp.Pop(); finalPlan.Push(nextTask); } } else if (decompHistory.Count > 0) { //RestoreToLastDecomposedTask(); PlannerState lastState = decompHistory.Pop(); CompoundTask lastCompoundTask = lastState.currentTask; finalPlan = lastState.finalPlan; tasksToProcess = lastState.tasksToProcess; // Remove the failed method and return CompoundTask to the stack. On the next iteration, it will be checked again for a valid method. lastCompoundTask.InvalidateMethod(lastState.currentMethod); tasksToProcess.Push(lastCompoundTask); } } } }
public override bool PrimitiveConditionsMet(GameController.WorldState WorkingWS) { // No Preconditions for finding nearest alcove, as there will always be alcoves. return(true); }
public override bool ApplyEffects(AIController ai, GameController.WorldState WorkingWS) { List <Transform> alcoves = new List <Transform> { ai.game.bottomAlcove1, ai.game.bottomAlcove2, ai.game.bottomAlcove3, ai.game.bottomAlcove4, ai.game.bottomAlcove5, ai.game.topAlcove1, ai.game.topAlcove2, ai.game.topAlcove3, ai.game.topAlcove4, ai.game.topAlcove5, ai.game.leftAlcove, ai.game.rightAlcove }; float minDistToAlcove = 1000; Transform closestAlcove = null; foreach (Transform t in alcoves) { float distToAlcove = Vector3.Distance(ai.agent.transform.position, t.position); if (distToAlcove < minDistToAlcove) { // Check if no enemies are too close to this alcove. float minEnemyDistToAlcove = 1000; for (int i = 0; i < ai.game.topEnemies.Length; i++) { float topEnemyDistToAlcove = 1000; float bottomEnemyDistToAlcove = 1000; if (ai.game.topEnemies[i].visionField != null) { topEnemyDistToAlcove = Vector3.Distance(ai.game.topEnemies[i].visionField.position, t.position); } else { topEnemyDistToAlcove = Vector3.Distance(ai.game.topEnemies[i].transform.position, t.position); } if (ai.game.bottomEnemies[i].visionField != null) { bottomEnemyDistToAlcove = Vector3.Distance(ai.game.bottomEnemies[i].visionField.position, t.position); } else { bottomEnemyDistToAlcove = Vector3.Distance(ai.game.bottomEnemies[i].transform.position, t.position); } if (topEnemyDistToAlcove < minEnemyDistToAlcove) { minEnemyDistToAlcove = topEnemyDistToAlcove; } if (bottomEnemyDistToAlcove < minEnemyDistToAlcove) { minEnemyDistToAlcove = bottomEnemyDistToAlcove; } } if (minEnemyDistToAlcove > 11) { minDistToAlcove = distToAlcove; closestAlcove = t; } } } // WorkingWS.nearestAlcove = closestAlcove; //WorkingWS.aiTentativeTarget = closestAlcove; if (closestAlcove != null) { return(true); } else { return(false); } }
public abstract bool PrimitiveConditionsMet(GameController.WorldState WorkingWS);
public override bool PreconditionsSatisfied(GameController.WorldState gameState) { // No preconditions, AI agent can always hide from enemy return(true); }
public abstract bool PreconditionsSatisfied(GameController.WorldState gameState);
public override bool ApplyEffects(AIController ai, GameController.WorldState WorkingWS) { if (ai.game.itemsRemaining != null && WorkingWS.numItemsRemaining > 0) { List <Transform> itemsRemaining = ai.game.itemsRemaining; float minDistToItem = Vector3.Distance(ai.agent.transform.position, itemsRemaining[0].position); Transform closestItem = itemsRemaining[0]; foreach (Transform t in itemsRemaining) { float distToItem = Vector3.Distance(ai.agent.transform.position, t.position); if (distToItem < minDistToItem) { // Check if no enemies are too close to this item. float minEnemyDistToItem = 1000; for (int i = 0; i < ai.game.topEnemies.Length; i++) { float topEnemyDistToItem = 1000; float bottomEnemyDistToItem = 1000; if (ai.game.topEnemies[i].visionField != null) { topEnemyDistToItem = Vector3.Distance(ai.game.topEnemies[i].visionField.position, t.position); } else { topEnemyDistToItem = Vector3.Distance(ai.game.topEnemies[i].transform.position, t.position); } if (ai.game.bottomEnemies[i].visionField != null) { bottomEnemyDistToItem = Vector3.Distance(ai.game.bottomEnemies[i].visionField.position, t.position); } else { bottomEnemyDistToItem = Vector3.Distance(ai.game.bottomEnemies[i].transform.position, t.position); } if (topEnemyDistToItem < minEnemyDistToItem) { minEnemyDistToItem = topEnemyDistToItem; } if (bottomEnemyDistToItem < minEnemyDistToItem) { minEnemyDistToItem = bottomEnemyDistToItem; } } minDistToItem = distToItem; closestItem = t; } } // WorkingWS.closestItemToAI = closestItem; // WorkingWS.aiTentativeTarget = closestItem; return(true); } else { return(false); } }
public abstract bool ApplyEffects(AIController ai, GameController.WorldState WorkingWS);