BFS算法迷宫
#include <iostream>
#include <string>
#include "QueueBottom.h"
#include <fstream>
using namespace std;
#include <iomanip>
#include <Windows.h>
#include <time.h>
clock_t start,finish;
void setColour(int x){
HANDLE h = GetStdHandle (-11);
SetConsoleTextAttribute(h,x);
}
int maze[100][100], past_footprint[100][100];
int dx[4] = {
0, 1, 0, -1};
int dy[4] = {
1, 0, -1, 0};
int final_array[100][100];
int printmaze[100][100];
int second_printmaze[100][100];
int whole_step;
struct point
{
int x;
int y;
int step;
};
queue<point> now_footprint;
queue<point> second_footprint;
void printMaze(int& endx, int& endy, int& startx, int& starty, int& length, int& width, string mapname)
{
ifstream first(mapname, ios::in);
if (!first.is_open())
{
cout << "Error: opening file fail" << endl;
system("pause");
exit(1);
}
while (!first.eof())
{
first >> length >> width ;
for (int i = 0; i < length; i++)
for (int j = 0; j < width; j++)
first >> maze[i][j];
first >> endx >> endy >> startx >> starty;
}
}
void findRoad(int startx, int starty, int endx, int endy, int length, int width)
{
point start;
start.x = startx;
start.y = starty;
start.step = 0;
int tag = 1;
now_footprint.push(start);
past_footprint[startx][starty] = 1;
cout << "The Map before function :" << endl;
cout << " 1 for road; 2 for wall " << endl << endl;
for(int m = 0; m < length;m++)
{
for(int n = 0; n < width;n++)
{
cout << maze[m][n] << " ";
}
cout << endl;
}
cout << endl;
int flag = 0;
while(!now_footprint.empty())
{
int x = now_footprint.front().x;
int y = now_footprint.front().y;
printmaze[x][y] = now_footprint.front().step;
whole_step = now_footprint.front().step;
if