static void Main(string[] args) { Node tree = createTree(); Console.WriteLine("================DFS============="); DFS.dfsTraversal(tree); }
public static void Main(string[] args) { map = new int[10, 10] { // 初始的map_maze { 1, 0, 3, 3, 3, 3, 3, 0, 3, 3 }, { 0, 0, 0, 0, 0, 0, 0, 0, 3, 0 }, { 0, 0, 0, 3, 0, 0, 3, 3, 3, 0 }, { 3, 0, 0, 0, 0, 3, 0, 0, 0, 0 }, { 0, 0, 0, 0, 3, 0, 0, 0, 0, 0 }, { 3, 0, 0, 0, 3, 0, 0, 3, 0, 3 }, { 3, 0, 0, 0, 0, 3, 3, 0, 0, 0 }, { 0, 0, 2, 0, 0, 0, 0, 0, 0, 0 }, { 3, 3, 3, 0, 0, 3, 0, 3, 0, 3 }, { 3, 0, 0, 0, 0, 3, 3, 3, 0, 3 }, }; getMapStrings(); BFS.InitMap(map); List <Node> passNodes = new List <Node>(); int startX, startY; int endX, endY; getPoint(1, out startX, out startY); getPoint(2, out endX, out endY); Node start = new Node(startX, startY, map[startX, startY]); Node end = new Node(endX, endY, map[endX, endY]); BFS.Search(start, end, ref passNodes); Console.WriteLine("\n === BFS 寻路结束 === " + (passNodes.Count > 0)); Console.WriteLine("一共有 " + passNodes.Count + " 个中间节点"); for (int i = 0; i < passNodes.Count; i++) { int x = passNodes[i].X; int y = passNodes[i].Y; map[x, y] = 8; } PrintMapData(); getMapStrings(); /* * map = new int[10,10]{ // 初始的map_maze * { 1, 0, 0, 3, 0, 3, 0, 0, 0, 0 }, * { 0, 0, 3, 0, 0, 3, 0, 3, 0, 3 }, * { 3, 0, 0, 0, 0, 3, 3, 3, 0, 3 }, * { 3, 0, 3, 0, 0, 0, 0, 0, 0, 3 }, * { 3, 0, 0, 2, 0, 3, 0, 3, 0, 3 }, * { 3, 0, 0, 3, 0, 0, 0, 3, 0, 3 }, * { 3, 0, 3, 0, 0, 3, 3, 0, 0, 0 }, * { 0, 0, 3, 0, 0, 0, 0, 0, 0, 0 }, * { 3, 3, 3, 0, 0, 3, 0, 3, 0, 3 }, * { 3, 0, 0, 0, 0, 3, 3, 3, 0, 3 }, * }; */ map = new int[10, 10] { // 初始的map_maze { 1, 0, 3, 3, 3, 3, 3, 0, 3, 3 }, { 0, 0, 0, 0, 0, 0, 0, 0, 3, 0 }, { 0, 0, 0, 3, 0, 0, 3, 3, 3, 0 }, { 3, 0, 0, 0, 0, 3, 0, 0, 0, 0 }, { 0, 0, 0, 0, 3, 0, 0, 0, 0, 0 }, { 3, 0, 0, 0, 3, 0, 0, 3, 0, 3 }, { 3, 0, 0, 0, 0, 3, 3, 0, 0, 0 }, { 0, 0, 2, 0, 0, 0, 0, 0, 0, 0 }, { 3, 3, 3, 0, 0, 3, 0, 3, 0, 3 }, { 3, 0, 0, 0, 0, 3, 3, 3, 0, 3 }, }; Console.WriteLine("DFS开始======================================"); PrintMapData(); getMapStrings(); DFS.InitMap(map); passNodes.Clear(); getPoint(1, out startX, out startY); getPoint(2, out endX, out endY); start = new Node(startX, startY, map[startX, startY]); end = new Node(endX, endY, map[endX, endY]); DFS.Search(start, end, ref passNodes); Console.WriteLine("\n === DFS 寻路结束 === " + (passNodes.Count > 0)); Console.WriteLine("一共有 " + passNodes.Count + " 个中间节点"); for (int i = 0; i < passNodes.Count; i++) { int x = passNodes[i].X; int y = passNodes[i].Y; Console.Write(x + "," + y + " "); map[x, y] = 8; } PrintMapData(); getMapStrings(); }