Esempio n. 1
0
        public override GlobalPath DecomposeGoalIntoPath(SteeringGoal goal)
        {
            GlobalPath path;

            if (goal.PositionSet && !this.CurrentGoalPosition.Equals(goal.Position))
            {
                this.CurrentGoalPosition = goal.Position;
                this.PathfindingAlgorithm.InitializePathfindingSearch(this.Pipeline.Character.position, goal.Position);
            }

            if (this.PathfindingAlgorithm.InProgress)
            {
                if (this.PathfindingAlgorithm.Search(out path, true))
                {
                    this.UnsmoothedPath = path;
                    this.CurrentPath    = StringPullingPathSmoothing.SmoothPath(this.Pipeline.Character, path);
                    this.CurrentPath.CalculateLocalPathsFromPathPositions(this.Pipeline.Character.position);
                }
                else
                {
                    this.UnsmoothedPath = path;
                    this.CurrentPath    = path;
                }
            }

            return(this.CurrentPath);
        }
        /// <summary>
        ///     Smoothes the current path
        /// </summary>
        public GlobalPath SmoothPath(GlobalPath currentSolution)
        {
            GlobalPath currentSmoothedSolution = null;

            currentSmoothedSolution = StringPullingPathSmoothing.SmoothPath(Character.KinematicData,
                                                                            currentSolution);
            currentSmoothedSolution.PathPositions.Add(Position);
            currentSmoothedSolution.CalculateLocalPathsFromPathPositions(
                Character.KinematicData.position);
            // currentSmoothedSolution.LastParam = lastParam;

            return(currentSmoothedSolution);
        }
 public bool Initialize(Vector3 position)
 {
     Position = position;
     //initialize the search algorithm
     if (aStarPathFinding.InitializePathfindingSearch(Character.KinematicData.position, position))
     {
         StringPullingPathSmoothing.Initialize();
         return(true);
     }
     else
     {
         return(false);
     }
 }
