public static MazeGraph <T> Execute(MazeGraph <T> G) { InitializeVariables(G); for (int i = 0; i < g.rows; ++i) { List <int> group = new List <int>(); for (int j = 0; j < g.cols; ++j) { group.Add(j); if (!(j < g.cols - 1) || ((i < g.rows - 1) && rand.Next(2) == 0)) { int connectAt = group[rand.Next(0, group.Count)]; g.addEdge(g.GetNode(i, connectAt), g.GetNode(i + 1, connectAt), default(T)); g.addEdge(g.GetNode(i + 1, connectAt), g.GetNode(i, connectAt), default(T)); group.Clear(); } else { g.addEdge(g.GetNode(i, j), g.GetEast(i, j), default(T)); g.addEdge(g.GetEast(i, j), g.GetNode(i, j), default(T)); } } } return(g); }
private static void DivideVertically(int row, int col, int height, int width) { int divideCell = rand.Next(width - 1); int passage_at = rand.Next(height); for (int i = 0; i < height; ++i) { if (i != passage_at) { int r = row + i; int c = col + divideCell; int node = g.GetNode(r, c); int eastnode = g.GetEast(r, c); g.removeEdge(node, eastnode); g.removeEdge(eastnode, node); } } Divide(row, col, height, divideCell + 1); Divide(row, col + divideCell + 1, height, width - divideCell - 1); }