public override void Solve(Map _map) { currentNode = _map.grid[_map.seekerX, _map.seekerY].GetComponent<Node>(); targetNode = _map.grid[_map.targetX, _map.targetY].GetComponent<Node>(); currentNode.distanceFromCharacter = 0; mapToSolve = _map; solvedNodeList = new List<Node>(); unsolvedNodeList = new List<Node>(); solvedKeyNodes = new List<Node>(); for (int x = 0; x < mapToSolve.mapWidth; x++) { for (int y = 0; y < mapToSolve.mapHeight; y++) { unsolvedNodeList.Add(mapToSolve.grid[x, y].GetComponent<Node>()); } } while (!(solvedNodeList.Contains(targetNode)) && currentNode != null) { AnalyseNeighbors(currentNode); unsolvedNodeList.Remove(currentNode); solvedNodeList.Add(currentNode); if (currentNode.nodeType == Node.Type.KEY) { solvedKeyNodes.Add(currentNode); } FindClosestUnsolvedNode(); } _map.nbrOfAnalysedTile.text = solvedNodeList.Count.ToString(); ShowShortestPath(); }
public void accessData(JSONObject obj) { floors = obj.list[0]; //this is the root for the floors JSON object nodes = obj.list[1]; //this is the root for the nodes JSON object edges = obj.list[2]; //this is the root for the edges JSON object storylines = obj.list[3]; //this is the root for the storylines JSON object floorList = populateFloors(); //parse the floors edgeList = PopulateEdges(); //parse the edges storylineList = PopulateStorylines(); //parse the storylines nodeList = populateNodes(); //parse the nodes initializePoiAndStorypointLists(); //populate the list that contains the points of interest and the other that contains storypoints createStartAndEndNode(); //transform the id's of the nodes in the edges into Node objects setAdjacencies(); //add all the adjacencies to all the nodes map = new Map(); //map.setPoiList(poiList); //map.setStorypointList(storypointList); map.setFloorplanList(floorList); map.setStorylineList(storylineList); map.initializeGraph(poiList); }
public void addNodeTest() { try { Map map = new Map(); Graph g = new Graph(); Node n1 = new PointOfInterest(1, 0, 0, 1); Node n2 = new PointOfInterest(2, 0, 0, 1); List<Node> nodeList = new List<Node>(); nodeList.Add(n1); nodeList.Add(n2); g.InsertNewVertex(n1); g.InsertNewVertex(n2); map.addNode(n1); map.addNode(n2); Graph mapGraph = map.getGraph(); List<Node> mapNodes = map.GetPoiNodes(); Assert.IsNotNull(nodeList); Assert.IsNotNull(g); Assert.IsNotNull(mapGraph); Assert.IsNotNull(mapNodes); Assert.Equals(nodeList, mapNodes); Assert.Equals(g, mapGraph); } catch (SecurityException e) { Console.WriteLine("Security Exception:\n\n{0}", e.Message); } }
public void addNodeListTest() { try { Map map = new Map(); Node n1 = new PointOfInterest(1, 0, 0, 1); Node n2 = new PointOfInterest(2, 0, 0, 1); List<Node> nodeList = new List<Node>(); nodeList.Add(n1); nodeList.Add(n2); map.setPoiList(nodeList); List<Node> mapNodes = map.GetPoiNodes(); Assert.IsNotNull(nodeList); Assert.IsNotNull(mapNodes); Assert.Equals(nodeList, mapNodes); } catch (SecurityException e) { Console.WriteLine("Security Exception:\n\n{0}", e.Message); } }
public IEnumerator startStoryline() { yield return new WaitForSeconds(0.005f); ui_Manager = FindObjectOfType<UI_Manager>(); floorManager = GameObject.Find("FloorManager"); //Storyline demo = new Storyline(0, 1, "Demo Storyline", "Let's see how good is your mobile app!"); mc = FindObjectOfType<MapController>(); map = mc.getMap(); iBeaconHandler bh = iBeaconHandler.GetComponent<iBeaconHandler>(); List<Beacon> beacons = bh.getBeacons(); int slID = PlayerPrefs.GetInt("storylineID"); DisplayFloor(2); //this should be the first floor map.initializeLists(arrayOfNodes); print("Storyline id is: " + slID); map.GetStoryline(slID).setBeaconList(beacons); map.startStoryline(map.getStorypointNodes(), slID); foreach (var sp in map.GetStoryline(slID).getStorypointList()) { print("Storypoint " + sp.id + " and is in order " + map.GetStoryline(slID).isInOrder(sp)); } /*List<Node> orderedPath = map.orderedPath(instantiatedNodes, slID); //map.setStorypointList(orderedPath); map.startStoryline(orderedPath, slID); map.GetStoryline(slID).getStorypointList()[0].setBeacon(new iBeaconServer("B9407F30-F5F8-466E-AFF9-25556B57FE6D", 38714, 26839)); POS sp = map.GetStoryline(slID).getStorypointList()[0]; sp.displayStorylinePopUpWindow(); /*print(map.GetStoryline(slID).getStorypointList().Count); foreach (var sp in map.GetStoryline(slID).getStorypointList()) { print(sp.storylineID); } /* foreach (var d in sp.GetPoiDescriptionList()) { print("Title: " + d.title + ", language: " + d.language + ", description: " + d.summary); }*/ //map.GetStoryline(slID).getStorypointList()[0].setBeacon(new iBeaconServer("B9407F30-F5F8-466E-AFF9-25556B57FE6D", 38714, 26839)); //shortestPathCreator.transform.position = new Vector3(instantiatedNodes[0].transform.position.x, instantiatedNodes[0].transform.position.y, -7); }
public override void Solve(Node _start, Node _target, Map _map, bool _realSolve) { openSet = new List<Node>(); closedSet = new HashSet<Node>(); openSet.Add(_start); while (openSet.Count > 0) { currentNode = openSet[0]; for (int i = 1; i < openSet.Count; i++) { if (openSet[i].fCost < currentNode.fCost || openSet[i].fCost == currentNode.fCost && openSet[i].hCost < currentNode.hCost) { currentNode = openSet[i]; } } openSet.Remove((currentNode)); closedSet.Add(currentNode); if (currentNode == _target) { if (_target.nodeType == Node.Type.KEY) { if (_realSolve) { nbrOfKeysAcquired++; } } else if (_target.nodeType == Node.Type.TARGET) { if (!_realSolve) { nbrOfKeysNeeded = GetNbrOfDoors(GetPath(_start, _target, false)); doorsToReachEndNode = GetDoorsToReachEndNode(GetPath(_start, _target, false)); } else { numberOfTileAnalysed += closedSet.Count; } } if (_realSolve) { finalPath.AddRange(GetPath(_start, _target, true)); } return; } foreach (Node neighbor in currentNode.neighbors) { if (neighbor.nodeType == Node.Type.OBSTACLE || closedSet.Contains(neighbor)) { continue; } int newMovementCostToNeighbour = currentNode.gCost + GetDistance(currentNode, neighbor); if (newMovementCostToNeighbour < neighbor.gCost || !openSet.Contains(neighbor)) { neighbor.gCost = newMovementCostToNeighbour; neighbor.hCost = GetDistance(neighbor, _target); neighbor.parent = currentNode; if (!openSet.Contains(neighbor)) { openSet.Add(neighbor); } } } } numberOfTileAnalysed += openSet.Count; }
//Setup public void RealSolve(Map _map) { map = _map; grid = _map.grid; listOfObjectives = new List<Node>(); finalPath = new List<Node>(); SetOrderedListOfObjectives(); }
public virtual void Solve(Map _map) { }
public virtual void Solve(Node _start, Node _target, Map _map, bool _firstSolve) { }
public void getGraphTest() { try { Map map = new Map(); Node n1 = new PointOfInterest(1, 0, 0, 1); Node n2 = new PointOfInterest(2, 0, 0, 1); map.addNode(n1); map.addNode(n2); Graph g = new Graph(); g.InsertNewVertex(n1); g.InsertNewVertex(n2); Assert.Equals(g, map.getGraph()); } catch (SecurityException e) { Console.WriteLine("Security Exception:\n\n{0}", e.Message); } }