Esempio n. 4
0
        public override Goal Decompose(KinematicData character, Goal goal)
        {
            if ((Astar == null))
            {
                Astar = new NodeArrayAStarPathFinding(Graph, Heuristic);
                Astar.InitializePathfindingSearch(character.position, goal.position);
                CurrentParam = 0.0f;
            }


            GlobalPath currentSolution;

            if (Astar.InProgress)
            {
                var finished = Astar.Search(out currentSolution, true);

                if (finished && currentSolution != null)
                {
                    this.AStarSolution = currentSolution;
                    this.GlobalPath    = StringPullingPathSmoothing.SmoothPath(character, currentSolution);
                    this.GlobalPath.CalculateLocalPathsFromPathPositions(character.position);
                    // gets first node
                    goal.position = this.GlobalPath.LocalPaths[0].EndPosition;
                    return(goal);
                }

                /* else if(currentSolution != null && currentSolution.IsPartial)
                 * {
                 *   goal.position = currentSolution.PathPositions[0];
                 *   return goal;
                 * }*/
            }
            else
            {
                if (GlobalPath.PathEnd(CurrentParam))
                {
                    goal.position = GlobalPath.LocalPaths[GlobalPath.LocalPaths.Count - 1].GetPosition(1.0f);
                    return(goal);
                }

                CurrentParam = GlobalPath.GetParam(character.position, CurrentParam);


                goal.position = GlobalPath.GetPosition(CurrentParam + 0.2f);
                return(goal);
            }
            return(new Goal());
        }
    // Update is called once per frame
    void Update()
    {
        Vector3 position;

        if (Input.GetMouseButtonDown(0))
        {
            //if there is a valid position
            if (this.MouseClickPosition(out position))
            {
                //we're setting the end point
                //this is just a small adjustment to better see the debug sphere
                this.endDebugSphere.transform.position = position + Vector3.up;
                this.endDebugSphere.SetActive(true);
                //this.currentClickNumber = 1;
                this.endPosition = position;
                this.draw        = true;
                //initialize the search algorithm
                this.AStarPathFinding.InitializePathfindingSearch(this.character.KinematicData.position, this.endPosition);
            }
        }

        //call the pathfinding method if the user specified a new goal
        if (this.AStarPathFinding.InProgress)
        {
            var finished = this.AStarPathFinding.Search(out this.currentSolution);
            if (finished && this.currentSolution != null)
            {
                //lets smooth out the Path
                this.startPosition           = this.character.KinematicData.position;
                this.currentSmoothedSolution = StringPullingPathSmoothing.SmoothPath(this.character.KinematicData, this.currentSolution);
                this.currentSmoothedSolution.CalculateLocalPathsFromPathPositions(this.character.KinematicData.position);
                this.character.Movement = new DynamicFollowPath(this.character.KinematicData, this.currentSmoothedSolution)
                {
                    MaxAcceleration = 40.0f,
                    MaxSpeed        = 20.0f
                };
            }
        }

        this.character.Update();
    }
        void Update()
        {
            if (GameManager.GameOver == false)
            {
                if (Time.time > this.nextUpdateTime || this.GameManager.WorldChanged)
                {
                    this.GameManager.WorldChanged = false;
                    this.nextUpdateTime           = Time.time + DECISION_MAKING_INTERVAL;

                    //first step, perceptions
                    //update the agent's goals based on the state of the world
                    this.SurviveGoal.InsistenceValue = this.GameManager.characterData.MaxHP - this.GameManager.characterData.HP;

                    this.BeQuickGoal.InsistenceValue += DECISION_MAKING_INTERVAL * 0.1f;
                    if (this.BeQuickGoal.InsistenceValue > 10.0f)
                    {
                        this.BeQuickGoal.InsistenceValue = 10.0f;
                    }

                    this.GainXPGoal.InsistenceValue += 0.1f; //increase in goal over time
                    if (this.GameManager.characterData.XP > this.previousXP)
                    {
                        this.GainXPGoal.InsistenceValue -= this.GameManager.characterData.XP - this.previousXP;
                        this.previousXP = this.GameManager.characterData.XP;
                    }

                    this.GetRichGoal.InsistenceValue += 0.1f; //increase in goal over time
                    if (this.GetRichGoal.InsistenceValue > 10)
                    {
                        this.GetRichGoal.InsistenceValue = 10.0f;
                    }

                    if (this.GameManager.characterData.Money > this.previousGold)
                    {
                        this.GetRichGoal.InsistenceValue -= this.GameManager.characterData.Money - this.previousGold;
                        this.previousGold = this.GameManager.characterData.Money;
                    }

                    this.SurviveGoalText.text = "Survive: " + this.SurviveGoal.InsistenceValue;
                    this.GainXPGoalText.text  = "Gain XP: " + this.GainXPGoal.InsistenceValue.ToString("F1");
                    this.BeQuickGoalText.text = "Be Quick: " + this.BeQuickGoal.InsistenceValue.ToString("F1");
                    this.GetRichGoalText.text = "GetRich: " + this.GetRichGoal.InsistenceValue.ToString("F1");

                    //initialize Decision Making Proccess
                    this.CurrentAction = null;
                    if (this.MCTSActive)
                    {
                        this.MCTSDecisionMaking.InitializeMCTSearch();
                    }
                    else
                    {
                        this.GOAPDecisionMaking.InitializeDecisionMakingProcess();
                    }
                }

                if (this.MCTSActive)
                {
                    this.UpdateMCTS();
                }
                else
                {
                    this.UpdateDLGOAP();
                }

                if (this.CurrentAction != null)
                {
                    if (this.CurrentAction.CanExecute())
                    {
                        this.CurrentAction.Execute();
                    }
                }

                //call the pathfinding method if the user specified a new goal
                if (this.AStarPathFinding.InProgress)
                {
                    var finished = this.AStarPathFinding.Search(out this.currentSolution);
                    if (finished && this.currentSolution != null)
                    {
                        //lets smooth out the Path
                        this.startPosition           = this.Character.KinematicData.position;
                        this.currentSmoothedSolution = StringPullingPathSmoothing.SmoothPath(this.Character.KinematicData, this.currentSolution);
                        this.currentSmoothedSolution.CalculateLocalPathsFromPathPositions(this.Character.KinematicData.position);
                        this.Character.Movement = new DynamicFollowPath(this.Character.KinematicData, this.currentSmoothedSolution)
                        {
                            MaxAcceleration = 200.0f,
                            MaxSpeed        = 40.0f
                        };
                    }
                }


                this.Character.Update();
            }
        }
