private static int DFS(Node Start) { if (Start.getGoal()) { MessageBox.Show("Stigli smo do cilja, ura!"); return(1); } else { int k = 0; Start.mark(); Start.getButton().Visible = false; Start.getButton().Visible = true; System.Threading.Thread.Sleep(10); Start.getButton().BackColor = Color.Blue; Node[] Neighbours = getUnmarkedNeighbours(Start, false); while (Neighbours[k] != null) { if (!Neighbours[k].isMarked() && !Neighbours[k].isBarrier()) { if (DFS(Neighbours[k]) == 1) { // Neighbours[k].getButton().BackColor = Color.Orange; return(1); } } k++; } return(0); } }
} //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); }