#include <iostream>
#include <stdio.h>
using namespace std;
int ei=6,ej=6;
int maze[8][8]={{1,1,1,1,1,1,1,1},
{1,0,0,0,1,0,0,1},
{1,1,1,0,0,0,1,1},
{1,0,0,1,1,0,0,1},
{1,1,0,0,0,0,1,1},
{1,1,0,1,0,0,0,1},
{1,0,0,1,1,0,0,1},
{1,1,1,1,1,1,1,1}};
int vi(int i,int j)
{
int suc = 0;
maze[i][j] = 2;
if (i == ei && j == ej)
suc = 1;
if (suc != 1 && maze[i][j+1] == 0)
suc = vi(i,j+1);
if (suc != 1 && maze[i+1][j] == 0)
suc = vi(i+1,j);
if (suc != 1 && maze[i][j-1] == 0)
suc = vi(i,j-1);
if (suc != 1 && maze[i-1][j] == 0)
suc = vi(i-1,j);
if (suc != 1)
maze[i][j] = 0;
return suc;
}
int main(void)
{
int i,j,si,sj;
cout <<"請輸入出發點的x座標(0-7):\n";
cin >> si;
cout <<"請輸入出發點的y座標(0-7):\n";
cin >> sj;
cout <<"迷宮出發前:\n";
for (i=0;i<8;i++)
{
for (j=0;j<8;j++)
{
if (maze[i][j] == 1)
cout <<"●";
else
cout <<" ";
}
cout <<"\n";
}
if (vi(si,sj) != 1)
cout <<"沒有找到出口!"<<endl;
else
{
cout <<"迷宮走的路線:\n";
for (i=0;i<8;i++)
{
for(j=0;j<8;j++)
{
if (maze[i][j] == 1)
cout <<"●";
else if(maze[i][j] == 2)
cout <<"◎";
else
cout <<" ";
}
cout <<"\n";
}
}
return 0;
}