Exemplo n.º 1
0
 public Method FindSatisfiedMethod(GameController.WorldState WorkingWS)
 {
     foreach (Method m in this.methods)
     {
         if (m.PreconditionsSatisfied(WorkingWS))
         {
             return(m);
         }
     }
     return(null);
 }
Exemplo n.º 2
0
 public override bool PrimitiveConditionsMet(GameController.WorldState WorkingWS)
 {
     if (WorkingWS.aiTeleportsRemaining <= 0)
     {
         return(false);
     }
     else
     {
         return(true);
     }
 }
Exemplo n.º 3
0
 public override bool PrimitiveConditionsMet(GameController.WorldState WorkingWS)
 {
     if (WorkingWS.aiPreviousTarget == null)
     {
         return(false);
     }
     else
     {
         return(true);
     }
 }
Exemplo n.º 4
0
 public override bool PreconditionsSatisfied(GameController.WorldState gameState)
 {
     if (gameState.aiPreviousTarget == null)
     {
         return(false);
     }
     else
     {
         return(true);
     }
 }
Exemplo n.º 5
0
 public override bool ApplyEffects(AIController ai, GameController.WorldState WorkingWS)
 {
     if (WorkingWS.aiTeleportsRemaining <= 0)
     {
         return(false);
     }
     else
     {
         // WorkingWS.aiTeleportsRemaining--;
         return(true);
     }
 }
Exemplo n.º 6
0
 public override bool ApplyEffects(AIController ai, GameController.WorldState WorkingWS)
 {
     if (WorkingWS.aiPreviousTarget != null)
     {
         // WorkingWS.aiPreviousTarget = WorkingWS.AITarget;
         return(true);
     }
     else
     {
         return(false);
     }
 }
Exemplo n.º 7
0
 public override bool PrimitiveConditionsMet(GameController.WorldState WorkingWS)
 {
     if (WorkingWS.nearestAlcove == null)
     {
         return(false);
     }
     else if (WorkingWS.aiMovingTowardEnemy)
     {
         return(false);
     }
     else
     {
         return(true);
     }
 }
Exemplo n.º 8
0
 public override bool PreconditionsSatisfied(GameController.WorldState gameState)
 {
     if (gameState.enemyCloseToAITarget)
     {
         return(false);
     }
     else if (gameState.aiMovingTowardEnemy)
     {
         return(false);
     }
     else
     {
         return(true);
     }
 }
Exemplo n.º 9
0
 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);
     }
 }
Exemplo n.º 10
0
    // 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++;
        }
    }
Exemplo n.º 11
0
 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);
     }
 }
Exemplo n.º 12
0
 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);
     }
 }
Exemplo n.º 13
0
    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);
                }
            }
        }
    }
Exemplo n.º 14
0
 public override bool PrimitiveConditionsMet(GameController.WorldState WorkingWS)
 {
     // No Preconditions for finding nearest alcove, as there will always be alcoves.
     return(true);
 }
Exemplo n.º 15
0
        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);
            }
        }
Exemplo n.º 16
0
 public abstract bool PrimitiveConditionsMet(GameController.WorldState WorkingWS);
Exemplo n.º 17
0
 public override bool PreconditionsSatisfied(GameController.WorldState gameState)
 {
     // No preconditions, AI agent can always hide from enemy
     return(true);
 }
Exemplo n.º 18
0
 public abstract bool PreconditionsSatisfied(GameController.WorldState gameState);
Exemplo n.º 19
0
        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);
            }
        }
Exemplo n.º 20
0
 public abstract bool ApplyEffects(AIController ai, GameController.WorldState WorkingWS);