Esempio n. 7
0
        void Update()
        {
            if (Time.time > this.nextUpdateTime)
            {
                this.nextUpdateTime = Time.time + DECISION_MAKING_INTERVAL;

                //first step, perceptions
                //update the agent's goals based on the state of the world
                this.SurviveGoal.InsistenceValue = this.GameManager.characterData.MaxHP - this.GameManager.characterData.HP;

                this.BeQuickGoal.InsistenceValue += DECISION_MAKING_INTERVAL * 0.1f;
                if (this.BeQuickGoal.InsistenceValue > 10.0f)
                {
                    this.BeQuickGoal.InsistenceValue = 10.0f;
                }

                this.GainXPGoal.InsistenceValue += 0.1f; //increase in goal over time
                if (this.GameManager.characterData.XP > this.previousXP)
                {
                    this.GainXPGoal.InsistenceValue -= this.GameManager.characterData.XP - this.previousXP;
                    this.previousXP = this.GameManager.characterData.XP;
                }

                this.GetRichGoal.InsistenceValue += 0.1f; //increase in goal over time
                if (this.GetRichGoal.InsistenceValue > 10)
                {
                    this.GetRichGoal.InsistenceValue = 10.0f;
                }

                if (this.GameManager.characterData.Money > this.previousGold)
                {
                    this.GetRichGoal.InsistenceValue -= this.GameManager.characterData.Money - this.previousGold;
                    this.previousGold = this.GameManager.characterData.Money;
                }

                this.SurviveGoalText.text = "Survive: " + this.SurviveGoal.InsistenceValue;
                this.GainXPGoalText.text  = "Gain XP: " + this.GainXPGoal.InsistenceValue.ToString("F1");
                this.BeQuickGoalText.text = "Be Quick: " + this.BeQuickGoal.InsistenceValue.ToString("F1");
                this.GetRichGoalText.text = "GetRich: " + this.GetRichGoal.InsistenceValue.ToString("F1");

                //initialize GOAP Decision Making Proccess
                this.GOAPDecisionMaking.InitializeDecisionMakingProcess();
            }



            if (this.GOAPDecisionMaking.InProgress)
            {
                //choose an action using the GOB Decision Making process
                var action = this.GOAPDecisionMaking.ChooseAction();
                if (action != null)
                {
                    action.Execute();
                    this.CurrentAction = action;
                }
            }

            this.TotalProcessingTimeText.text = "Process. Time: " + this.GOAPDecisionMaking.TotalProcessingTime.ToString("F");
            this.BestDiscontentmentText.text  = "Best Discontentment: " + this.GOAPDecisionMaking.BestDiscontentmentValue.ToString("F");
            this.ProcessedActionsText.text    = "Act. comb. processed: " + this.GOAPDecisionMaking.TotalActionCombinationsProcessed;

            if (this.GOAPDecisionMaking.BestAction != null)
            {
                var actionText = "";
                foreach (var action in this.GOAPDecisionMaking.BestActionSequence)
                {
                    actionText += "\n" + action.Name;
                }
                this.BestActionText.text = "Best Action Sequence: " + actionText;
            }
            else
            {
                this.BestActionText.text = "Best Action Sequence:\nNone";
            }

            //call the pathfinding method if the user specified a new goal
            if (this.AStarPathFinding.InProgress)
            {
                var finished = this.AStarPathFinding.Search(out this.currentSolution);
                if (finished && this.currentSolution != null)
                {
                    //lets smooth out the Path
                    this.startPosition           = this.Character.KinematicData.position;
                    this.currentSmoothedSolution = StringPullingPathSmoothing.SmoothPath(this.Character.KinematicData, this.currentSolution);
                    this.currentSmoothedSolution.CalculateLocalPathsFromPathPositions(this.Character.KinematicData.position);

                    this.Character.Movement = new DynamicFollowPath(this.Character.KinematicData, this.currentSmoothedSolution);
                }
            }
            this.Character.Update();
        }
