Пример #1
0
        private static bool Search(bool[,] graph, bool[,] visited, Cell current, Cell end)
        {
            if (current.X == end.X && current.Y == end.Y)
            {
                return(true);
            }

            for (int i = 0; i < 4; i++)
            {
                int x = current.X + Deltas[i];
                int y = current.Y + Deltas[i + 1];

                if (x < 0 || x >= visited.GetLength(0))
                {
                    continue;
                }

                if (y < 0 || y >= visited.GetLength(0))
                {
                    continue;
                }

                if (visited[x, y] || !graph[x, y])
                {
                    continue;
                }

                visited[x, y] = true;

                if (SearchMaze.Search(graph, visited, new Cell {
                    X = x, Y = y
                }, end))
                {
                    return(true);
                }
            }

            return(false);
        }
Пример #2
0
 private static bool DFS(bool[,] graph, Cell start, Cell end)
 {
     bool[,] visited = new bool[graph.GetLength(0), graph.GetLength(1)];
     return(SearchMaze.Search(graph, visited, start, end));
 }