public DijkstraSearchThread(NavigationGraphNode startNode, NodeGoalBounds bounds, GoalBoundsDijkstraMapFlooding dijkstra, GoalBoundingTable goalBoundingTable, int index) { this.startNode = startNode; this.bounds = bounds; this.dijkstra = dijkstra; this.goalBoundingTable = goalBoundingTable; this.index = index; }
private static void CalculateGoalBounds() { //get the NavMeshGraph from the current scene NavMeshPathGraph navMesh = GameObject.Find("Navigation Mesh").GetComponent <NavMeshRig>().NavMesh.Graph; //this is needed because RAIN AI does some initialization the first time the QuantizeToNode method is called //if this method is not called, the connections in the navigationgraph are not properly initialized navMesh.QuantizeToNode(new Vector3(0, 0, 0), 1.0f); var dijkstra = new GoalBoundsDijkstraMapFlooding(navMesh); GoalBoundingTable goalBoundingTable = new GoalBoundingTable(); var nodes = GetNodesHack(navMesh); goalBoundingTable.table = new NodeGoalBounds[nodes.Count]; NodeGoalBounds auxGoalBounds; //calculate goal bounds for each edge for (int i = 0; i < nodes.Count; i++) { if (nodes[i] is NavMeshEdge) { //initialize the GoalBounds structure for the edge auxGoalBounds = new NodeGoalBounds { connectionBounds = new Assets.Scripts.IAJ.Unity.Pathfinding.DataStructures.GoalBounding.Bounds[nodes[i].OutEdgeCount] }; for (int j = 0; j < nodes[i].OutEdgeCount; j++) { auxGoalBounds.connectionBounds[j] = new Assets.Scripts.IAJ.Unity.Pathfinding.DataStructures.GoalBounding.Bounds(); auxGoalBounds.connectionBounds[j].InitializeBounds(nodes[i].LocalPosition); } if (i % 10 == 0) { float percentage = (float)i / (float)nodes.Count; EditorUtility.DisplayProgressBar("GoalBounding precomputation progress", "Calculating goal bounds for each edge", percentage); } //run a Dijkstra mapflooding for each node dijkstra.Search(nodes[i], auxGoalBounds); goalBoundingTable.table[i] = auxGoalBounds; } } //saving the table to a binary file EditorUtility.DisplayProgressBar("GoalBounding precomputation progress", "Saving GoalBoundsTable to an Asset file", 100); goalBoundingTable.Save(Application.dataPath + "/Resources/", "GoalBoundingTable.dat"); //saving the assets, this takes forever using Unity's serialization mechanism EditorUtility.ClearProgressBar(); }
// Use this for initialization void Awake() { this.currentClickNumber = 1; GoalBoundingTable goalBoundingTable = Resources.Load("GoalBoundingTable") as GoalBoundingTable; //GoalBoundingTable goalBoundingTable = Resources.Load<GoalBoundingTable>("Assets/GoalBoundingTable.asset"); //read the goal boundings table asset //this.Initialize(NavigationManager.Instance.NavMeshGraphs[0], new AStarPathfinding(NavigationManager.Instance.NavMeshGraphs[0], new NodePriorityHeap(), new NodeHashMap(), new EuclideanHeuristic())); //this.Initialize(NavigationManager.Instance.NavMeshGraphs[0], new NodeArrayAStarPathFinding(NavigationManager.Instance.NavMeshGraphs[0], new EuclideanHeuristic())); this.Initialize(NavigationManager.Instance.NavMeshGraphs[0], new GoalBoundingPathfinding(NavigationManager.Instance.NavMeshGraphs[0], new EuclideanHeuristic(), goalBoundingTable)); }
// Use this for initialization void Awake() { BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Open("Assets/GoalBoundingData/GoalBounding.dat", FileMode.Open); GoalBoundingTable goalBoundingTable = (GoalBoundingTable)bf.Deserialize(file); file.Close(); this.currentClickNumber = 1; navMesh = NavigationManager.Instance.NavMeshGraphs[0]; this.Initialize(NavigationManager.Instance.NavMeshGraphs[0], new GoalBoundingPathfinding(NavigationManager.Instance.NavMeshGraphs[0], new EuclideanHeuristic(), goalBoundingTable)); //this.Initialize(NavigationManager.Instance.NavMeshGraphs[0], new NodeArrayAStarPathFinding(NavigationManager.Instance.NavMeshGraphs[0], new EuclideanHeuristic())); }
// Use this for initialization void Awake() { this.currentClickNumber = 1; //comentar o metodo que nao queremos usar e descomentar o que queremos usar (organizado do pior ao melhor): //AStar com Unordered List //this.Initialize(NavigationManager.Instance.NavMeshGraphs[0], new AStarPathfinding(NavigationManager.Instance.NavMeshGraphs[0], new SimpleUnorderedNodeList(), new HashtableSet(), new EuclidianDistanceHeuristic())); //AStar com PriorityHeap //this.Initialize(NavigationManager.Instance.NavMeshGraphs[0], new AStarPathfinding(NavigationManager.Instance.NavMeshGraphs[0], new NodePriorityHeap(), new HashtableSet(), new EuclidianDistanceHeuristic())); //NodeAStar //this.Initialize(NavigationManager.Instance.NavMeshGraphs[0], new NodeArrayAStarPathFinding(NavigationManager.Instance.NavMeshGraphs[0], new EuclidianDistanceHeuristic())); //GoalBounding this.goalBoundsTable = Resources.Load <GoalBoundingTable>("GoalBoundingTable"); this.Initialize(NavigationManager.Instance.NavMeshGraphs[0], new GoalBoundingPathfinding(NavigationManager.Instance.NavMeshGraphs[0], new EuclidianDistanceHeuristic(), this.goalBoundsTable)); }
// Use this for initialization void Awake() { this.currentClickNumber = 1; //first table //this.Initialize(NavigationManager.Instance.NavMeshGraphs[0], new AStarPathfinding(NavigationManager.Instance.NavMeshGraphs[0], new SimpleUnorderedNodeList(), new SimpleUnorderedNodeList(), new EuclideanDistance())); //secound table //this.Initialize(NavigationManager.Instance.NavMeshGraphs[0], new AStarPathfinding(NavigationManager.Instance.NavMeshGraphs[0], new SimpleUnorderedNodeList(), new ClosedSetDictionary(), new EuclideanDistance())); //third table //this.Initialize(NavigationManager.Instance.NavMeshGraphs[0], new AStarPathfinding(NavigationManager.Instance.NavMeshGraphs[0], new NodePriorityHeap(), new ClosedSetDictionary(), new EuclideanDistance())); //fourth table //this.Initialize(NavigationManager.Instance.NavMeshGraphs[0], new NodeArrayAStarPathFinding(NavigationManager.Instance.NavMeshGraphs[0], new EuclideanDistance())); //quinta table GoalBoundingTable goalBoundsTable = Resources.Load <GoalBoundingTable>("GoalBoundingTable"); this.Initialize(NavigationManager.Instance.NavMeshGraphs[0], new GoalBoundingPathfinding(NavigationManager.Instance.NavMeshGraphs[0], new EuclideanDistance(), goalBoundsTable)); }
public GoalBoundingPathfinding(NavMeshPathGraph graph, IHeuristic heuristic, GoalBoundingTable goalBoundsTable) : base(graph, heuristic) { this.GoalBoundingTable = goalBoundsTable; }
private static void CalculateGoalBounds() { Debug.Log("Creating goalbounds table"); DateTime startTime = DateTime.Now; //get the NavMeshGraph from the current scene NavMeshPathGraph navMesh = GameObject.Find("Navigation Mesh").GetComponent <NavMeshRig>().NavMesh.Graph; //this is needed because RAIN AI does some initialization the first time the QuantizeToNode method is called //if this method is not called, the connections in the navigationgraph are not properly initialized navMesh.QuantizeToNode(new Vector3(0, 0, 0), 1.0f); GoalBoundingTable goalBoundingTable = new GoalBoundingTable(); var nodes = GetNodesHack(navMesh); goalBoundingTable.table = new NodeGoalBounds[nodes.Count]; var dijkstra = new GoalBoundsDijkstraMapFlooding(nodes); NodeGoalBounds auxGoalBounds; //calculate goal bounds for each edge for (int i = 0; i < nodes.Count; i++) { if (nodes[i] is NavMeshEdge) { //initialize the GoalBounds structure for the edge auxGoalBounds = new NodeGoalBounds(); auxGoalBounds.connectionBounds = new Assets.Scripts.IAJ.Unity.Pathfinding.DataStructures.GoalBounding.Bounds[nodes[i].OutEdgeCount]; for (int j = 0; j < nodes[i].OutEdgeCount; j++) { auxGoalBounds.connectionBounds[j] = new Assets.Scripts.IAJ.Unity.Pathfinding.DataStructures.GoalBounding.Bounds(); auxGoalBounds.connectionBounds[j].InitializeBounds(nodes[i].Position); } if (i % 10 == 0) { float percentage = (float)i / (float)nodes.Count; EditorUtility.DisplayProgressBar("GoalBounding precomputation progress", "Calculating goal bounds for each edge", percentage); } //run a Dijkstra mapflooding for each node dijkstra.Search(nodes[i], auxGoalBounds); goalBoundingTable.table[i] = auxGoalBounds; //edgeIndex++; } } BinaryFormatter bf = new BinaryFormatter(); if (File.Exists("Assets/GoalBoundingData/GoalBounding.dat")) { File.Delete("Assets/GoalBoundingData/GoalBounding.dat"); } FileStream file = File.Create("Assets/GoalBoundingData/GoalBounding.dat"); bf.Serialize(file, goalBoundingTable); file.Close(); EditorUtility.ClearProgressBar(); TimeSpan time = DateTime.Now - startTime; Debug.Log("Duration creating goalboundtable : " + time.ToString()); }
public GoalBoundingPathfinding(NavMeshPathGraph graph, IHeuristic heuristic, GoalBoundingTable goalBoundsTable) : base(graph, heuristic) { this.GoalBoundingTable = goalBoundsTable; dikjstra = new GoalBoundsDijkstraMapFlooding(graph); }
private static void CalculateGoalBounds() { //get the NavMeshGraph from the current scene NavMeshPathGraph navMesh = GameObject.Find("Navigation Mesh").GetComponent <NavMeshRig>().NavMesh.Graph; //this is needed because RAIN AI does some initialization the first time the QuantizeToNode method is called //if this method is not called, the connections in the navigationgraph are not properly initialized navMesh.QuantizeToNode(new Vector3(0, 0, 0), 1.0f); GoalBoundingTable goalBoundingTable = ScriptableObject.CreateInstance <GoalBoundingTable>(); var nodes = GetNodesHack(navMesh); goalBoundingTable.table = new NodeGoalBounds[nodes.Count]; // List of threads to wait. List <Thread> threads = new List <Thread>(); //calculate goal bounds for each edge for (int i = 0; i < nodes.Count; i++) { if (nodes[i] is NavMeshEdge) { var dijkstra = new GoalBoundsDijkstraMapFlooding(navMesh); NodeGoalBounds auxGoalBounds; //initialize the GoalBounds structure for the edge auxGoalBounds = ScriptableObject.CreateInstance <NodeGoalBounds>(); auxGoalBounds.connectionBounds = new Assets.Scripts.IAJ.Unity.Pathfinding.DataStructures.GoalBounding.Bounds[nodes[i].OutEdgeCount]; for (int j = 0; j < nodes[i].OutEdgeCount; j++) { auxGoalBounds.connectionBounds[j] = ScriptableObject.CreateInstance <Assets.Scripts.IAJ.Unity.Pathfinding.DataStructures.GoalBounding.Bounds>(); auxGoalBounds.connectionBounds[j].InitializeBounds(nodes[i].Position); } if (i % 10 == 0) { float percentage = (float)i / (float)nodes.Count; EditorUtility.DisplayProgressBar("GoalBounding precomputation progress", "Calculating goal bounds for each edge", percentage); } //run a Dijkstra mapflooding for each node //run in a new thread: /* * dijkstra.Search(nodes[i], auxGoalBounds); * * goalBoundingTable.table[i] = auxGoalBounds; */ var searchThread = new DijkstraSearchThread(nodes[i], auxGoalBounds, dijkstra, goalBoundingTable, i); Thread t = new Thread(new ThreadStart(searchThread.Search)); threads.Add(t); t.Start(); //t.Join(); //edgeIndex++; } } foreach (Thread t in threads) { t.Join(); } //saving the assets, this takes forever using Unity's serialization mechanism goalBoundingTable.SaveToAssetDatabase(); EditorUtility.ClearProgressBar(); }
public void Start() { this.draw = true; this.navMesh = NavigationManager.Instance.NavMeshGraphs[0]; this.Character = new DynamicCharacter(this.gameObject); goalBoundsTable = Resources.Load <GoalBoundingTable>("GoalBoundingTable"); //initialize your pathfinding algorithm here! //use goalBoundingPathfinding for a more efficient algorithm this.Initialize(NavigationManager.Instance.NavMeshGraphs[0], new GoalBoundingPathfinding(NavigationManager.Instance.NavMeshGraphs[0], new EuclideanDistanceHeuristic(), goalBoundsTable)); //initialization of the GOB decision making //let's start by creating 4 main goals this.SurviveGoal = new Goal(SURVIVE_GOAL, 2.0f); this.GainXPGoal = new Goal(GAIN_XP_GOAL, 1.0f) { ChangeRate = 0.5f }; this.GetRichGoal = new Goal(GET_RICH_GOAL, 1.0f) { InsistenceValue = 2.5f, ChangeRate = 0.5f }; this.BeQuickGoal = new Goal(BE_QUICK_GOAL, 1.0f) { 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>(); 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)); } foreach (var enemy in GameObject.FindGameObjectsWithTag("Skeleton")) { this.Actions.Add(new SwordAttack(this, enemy)); this.Actions.Add(new Fireball(this, enemy)); } foreach (var enemy in GameObject.FindGameObjectsWithTag("Orc")) { this.Actions.Add(new SwordAttack(this, enemy)); this.Actions.Add(new Fireball(this, enemy)); } foreach (var enemy in GameObject.FindGameObjectsWithTag("Dragon")) { this.Actions.Add(new SwordAttack(this, enemy)); this.Actions.Add(new Fireball(this, enemy)); } this.Actions.Add(new LevelUp(this)); var worldModel = new CurrentStateWorldModel(this.GameManager, this.Actions, this.Goals); this.GOAPDecisionMaking = new DepthLimitedGOAPDecisionMaking(worldModel, this.Actions, this.Goals); //this.MCTSDecisionMaking = new MCTS(worldModel); this.MCTSDecisionMaking = new MCTSBiasedPlayout(worldModel); //this.MCTSDecisionMaking.MaxIterations = 500; //this.MCTSDecisionMaking.MaxIterationsProcessedPerFrame = 100; }
public void Start() { this.draw = true; this.navMesh = NavigationManager.Instance.NavMeshGraphs[0]; this.Character = new DynamicCharacter(this.gameObject); //Goal Bounding Node Array A*, EuclideanDistanceHeuristic var goalBoundsTable = GoalBoundingTable.Load(Application.dataPath + "/Resources/", "GoalBoundingTable.dat"); this.Initialize(NavigationManager.Instance.NavMeshGraphs[0], new GoalBoundingPathfinding(NavigationManager.Instance.NavMeshGraphs[0], new EuclideanDistanceHeuristic(), goalBoundsTable)); //initialization of the GOB decision making //let's start by creating 4 main goals this.SurviveGoal = new Goal(SURVIVE_GOAL, 2.0f); this.GainXPGoal = new Goal(GAIN_XP_GOAL, 1.0f) { ChangeRate = 0.1f }; this.GetRichGoal = new Goal(GET_RICH_GOAL, 1.0f) { InsistenceValue = 5.0f, ChangeRate = 0.2f }; this.BeQuickGoal = new Goal(BE_QUICK_GOAL, 1.0f) { ChangeRate = 0.1f }; this.Goals = new List <Goal> { this.SurviveGoal, this.BeQuickGoal, this.GetRichGoal, this.GainXPGoal }; //initialize the available actions this.Actions = new List <Action> { new LevelUp(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)); } foreach (var enemy in GameObject.FindGameObjectsWithTag("Skeleton")) { this.Actions.Add(new SwordAttack(this, enemy)); this.Actions.Add(new Fireball(this, enemy)); } foreach (var enemy in GameObject.FindGameObjectsWithTag("Orc")) { this.Actions.Add(new SwordAttack(this, enemy)); this.Actions.Add(new Fireball(this, enemy)); } foreach (var enemy in GameObject.FindGameObjectsWithTag("Dragon")) { this.Actions.Add(new SwordAttack(this, enemy)); this.Actions.Add(new Fireball(this, enemy)); } this.InitialState = new CurrentStateWorldModel(this.GameManager, this.Actions, this.Goals); // Select Decision-Making Algorithm //this.DecisionMaking = new DepthLimitedGOAPDecisionMaking(this.InitialState, this.Actions,this.Goals); //this.DecisionMaking = new MCTS(this.InitialState); this.DecisionMaking = new MCTSBiasedPlayout(this.InitialState, new PropertyWeightedSumHeuristic()); }