} //some other time perhaps private static int MazeGenDFS(Node Start) { bool ret = true; for (int i = 0; i < HEIGHT; i++) { for (int j = 0; j < WIDTH; j++) { if (!Graph[i, j].isMarked()) { ret = false; } } } if (ret) { return(0); } Node[] Neighbours = getUnmarkedNeighbours(Start, false).Where(c => c != null && !c.isBarrier()).ToArray(); bool NeighboursLeft = true; Random R = new Random(); Start.mark(); Start.toggleBarrier(); while (NeighboursLeft && Neighbours.Length > 0) { NeighboursLeft = false; int index = R.Next() % Neighbours.Length; while (Neighbours[index].isBarrier()) { index = R.Next() % Neighbours.Length; } if (MazeGenDFS(Neighbours[index]) == 1) { return(1); } for (int i = 0; i < Neighbours.Length; i++) { if (!Neighbours[i].isBarrier()) { NeighboursLeft = true; } } } return(0); }