有关于迷宫算法的帖子吗?

yangyinbo 2007-06-02 08:06:18
有关于迷宫算法的帖子吗?
数据结构的
...全文
357 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
juanjuanningning 2009-02-18
  • 打赏
  • 举报
回复
能把你的思路说清楚一点吗?
yangyinbo 2007-06-04
  • 打赏
  • 举报
回复
我是用一个字符数组先定义好了迷宫
书上的算法,我没明白,写了这么多:
#include<stdio.h>
#include<math.h>
#include<string.h>
#define length sizeof(struct mazepath)
typedef struct mazepath{
int ord;
char seat[100];
int di;
struct mazepath *next;
};
main()
{
int curstep,i,j,k,n,m;
char footprint, curpos;
struct mazepath *head,*stack;
char map[10][10]={{'#','#','#','#','#','#','#','#','#','#'},
{'#','1','1','#','1','1','1','#','1','#'},
{'#','1','1','#','1','1','1','#','1','#'},
{'#','1','1','1','1','#','#','1','1','#'},
{'#','1','#','#','#','1','1','1','1','#'},
{'#','1','1','1','#','1','1','1','1','#'},
{'#','1','#','1','1','1','#','1','1','#'},
{'#','1','#','#','#','1','#','#','1','#'},
{'#','#','1','1','1','1','1','1','1','#'},
{'#','#','#','#','#','#','#','#','#','#'}};
footprint='0';
head=NULL;
stack=(struct mazepath *)malloc(length);
printf("The map:\n");
for(n=0;n<10;n++)
for(m=0;m<10;m++){printf("%c",map[n][m]);
if(m==9)printf("\n");
}
curstep=1;
i=0;
j=1;k=1;
curpos=map[j][k];
do{
if(curpos=='1')
{curpos=footprint;
stack->ord=curstep;
stack->seat[i++]=curpos;
stack->di=1;
stack->next=head;
stack=head; /*将当前的通道块入栈*/
if(curpos==map[9][9])getch();/*是否到所设终点*/
else {curpos=map[j][k++];
curstep++;
}
}
else {if(stack!=NULL){head=head->next;
free(head);}
while(stack->di==4&&stack!=NULL){curpos='#';
head=head->next;
free(head);
}
if(stack->di<4){
stack->di++;
stack->ord=curstep;
stack->seat[i++]=curpos;
stack->di=1;
stack->next=head;
stack=head; /*将当前的通道块入栈*/
curpos=map[j++][k++];
}


}


}while(stack!=NULL);
printf("The path:\n");
do{printf("%s",stack->seat);
head=head->next;}while(stack!=NULL);
}



主要问题晚不能明白怎么在地图上找其它的可同方块!!!
谢谢!能指点一下吗?

celftj 2007-06-04
  • 打赏
  • 举报
回复

15,440

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