private static int GetDistanceBetweenNodes(sNode nodeA, sNode nodeB) { int dstX = Mathf.Abs(nodeA.cell.x - nodeB.cell.x); int dstY = Mathf.Abs(nodeA.cell.y - nodeB.cell.y); return((dstX * dstX) + (dstY * dstY)); }
public sNode s() { var token = lexer.GetToken(); if (token.Id == 3 || token.Id == 2) { var text = ""; var arg0 = mul(); text += arg0.Text; var arg1 = MINUS(); text += arg1.Text; var arg2 = sub(); text += arg2.Text; var result = new sNode(text, null, arg0, arg1, arg2); result.mul = arg0; result.MINUS = arg1; result.sub = arg2; result.res = result.mul.res.Add(result.sub.res); token = lexer.GetToken(); if (token.Id != -1) { throw new ParserException("Got unxpected token from lexer"); } return(result); } throw new ParserException("Got unxpected token from lexer"); //return null }
public bool AwareExistingNode(sXYZ location, out sNode existingNode) { sNode exn = null; if (this.nodes != null && this.nodes.Count > 0) { foreach (sNode sn in this.nodes) { double dis = location.DistanceTo(sn.location); if (dis < 0.001) { exn = sn; break; } } } if (exn != null) { existingNode = exn; return(true); } else { existingNode = null; return(false); } }
public void UpdateNodeAtCell(Vector3Int cell) { if (!IsCellEmpty(cell, false)) { if (!m_Nodes.ContainsKey(cell)) { m_Nodes.Add(cell, new sNode()); } sNode node = m_Nodes[cell]; node.cell = cell; if (m_TileMaps != null && m_TileMaps.Count > 0) { bool foundTile = false; for (int i = 0; i < m_TileMaps.Count; i++) { foundTile = false; switch (m_TileMaps[i].name) { case COLLIDABLE_TILEMAP_NAME: if (m_TileMaps[i].HasTile(cell)) { node.isWalkable = false; foundTile = true; } break; case INTERACTABLE_TILEMAP_NAME: if (m_InteractableTilemap.IsTileOccupied(cell)) { node.isWalkable = true; node.price = m_InteractableNodePrice; if (cell == m_InteractableTilemap.HomeBaseCell) { node.price = 0; } foundTile = true; } break; case GROUND_TILEMAP_NAME: if (m_TileMaps[i].HasTile(cell)) { node.isWalkable = true; node.price = 1; foundTile = true; } break; } if (foundTile) { break; } } } } }
private List <sNode> GetNeighbourNodes(sNode node) { List <sNode> nodes = new List <sNode>(); foreach (Vector3Int direction in GameConstants.FOUR_DIRECTIONS) { Vector3Int cell = node.cell + direction; if (m_Nodes.ContainsKey(cell) && m_Nodes[cell].isWalkable) { nodes.Add(m_Nodes[cell]); } } return(nodes); }
public StatNode FindStatNode(sNode jn, double tol) { StatNode clnode = null; foreach (StatNode n in this.FEsystem.Nodes) { C_vector jv = new C_vector(jn.location.X, jn.location.Y, jn.location.Z); if (jv.DistanceTo(n.p) < tol) { clnode = n; break; } } return(clnode); }
public bool UpdateNodeFromPointElement(sPointLoad pl, int id) { sNode exNode; if (AwareExistingNode(pl.location, out exNode)) { exNode.UpdatePointElement(pl); return(false); } else { sNode newN = pl.TosNode(); newN.nodeID = id; //newN.elementGUID = Guid.NewGuid(); this.nodes.Add(newN); return(true); } }
private static List <Vector3Int> RetracePath(sNode startNode, sNode endNode) { List <sNode> path = new List <sNode>(); sNode currentNode = endNode; while (currentNode.cell != startNode.cell) { path.Add(currentNode); currentNode = currentNode.parentNode; } List <Vector3Int> cellPath = new List <Vector3Int>(); for (int i = path.Count - 1; i >= 0; i--) { cellPath.Add(path[i].cell); } return(cellPath); }
public sNode s() { var token = lexer.GetToken(); if (token.Id == 3 || token.Id == 2) { var text = ""; var arg0 = mul(); text += arg0.Text; var arg1 = s2(); text += arg1.Text; var result = new sNode(text, arg0, arg1); result.mul = arg0; result.s2 = arg1; token = lexer.GetToken(); if (token.Id != -1) { throw new ParserException("Got unxpected token from lexer"); } return(result); } throw new ParserException("Got unxpected token from lexer"); //return null }
public void UpdateNodeResults() { sStatConverter conv = new sStatConverter(); this.nodes.Clear(); this.nodes = new List <sNode>(); foreach (StatNode sn in this.FEsystem.Nodes) { int count = 0; sNode n = sn.ExtraData as sNode; if (n != null && sn.SupportType != BOUNDARYCONDITIONS.NONE) { if (sn.ReactionForce.Length > 0.0) { count++; n.boundaryCondition.reaction_force = conv.TosXYZ(sn.ReactionForce); } if (sn.ReactionMoment.Length > 0.0) { count++; n.boundaryCondition.reaction_moment = conv.TosXYZ(sn.ReactionMoment); } } if (n != null && n.pointLoads != null && n.pointLoads.Count > 0) { count++; } if (count > 0) { this.nodes.Add(n.DuplicatesNode()); } } }
public C_vector ToCVector(sNode jn) { return(new C_vector(jn.location.X, jn.location.Y, jn.location.Z)); }
public List <Vector3Int> FindPath(Vector3Int startPos, Vector3Int endPos) { sNode startNode = GetNodeAtCell(startPos); sNode endNode = GetNodeAtCell(endPos); List <sNode> openSet = new List <sNode>(); HashSet <sNode> closedSet = new HashSet <sNode>(); sNode currentNode; openSet.Add(startNode); while (openSet.Count > 0) { // set current node to the first node in the open set currentNode = openSet[0]; // loop through open nodes and find set the currentNode to the node with the smallest distances for (int i = 1; i < openSet.Count; i++) { if (openSet[i].fValue <= currentNode.fValue) { currentNode = openSet[i]; } } // since we are looking at this node, remove it from the open set and add it to the closed set openSet.Remove(currentNode); closedSet.Add(currentNode); // if our current node is the same as our end node, we've reached our target and can return the path if (currentNode.cell == endNode.cell) { return(RetracePath(startNode, endNode)); } // get a list of the neighbours to check List <sNode> neighbourNodes = GetNeighbourNodes(currentNode); for (int i = 0; i < neighbourNodes.Count; i++) { // if the neighbour was already checked, don't check it again if (closedSet.Contains(neighbourNodes[i])) { continue; } neighbourNodes[i].gValue = currentNode.gValue + neighbourNodes[i].price; neighbourNodes[i].hValue = GetDistanceBetweenNodes(neighbourNodes[i], endNode); neighbourNodes[i].parentNode = currentNode; // keeping this for now for debugging SINCE I CANT ATTACH VISUAL STUDIO TO UNITY FOR SOME GODDAMN REASON ASLJFIOA JGJSF //Debug.LogError("neighbour cell: " + neighbourNodes[i].cell + "\nneighbour g: " + neighbourNodes[i].gValue + "\nneighbour h: " + neighbourNodes[i].hValue + "\nneighbour price: " + neighbourNodes[i].price); if (openSet.Contains(neighbourNodes[i])) { continue; } openSet.Add(neighbourNodes[i]); } } return(null); }