private static unsafe bool SearchForPath(int2 currentNode, int2 targetNode, NativeArray2D <MapNode> gridCopy) { MapNode *currentNodePtr = gridCopy.GetPointerToElement(currentNode); NativeList <MapNode> passableNeighbours = GetPassableNeighbours(currentNode, gridCopy, currentNodePtr); NodeCompare nodeCompare = new NodeCompare(); passableNeighbours.Sort(nodeCompare); currentNodePtr->state = NodeState.Closed; for (int i = 0; i < passableNeighbours.Length; ++i) { MapNode neighbour = passableNeighbours[i]; currentNodePtr->child = gridCopy.GetPointerToElement(neighbour.gridPosition); //Target has been reached. if (neighbour.gridPosition.Equals(targetNode)) { passableNeighbours.Dispose(); return(true); } //Recursively search deeper. if (SearchForPath(neighbour.gridPosition, targetNode, gridCopy)) { passableNeighbours.Dispose(); return(true); } } passableNeighbours.Dispose(); return(false); }
private static List <NodeCompare> ExtractNodeCompare(MyNode node, string[] attrs, string containerXML) { List <NodeCompare> attrsValues = new List <NodeCompare>(); if (node.ExecutationState.Xml == null) { return(attrsValues); } IEnumerable <XElement> elements; if (!string.IsNullOrEmpty(containerXML)) { elements = node.ExecutationState.Xml.Descendants(containerXML).Descendants().Distinct(); } else { elements = node.ExecutationState.Xml.Descendants().Distinct(); } foreach (XElement e in elements) { for (int i = 0; i < attrs.Length; i++) { if (e.Attribute(attrs[i]) != null && e.Attribute(attrs[i]).Value.Trim() != "") { string[] words = e.Attribute(attrs[i]).Value.Trim().Split(' ').Select(w => w.ToLower()).ToArray(); foreach (string word in words) { if (!string.IsNullOrEmpty(word.Trim())) { NodeCompare n = attrsValues.Find(w => w.WordInNode == word); if (n.Qtd > 0) { n.Qtd++; } else { NodeCompare v = new NodeCompare() { WordInNode = word, Qtd = 1 }; attrsValues.Add(v); } } } } } } return(attrsValues); }
public Node[] shortestWay(Node objectif, Node start) { NodeCompare nc = new NodeCompare(); /*List<Node> sort = new List<Node> (); * sort.Add (new Node (5, 6, 0, 1)); * sort.Add (new Node (5, 7, 0, 2)); * sort.Sort (nc);*/ Node[] nodeF = new Node[1]; nodeF [0] = new Node(0, 0, 0); List <Node> closedList = new List <Node> (); List <Node> openList = new List <Node> (); openList.Add(start); openList.Sort(nc); while (openList.Count != 0) { Node u = openList [0]; openList.RemoveAt(0); if (u.x == objectif.x && u.y == objectif.y && u.z == objectif.z) { nodeF = new Node[u.cost + 1]; nodeF = reconstitutePath(closedList, objectif, u.cost); break; } else { foreach (Vector3 v in voisin) { if (v.x + u.x >= start.x - vision && v.x + u.x <= start.x + vision && v.y + u.y >= start.y - Mathf.FloorToInt(vision / 2) && v.y + u.y <= start.y + Mathf.FloorToInt(vision / 2) && v.z + u.z >= start.z - vision && v.z + u.z <= start.z + vision) { if (graphVerity [(int)v.x + u.x - start.x + vision, (int)v.y + u.y - start.y + Mathf.FloorToInt(vision / 2), (int)v.z + u.z - start.z + vision]) { Node vnode = new Node((int)v.x + u.x, (int)v.y + u.y, (int)v.z + u.z, u.cost + 1, (int)u.cost + 1 + Mathf.FloorToInt(Mathf.Sqrt(Mathf.Pow(u.x + v.x - objectif.x, 2) + Mathf.Pow(u.y + v.y - objectif.y, 2) + Mathf.Pow(u.z + v.z - objectif.z, 2)))); if (nodeExistAndHasSmallCost(vnode, openList) && nodeExistAndHasSmallHeuristic(vnode, closedList)) { deleteDuplicateNode(vnode.x, vnode.y, vnode.z, openList); openList.Add(vnode); openList.Sort(nc); } } } } } closedList.Add(u); } /*int[,] tab = new int[2 * vision + 1, 2 * vision + 1]; * * for (int x = 0; x < 2 * vision + 1; x++) { * for (int y = 0; y < 2 * vision + 1; y++) { * tab [x, y] = -1; * } * } * * foreach (Node n in closedList) { * if(tab [n.x - start.x + vision, n.z - start.z + vision] == -1 || tab [n.x - start.x + vision, n.z - start.z + vision] > n.heuristic) * tab [n.x - start.x + vision, n.z - start.z + vision] = n.heuristic; * } * * string lines = ""; * string lines2 = ""; * * for (int x = 0; x < 2 * vision + 1; x++) { * for (int y = 0; y < 2 * vision + 1; y++) { * if (graphVerity [x, y]) { * if (tab [x, y] < 10 && tab [x, y] >= 0) * lines += " " + tab [x, y] + ", "; * else * lines += tab [x, y] + ", "; * } * else * lines += "-5, "; * } * lines += "\r\n"; * } * * System.IO.StreamWriter file = new System.IO.StreamWriter("closedList.txt"); * file.WriteLine(lines); * * file.Close();*/ return(nodeF); }