bool AgentEvade(MazeNode node, MazeNode evadeNode, int depth, int distance = 50, EvadeUseMode mode = EvadeUseMode.display) { if (depth >= distance) { ClearNodesSearched(); return true; } List<MazeNode> nodes = new List<MazeNode>(node.currentConnections); List<MazeNode> inOrder = new List<MazeNode>(); while (nodes.Count > 0) { MazeNode bestNode = nodes[0]; float largestDist; if (nodes[0] != null) { largestDist = GetHeuristic(nodes[0], evadeNode, AStarMode.randomEuclidian, searchRandom); } else { largestDist = 0f; } for (int i = 1; i < nodes.Count; i++) { if (nodes[i] == null) { continue; } if (nodes[i].searched) { continue; } float dist = GetHeuristic(nodes[i], evadeNode, AStarMode.randomEuclidian, searchRandom); if (dist > largestDist) { largestDist = dist; bestNode = nodes[i]; } } if (bestNode != null) { inOrder.Add(bestNode); nodes.Remove(bestNode); } else { break; } } foreach (MazeNode n in inOrder) { n.searched = true; if (debugColors && mode == EvadeUseMode.display) { n.floorRenderer.material = debugGreen; } bool endFound = AgentEvade(n, evadeNode, depth + 1, distance, mode); if (endFound) { if (depth + 1 >= distance) { if (mode == EvadeUseMode.wallPlacement) { if (!PlaceWall(node, n)) { endFound = false; continue; } else { if (debugColors) { node.GetLinkToNode(n).cubeRenderer.material = debugMagenta; } } } } return true; } } return false; }