在今天早上的时候,我还到处“求医问药”希望能解决程序中未能解决的问题,郁闷了一天,总算是明白问题是出在什么地方的了。好了,还是先将迷宫算法的解决算法发上来,之后再讨论之前的问题出在什么地方,又是怎样解决的。
迷宫算法如下:
//#############################################################//
//在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位置为迷宫中可以走的位置