Пример #1
0
 public MCTS(PropertyArrayWorldModel currentStateWorldModel)
 {
     this.InProgress                     = false;
     this.CurrentStateWorldModel         = currentStateWorldModel;
     this.PlayoutIterations              = 5;
     this.MaxIterationsProcessedPerFrame = 1000;
     this.RandomGenerator                = new System.Random();
 }
Пример #2
0
 public MCTSBiasedPlayout(PropertyArrayWorldModel currentStateWorldModel) : base(currentStateWorldModel)
 {
 }
        public void Start()
        {
            this.draw = true;

            this.navMesh   = NavigationManager.Instance.NavMeshGraphs[0];
            this.Character = new DynamicCharacter(this.gameObject);

            //initialize your pathfinding algorithm here!
            //use goalBoundingPathfinding for a more efficient algorithm
            //this.Initialize(NavigationManager.Instance.NavMeshGraphs[0], new NodeArrayAStarPathFinding(NavigationManager.Instance.NavMeshGraphs[0], new EucledianDistanceHeuristic()));
            this.Initialize(NavigationManager.Instance.NavMeshGraphs[0], new GoalBoundingPathfinding(NavigationManager.Instance.NavMeshGraphs[0], new EucledianDistanceHeuristic(), AssetDatabase.LoadAssetAtPath <Assets.Scripts.IAJ.Unity.Pathfinding.DataStructures.GoalBounding.GoalBoundingTable>("Assets/Resources/GoalBoundingTable.asset")));

            //initialization of the GOB decision making
            //let's start by creating 4 main goals

            this.SurviveGoal = new Goal(SURVIVE_GOAL, 0.2f, 0);

            this.GainXPGoal = new Goal(GAIN_XP_GOAL, 0.1f, 1)
            {
                ChangeRate = 0.1f
            };

            this.GetRichGoal = new Goal(GET_RICH_GOAL, 0.1f, 2)
            {
                InsistenceValue = 5.0f,
                ChangeRate      = 0.2f
            };

            this.BeQuickGoal = new Goal(BE_QUICK_GOAL, 8.0f, 3)
            {
                ChangeRate = 0.1f
            };

            this.Goals = new List <Goal>();
            this.Goals.Add(this.SurviveGoal);
            this.Goals.Add(this.BeQuickGoal);
            this.Goals.Add(this.GetRichGoal);
            this.Goals.Add(this.GainXPGoal);

            //initialize the available actions

            this.Actions = new List <Action>();

            this.Actions.Add(new ShieldOfFaith(this));
            this.Actions.Add(new LayOnHands(this));

            foreach (var chest in GameObject.FindGameObjectsWithTag("Chest"))
            {
                this.Actions.Add(new PickUpChest(this, chest));
            }

            foreach (var potion in GameObject.FindGameObjectsWithTag("ManaPotion"))
            {
                this.Actions.Add(new GetManaPotion(this, potion));
            }

            foreach (var potion in GameObject.FindGameObjectsWithTag("HealthPotion"))
            {
                this.Actions.Add(new GetHealthPotion(this, potion));
            }

            GameObject[] skeletons = GameObject.FindGameObjectsWithTag("Skeleton");
            foreach (var enemy in skeletons)
            {
                this.Actions.Add(new SwordAttack(this, enemy));
                this.Actions.Add(new DivineSmite(this, enemy));
            }

            GameObject[] orcs = GameObject.FindGameObjectsWithTag("Orc");
            foreach (var enemy in orcs)
            {
                this.Actions.Add(new SwordAttack(this, enemy));
            }

            GameObject[] dragons = GameObject.FindGameObjectsWithTag("Dragon");
            foreach (var enemy in dragons)
            {
                this.Actions.Add(new SwordAttack(this, enemy));
            }

            List <GameObject> allEnemies = new List <GameObject>();

            allEnemies.AddRange(skeletons);
            allEnemies.AddRange(orcs);
            allEnemies.AddRange(dragons);

            GameManager.enemies = allEnemies;

            this.Actions.Add(new DivineWrath(this, allEnemies));

            var worldModel = new PropertyArrayWorldModel(this.GameManager, this.Actions);

            if (MCTSActive)
            {
                //this.MCTS = new MCTS(worldModel);
                this.MCTS = new MCTSBiasedPlayout(worldModel);
                this.MCTS.autonomousCharacter = this;
            }
            else
            {
                this.GOAPDecisionMaking = new DepthLimitedGOAPDecisionMaking(worldModel, this.Actions, this.Goals);
            }
        }
 public DepthLimitedGOAPDecisionMaking(PropertyArrayWorldModel currentStateWorldModel, List <Action> actions, List <Goal> goals)
 {
     this.ActionCombinationsProcessedPerFrame = 300;
     this.Goals             = goals;
     this.InitialWorldModel = currentStateWorldModel;
 }