/** * Gets a list of successor nodes for a specified node. * Each successor node's parent is set to the speified node. * * @param node The node to get successors for. */ private List<Node> getSuccessors(Node node) { List<Node> successors = new List<Node>(); for (int i = 0; i < BORDER_NODES.Length; i++) { Vector2 pos = node.getPosition() + BORDER_NODES[i]; Node n = getNode((int)pos.X, (int)pos.Y); if (n != null && canMove(node, n)) { n.setParent(node); successors.Add(n); } } return successors; }
/** * Determines if it is possible to move between two adjacent nodes. * * @param a The first node. * @param b The second node. * @return True if it is possible to move from a to b. */ private bool canMove(Node a, Node b) { Vector2 posA = a.getPosition(); Vector2 posB = b.getPosition(); float diff = Math.Abs(scaledHeightMap[(int)posA.X, (int)posA.Y] - scaledHeightMap[(int)posB.X, (int)posB.Y]); return diff <= MAX_MOVE_DIST; }