private void makeMiddleExitHorizontal(Cluster cluster1, Cluster cluster2, ClusterMap clusters) { var map = clusters.getMap(); int w = cluster1.width; int y = cluster1.top; int firstOpenLeft = -1; int firstOpenRight = -1; //go right from middle first; for (int x = cluster1.left + w / 2; x < cluster1.left + w; ++x) { //if there is an exit available on both clusters if (map.isOpen(x, y) && map.isOpen(x, y - 1)) { firstOpenRight = x; break; } } //go left from middle next; for (int x = cluster1.left + (w / 2) - 1; 0 < x; --x) { //if there is an exit available on both clusters if (map.isOpen(x, y) && map.isOpen(x, y - 1)) { firstOpenLeft = x; break; } } int selectedX = 0; if (firstOpenLeft + firstOpenRight == -2) { return; } else if (firstOpenLeft == -1) { selectedX = firstOpenRight; } else if (firstOpenRight == -1) { selectedX = firstOpenLeft; } else { selectedX = (Math.Abs(firstOpenRight) < Math.Abs(firstOpenLeft)) ? firstOpenRight : firstOpenLeft; //compare which side is closest to middle } var exit1 = new ExitPoint(selectedX, y); exit1.connection = new ExitPoint(selectedX, y - 1, exit1); cluster1.addExit(exit1); cluster2.addExit(exit1.connection); }
private void makeMiddleExitVertical(Cluster cluster1, Cluster cluster2, ClusterMap clusters) { var map = clusters.getMap(); int h = cluster1.height; int x = cluster1.left; int firstOpenTop = -1; int firstOpenBottom = -1; //go top from middle first; for (int y = cluster1.top + h / 2; y < cluster1.top + h; ++y) { //if there is an exit available on both clusters if (map.isOpen(x, y) && map.isOpen(x - 1, y)) { firstOpenBottom = y; break; } } //go bottom from middle next; for (int y = cluster1.top + (h / 2) - 1; 0 < y; --y) { //if there is an exit available on both clusters if (map.isOpen(x, y) && map.isOpen(x - 1, y)) { firstOpenTop = y; break; } } int selectedY = 0; if (firstOpenTop + firstOpenBottom == -2) { return; } else if (firstOpenTop == -1) { selectedY = firstOpenBottom; } else if (firstOpenBottom == -1) { selectedY = firstOpenTop; } else { selectedY = (Math.Abs(firstOpenBottom) < Math.Abs(firstOpenTop)) ? firstOpenBottom : firstOpenTop; //compare which side is closest to middle } var exit1 = new ExitPoint(x, selectedY); exit1.connection = new ExitPoint(x - 1, selectedY, exit1); cluster1.addExit(exit1); cluster2.addExit(exit1.connection); }
public List<Node> findPath(Node start, Node end) { Cluster startCluster; Cluster endCluster; //first find which are our start and endClusters findEndClusters(start, end, out startCluster, out endCluster); //if we start and end in the same cluster, check if we can get a path without leaving the cluster if(startCluster == endCluster) { var simplePath = new SimplePathfinding(); var path = simplePath.SimplePath(clusterMap.getMap(), int.MaxValue, start, end, startCluster); if (path != null) return path; } return null; }
private void makeExitVertical(Cluster cluster1, Cluster cluster2, ClusterMap clusters, int direction) { var map = clusters.getMap(); int h = cluster1.height; int x = cluster1.left; int y = (direction >= 0) ? cluster1.top : cluster1.top + h - 1; //go right until we find the first spot while (Math.Abs(y - cluster1.top + h / 2) != 0) { if (map.isOpen(x, y) && map.isOpen(x - 1, y)) { var exit1 = new ExitPoint(x, y); exit1.connection = new ExitPoint(x - 1, y, exit1); cluster1.addExit(exit1); cluster2.addExit(exit1.connection); return; } y += direction; } }
private void makeExitHorizontal(Cluster cluster1, Cluster cluster2, ClusterMap clusters, int direction) { var map = clusters.getMap(); int w = cluster1.width; int y = cluster1.top; int x = (direction >= 0) ? cluster1.left : cluster1.left + w - 1; //go right until we find the first spot while (Math.Abs(x - cluster1.left + w / 2) != 0) { if (map.isOpen(x, y) && map.isOpen(x, y - 1)) { var exit1 = new ExitPoint(x, y); exit1.connection = new ExitPoint(x, y - 1, exit1); cluster1.addExit(exit1); cluster2.addExit(exit1.connection); return; } x += direction; } }