Esempio n. 8
0
        void Update()
        {
            if (GameManager.gameEnded)
            {
                return;
            }

            if (Time.time > this.nextUpdateTime || this.GameManager.WorldChanged)
            {
                this.GameManager.WorldChanged = false;
                this.nextUpdateTime           = Time.time + DECISION_MAKING_INTERVAL;

                //first step, perceptions
                //update the agent's goals based on the state of the world


                this.SurviveGoal.InsistenceValue = this.GameManager.characterData.MaxHP - this.GameManager.characterData.HP;

                this.BeQuickGoal.InsistenceValue += DECISION_MAKING_INTERVAL * this.BeQuickGoal.ChangeRate;
                if (this.BeQuickGoal.InsistenceValue > 10.0f)
                {
                    this.BeQuickGoal.InsistenceValue = 10.0f;
                }

                this.GainLevelGoal.InsistenceValue += this.GainLevelGoal.ChangeRate; //increase in goal over time
                if (this.GameManager.characterData.Level > this.previousLevel)
                {
                    this.GainLevelGoal.InsistenceValue -= this.GameManager.characterData.Level - this.previousLevel;
                    this.previousLevel = this.GameManager.characterData.Level;
                }

                this.GetRichGoal.InsistenceValue += this.GetRichGoal.ChangeRate; //increase in goal over time
                if (this.GetRichGoal.InsistenceValue > 10)
                {
                    this.GetRichGoal.InsistenceValue = 10.0f;
                }

                if (this.GameManager.characterData.Money > this.previousGold)
                {
                    this.GetRichGoal.InsistenceValue -= this.GameManager.characterData.Money - this.previousGold;
                    this.previousGold = this.GameManager.characterData.Money;
                }



                this.SurviveGoalText.text    = "Survive: " + this.SurviveGoal.InsistenceValue;
                this.GainXPGoalText.text     = "Gain Level: " + this.GainLevelGoal.InsistenceValue.ToString("F1");
                this.BeQuickGoalText.text    = "Be Quick: " + this.BeQuickGoal.InsistenceValue.ToString("F1");
                this.GetRichGoalText.text    = "GetRich: " + this.GetRichGoal.InsistenceValue.ToString("F1");
                this.DiscontentmentText.text = "Discontentment: " + this.CalculateDiscontentment().ToString("F1");

                //initialize Decision Making Proccess
                this.CurrentAction = null;
                this.GOAPDecisionMaking.InitializeDecisionMakingProcess();
                this.MCTS.InitializeMCTSearch();
            }

            //this.UpdateDLGOAP();
            if (MCTSActive)
            {
                if (this.CurrentAction == null)
                {
                    this.UpdateMCTS();
                }
            }

            if (this.CurrentAction != null)
            {
                if (this.CurrentAction.CanExecute())
                {
                    this.CurrentAction.Execute();
                }
            }

            //call the pathfinding method if the user specified a new goal
            if (this.AStarPathFinding.InProgress)
            {
                var finished = this.AStarPathFinding.Search(out this.currentSolution);
                if (finished && this.currentSolution != null)
                {
                    //lets smooth out the Path
                    this.startPosition           = this.Character.KinematicData.position;
                    this.currentSmoothedSolution = StringPullingPathSmoothing.SmoothPath(this.Character.KinematicData.position, this.currentSolution);
                    //this.currentSolution.P
                    this.currentSmoothedSolution = this.smoothPath(this.Character.KinematicData.position, this.currentSolution);
                    this.currentSmoothedSolution.CalculateLocalPathsFromPathPositions(this.Character.KinematicData.position);
                    this.Character.Movement = new DynamicFollowPath(this.Character.KinematicData, this.currentSmoothedSolution)
                    {
                        MaxAcceleration = 200.0f,
                        MaxSpeed        = 40.0f
                    };
                }
            }


            this.Character.Update();
            //manage the character's animation
            if (this.Character.KinematicData.velocity.sqrMagnitude > 0.1)
            {
                this.characterAnimator.SetBool("Walking", true);
            }
            else
            {
                this.characterAnimator.SetBool("Walking", false);
            }
        }