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

时间:2008-05-12 11:48:04   来源:论坛整理  作者:  编辑:chinaitzhe
有关于迷宫算法的帖子吗?
数据结构的
网友回复:有
网友回复:我是用一个字符数组先定义好了迷宫
书上的算法,我没明白,写了这么多:
#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);
}


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

关键字:有关于,迷宫,算法,帖子,

相关文章

文章评论

共有 0 位网友发表了评论 此处只显示部分留言 点击查看完整评论页面