#include
#include
#define N1 9
#define N2 8
#define T N1*N2
#define M 4
char B[N1+1][N2+1];
int count=0; //记录路径条数
typedef struct node1
{
int a1;
int a2;
}find,direct[M+1];
typedef struct
{
int b1;
int b2;
int id;
}site;
typedef struct //顺序栈
{
site ht[T];
int top;
}Stack;
void Push(Stack *s,int a,int b)
{ s->top++;
s->ht[s->top].b1=a;
s->ht[s->top].b2=b;
}
void Gettop(Stack * s,int *a,int *b)
{ *a=s->ht[s->top].b1;
*b=s->ht[s->top].b2;
}
void create(char *a) //从文件读出迷宫(正确)
{
int i=0,j=0,p=1;
char x;
FILE *fp;
fp=fopen("in.txt","r");
if(fp==NULL)
{ printf("文件不能打开!\n");
exit(0);
}
x=fgetc(fp);
while(x!=EOF)
{ if(x=='0')
{ i++;
a[i]=x;
}
if(x=='1')
{ i++;
a[i]=x;
}
x=fgetc(fp);
}
printf(" ~~~~~~~生成迷宫~~~~~~~\n");
x=fgetc(fp);
while(p<=T) //用二维数组b记录迷宫每个位置是否可行
{ for(i=1;i<=N1;i++)
for(j=1;j<=N2;j++)
{ B[i][j]=a[p];
p++;
}
}
printf(" ");
printf("■■■■■■■■■■■■\n");
printf(" ■");
printf(" ■\n");
for(i=1;i<=N1;i++)
{ printf(" ");
printf("■ ");
for(j=1;jht[s1->top].id=id;
B[x][y]='*';
while(s1->top>0)
{ Gettop(s1,&x,&y);
2021-12-05 16:56:13
5KB
迷宫
1