随机迷宫c语言实验报告,[原创]递归随机迷宫生成算法详解

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

#include                                               

#include                                              

#include                                             

char cw[][4]={" ","┃","━","┗","┃","┃","┏","┣","━"//map

,"┛","━","┻","┓","┫","┳" ,"╋"};char m[50][50];char *getw

(int x,int y){return cw[(m[x]   [y-1]?0:1)|(m[x+1][y]?0:2)|(m [

x][y+1]?0:4)|(m[x-1][y]?0:8)     ];}int sr(int x,int y){ static

int d[4][2]={{0,1},{1,0},{0       ,-1},{-1,0}};int zx=x*2,zy=y*

2,nx,tn=rand()%2? 1:3,i;m[         zx][zy]=1;for(i=0,nx=rand()%

4;i<4;i++,nx=(nx+tn)%4)if           (m[zx+2*d[nx][0]][zy+2*d[nx

][1]]==0)m[zx+d[nx][0]][             zy+d[nx][1]]=1,sr (x+d[nx]

[0],y+d[nx][1]); return               0;} void Make_Maze(int x,

int y){int z1,z2;for (                 z1=0,z2=2*y+2;z1<=2*x+2;

z1++)m[z1][0]=1,m[z1]                   [z2]=1;for(z1=0, z2=2*x

+2;z1<=2*y+2;z1++)m[                     0][z1]=1,m[z2][z1]=1;m

[1][2]=1;m[2*x+1][2                       *y]=1;srand((unsigned

)time(NULL) ); sr(                         rand()%x+1,rand()%y+

1);}int main(void                           ){int x=15,y=10,z1,

z2;Make_Maze(x,y                             );for(z2=1;z2<=y*2

+1;z2++){for(z1                               =1;z1<=x*2+1;z1++

)printf(m[z1][                                 z2]?" ":getw(z1

,z2));if(z2<=                                   y*2)putchar(10)

;}return 0;}                                     // Puzzle Game

插一下楼

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值