public void addExit(ExitPoint exit) { if (!hasExit(exit.x, exit.y)) { exits.Add(exit); } }
public ExitPoint(int x, int y, ExitPoint connection) { this.x = x; this.y = y; this.id = x + "," + y; this.connection = connection; }
public Dictionary <ExitPoint, List <Node> > getPaths(ExitPoint exit) { if (paths.ContainsKey(exit)) { return(paths[exit]); } return(null); }
public List <Node> getPath(ExitPoint exit1, ExitPoint exit2) { if (!paths.ContainsKey(exit1) || !paths[exit1].ContainsKey(exit2)) { return(new List <Node>()); } return(paths[exit1][exit2]); }
public Dictionary <ExitPoint, Connection> getConnections(ExitPoint exit) { if (connections.ContainsKey(exit)) { return(connections[exit]); } return(null); }
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 void addPath(ExitPoint exit1, ExitPoint exit2, List <Node> path) { if (!paths.ContainsKey(exit1)) { paths[exit1] = new Dictionary <ExitPoint, List <Node> >(); } if (!paths.ContainsKey(exit2)) { paths[exit2] = new Dictionary <ExitPoint, List <Node> >(); } paths[exit1][exit2] = path; paths[exit2][exit1] = reversePath(path); }
public void addConnection(ExitPoint exit1, ExitPoint exit2, List <Node> path) { if (!connections.ContainsKey(exit1)) { connections.Add(exit1, new Dictionary <ExitPoint, Connection>()); } if (path == null) { connections[exit1].Add(exit2, new Connection()); } else { connections[exit1].Add(exit2, new Connection(path)); } }
public bool hasConnection(ExitPoint exit1, ExitPoint exit2) { try { if (connections[exit1][exit2] != null) { return(true); } } catch (Exception e) { return(false); } return(false); }
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; } }