www.gusucode.com > 规则迷宫的一种求解思想及算法C++源码程序 > 规则迷宫的一种求解思想及算法/mazes/MAZES/maze.cpp

    /*
#include  "stdio.h"
#include  "mazes.h"
#include  "stdafx.h"
#include  "mazesDlg.h"
#include  "mazes.h"

  */


/*
	#define XM  601
	#define YM  401
	#define XS  0
	#define YS  201

	#define XE  600
	#define YE  201

	enum dirt{E,W,N,S};

	int flags[XM][YM];
	bool search(int x,int y,int dir);
	*/

/*
bool search(int x,int y,int dir)
{bool subway=false,noway=false,east=false,west=false,north=false,south=false;
while(!subway && !noway)
{switch(dir){
 case S:  //go to east
	x++;
	if(x==XM) noway=true;
	if(mazelab[x+1][y]){noway=true,south=false;} else south=true;
	if(y<(YM-1) && !(mazelab[x][y+1])){east=true,subway=true;}
	if(y>1 && !(mazelab[x][y-1])){west=true,subway=true;}
	break;
 case N:  //go to west
	x--;   
	if(x==0) noway=true;
	if(mazelab[x-1][y]){noway=true,north=false;} else north=true;
	if(y<(YM-1) && !(mazelab[x][y+1])){east=true,subway=true;}
	if(y>1 && !(mazelab[x][y-1])){west=true,subway=true;}
	break;
 case E:  //go to south
	 y++;
 	if(y==YM) noway=true;
	if(mazelab[x][y+1]){noway=true,east=false;} else east=true;
	if(x<(XM-1) && !(mazelab[x+1][y])){south=true,subway=true;}
 	if(x>1 && !(mazelab[x-1][y])){north=true,subway=true;}
	break;
 case W:  //go to north
	 y--;
 	if(y==0) noway=true;
	if(mazelab[x][y-1]){noway=true,west=false;} else west=true;
	if(x<(XM-1) && !(mazelab[x+1][y])){south=true,subway=true;}
 	if(x>1 && !(mazelab[x-1][y])){north=true,subway=true;}
	break;
}
}
if(x==XE && y==YE) return true; //reach exit
if(!subway && noway) return false ;  // no way to go
if(!flags[x][y]) flags[x][y]=1; else return false ; //have come here
//if(
if(subway)
{if(east)  east=search(x,y,E);
 if(west)  west=search(x,y,W);
 if(south) south=search(x,y,S);
 if(north) north=search(x,y,N);
}
 if(east)  mazelab[x][y]=-1;
 if(west)  mazelab[x][y]=-2;
 if(south) mazelab[x][y]=-3;
 if(north) mazelab[x][y]=-4;
 return (east||west||south||north) ;

}

*/