设为首页 加入收藏

TOP

A*算法实现迷宫最短路径搜索(C++实现)
2014-11-18 18:53:13 】 浏览:9671
Tags:算法 实现 迷宫 路径 搜索

  在今天早上的时候,我还到处“求医问药”希望能解决程序中未能解决的问题,郁闷了一天,总算是明白问题是出在什么地方的了。好了,还是先将迷宫算法的解决算法发上来,之后再讨论之前的问题出在什么地方,又是怎样解决的。


  迷宫算法如下:


  //#############################################################//


  //在VC6及vs2005里面都没有调试通过,在MinGW Developer Studio和gCC里面调试通过


  #include


  #include


  #include


  #include


  #include


  using namespace std;


  #define MAZE_ROW 9


  #define MAZE_COL 7


  char maze[MAZE_ROW][MAZE_COL]={


  ' ',' ',' ','#','#','#','#',


  '#','#',' ','#','#','#','#',


  ' ','#',' ','#','#','#','#',


  ' ','#',' ',' ',' ',' ',' ',


  ' ',' ','#','#','#','#',' ',


  '#',' ',' ',' ',' ','#',' ',


  '#','#',' ','#',' ','#',' ',


  ' ',' ',' ',' ','#','#',' ',


  ' ',' ','#',' ',' ','#',' ',


  };


  typedef struct {


  int gn;


  int fn;


  int flag; //1――in open; 2――in close


  }GFN;


  map gmap; //g值


  int Bi=0, Bj=0;


  int Ei=6, Ej=6;


  bool opensort(int n1,int n2)


  {


  map ::iterator pos1,pos2;


  pos1 = gmap.find(n1);


  pos2 = gmap.find(n2);


  return pos1->second->fn < pos2->second->fn;


  }


  void getway(int i,int j,int gn); //输出路径


  void printmaze();


  void printway();


  bool isok(int i,int j);//判断n1位置为迷宫中可以走的位置


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇C++内部链接与外部链接 下一篇根据HKey查找当前打开的注册表路径

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目