易码技术论坛

 找回密码
 加入易码
搜索
查看: 121933|回复: 7

Eastsun请进,有事情麻烦你!

[复制链接]
发表于 2006-12-22 14:24:30 | 显示全部楼层
let me 找找,N久前滴了...
生成算法在偶的QQ空间上找到了:
  1. Empty the path list of rooms.
  2.    Set up the west walls for each room.
  3.    Set up the south walls for each room.
  4.    Set up the visitation status of each room.
  5.    Set up a count of rooms that remain to be visited.
  6.    Pick a starting location in the maze, at random.
  7.    DO WHILE (more rooms to visit),
  8.     Decrement the count of rooms to visit.
  9.     Mark the current room as visited.
  10.     Count the number of valid exits from this room.
  11.     DO WHILE (no exits from this room),
  12.       Pick an entry from the path list, at random.
  13.       Remove that entry from the path list.
  14.       Count the number of valid exits from this new room.
  15.     LOOP
  16.     IF (count of exits > 1) THEN
  17.       Add this room to the path list.
  18.     END IF
  19.     Select one of the available exits, at random.
  20.     Break the intervening wall in that selected direction.
  21.     Move into the new room in that direction.
  22.    LOOP  
复制代码
发表于 2006-12-22 14:34:18 | 显示全部楼层
找到源程序了,不过不太确定是不是最终版,因该不会有问题:
  1. /**
  2. @迷宫生成程序
  3. @Author :Eastsun
  4. @Version:1.0
  5. @Date  :6.7
  6. */
  7. #height 240
  8. #width  320
  9. #bigram
  10. #define  VISIT  0x01        //该位为1表示还未访问
  11. #define  VISIT1 0x20        //求解时用的
  12. #define  NORTH  0x02        //该位为0表示无墙
  13. #define  SOUTH  0x04
  14. #define  WEST  0x08
  15. #define  EAST  0x10
  16. #define  MASK  0x15
  17. #define  MWIDTH  160
  18. #define  MHEIGHT 120
  19. char  mazeMap[MHEIGHT+2][MWIDTH+2];
  20. int  width,height;
  21. void drawMaze(int x,int y,int dest,int type){
  22.   int w,h;
  23.   y++;
  24.   for(h =1;h<=height;h++)
  25.     for(w =1;w<=width;w++){
  26.       if(mazeMap[h][w]&EAST) Line(x+w*dest,y+(h-1)*dest,x+w*dest,y+h*dest,type);
  27.       if(mazeMap[h][w]&SOUTH)Line(x+(w-1)*dest,y+h*dest,x+w*dest,y+h*dest,type);
  28.     }
  29.    Line(x,y,x+width*dest,y,type);
  30.    Line(x,y+height*dest,x+width*dest,y+height*dest,type);
  31.    Line(x,y,x,y+height*dest,type);
  32.    Line(x+width*dest,y,x+width*dest,y+height*dest,type);
  33.    y--;
  34.    Line(x+2*dest,y,x+5*dest,y,type);
  35.    Line(x+3*dest+1,y,x+4*dest-1,y,type^1);
  36.    y++;
  37.    Line(x+3*dest+1,y,x+4*dest-1,y,type^1);
  38.    Line(x+width*dest,y+(height-1)*dest+1,x+width*dest,y+height*dest-1,type^1);
  39. }
  40. void  init(int h,int w,long seed){
  41.   int  n,unVisited,listSize,neighbor,px,py,r,process;
  42.   char  pathList[MHEIGHT*MWIDTH][2];
  43.   height =h;
  44.   width  =w;
  45.   memset(mazeMap,MASK,(MWIDTH+2)*(MHEIGHT+2));
  46.   for(n=0;n<=width+1;n++){ mazeMap[0][n] =0; mazeMap[height+1][n] =0;}
  47.   for(n=0;n<=height+1;n++){mazeMap[n][0] =0; mazeMap[n][width+1] =0; }
  48.   
  49.   if(seed)  srand(seed);
  50.   else    srand((Getms()<<8)+rand());
  51.   unVisited =height*width;
  52.   listSize  =0;
  53.   px =rand()%width+1; py =rand()%height+1;  //pick a starting location in maze,at random
  54.   Box(30,27,112,44,1,0);
  55.   Box(30,27,112,44,0,1);
  56.   TextOut(35,30,"迷宫生成中..",0x41);
  57.   process =0;
  58.   while(unVisited-1){
  59.     mazeMap[py][px] =mazeMap[py][px]^VISIT;
  60.     unVisited --;
  61.     if(unVisited%width==1){
  62.       process ++;
  63.       Box(30,27,112,44,1,0);
  64.        Box(30,27,112,44,0,1);
  65.        TextOut(35,30,"迷宫生成中..",0x41);
  66.        Box(35,30,35+72*process/height,41,1,2);
  67.      }
  68.     while(!(neighbor=(mazeMap[py][px-1]&VISIT)+(mazeMap[py][px+1]&VISIT)+
  69.            (mazeMap[py-1][px]&VISIT)+(mazeMap[py+1][px]&VISIT))){
  70.       py =pathList[--listSize][0];
  71.       px =pathList[listSize][1];
  72.     }
  73.     if(neighbor>1){
  74.      pathList[listSize][0] =py;
  75.      pathList[listSize][1] =px;
  76.      listSize ++;
  77.     }
  78.     r =rand()%neighbor;
  79.     n =0;
  80.     if(mazeMap[py-1][px]&VISIT){
  81.      if(n ==r){
  82.        mazeMap[py-1][px] =mazeMap[py-1][px]^SOUTH;
  83.        py--;
  84.        continue;
  85.      }
  86.      else n++;
  87.     }
  88.     if(mazeMap[py+1][px]&VISIT){
  89.      if(n ==r){
  90.        mazeMap[py][px]  =mazeMap[py][px]^SOUTH;
  91.        py++;
  92.        continue;
  93.      }
  94.      else n++;
  95.     }
  96.     if((mazeMap[py][px-1]&VISIT)&&n ==r){
  97.        mazeMap[py][px-1] =mazeMap[py][px-1]^EAST;
  98.        px--;
  99.     }
  100.     else{
  101.         mazeMap[py][px]  =mazeMap[py][px]^EAST;
  102.         px++;
  103.     }
  104.   }//while  
  105. }
  106. void main(){
  107.   char key,d;
  108.   while(1){
  109.     ClearScreen();
  110.     TextOut(1,0,  "*******迷宫生成程序*******",1);
  111.     TextOut(1,24, "    1  小型迷宫(39×19)  ",1);
  112.     TextOut(1,40, "    2  大型迷宫(79×39)  ",1);
  113.     TextOut(1,67, "********By Eastsun********",1);
  114.     Refresh();
  115.     key =getchar();
  116.     if(key ==&#39;b&#39;){    init(59,79,0); d =4;}
  117.     else if(key ==&#39;n&#39;){ init(119,159,0); d =2;}
  118.     else if(key ==0x1b) break;
  119.     else           continue;
  120.     ClearScreen();
  121.     Refresh();
  122.      drawMaze(1,0,d,0x01);
  123.      getchar();
  124.   }
  125. }
  126.       
  127.   
复制代码
发表于 2006-12-22 14:41:17 | 显示全部楼层
我不是N久以前发过算法么...被无视了...
发表于 2006-12-22 15:23:23 | 显示全部楼层
呵呵,Jay的算法太高深了,当时看不懂啊~现在好些了,不过既然有源代码,那么算法就……
 楼主| 发表于 2006-12-22 17:35:09 | 显示全部楼层
引用第2楼Eastsun2006-12-22 14:34发表的“”:
找到源程序了,不过不太确定是不是最终版,因该不会有问题:
[code]
/**
@迷宫生成程序
@Author :Eastsun
.......

非常感谢你!!!!~~~~~~~~~~~~~~~~~~~
 楼主| 发表于 2006-12-22 17:42:44 | 显示全部楼层
引用第3楼yzk03702006-12-22 14:41发表的“”:
我不是N久以前发过算法么...被无视了...


实在抱歉,我搜索的时候没看到你以前发的,可否也贴出来!?

谢谢
 楼主| 发表于 2006-12-22 17:46:52 | 显示全部楼层
引用第2楼Eastsun2006-12-22 14:34发表的“”:
找到源程序了,不过不太确定是不是最终版,因该不会有问题:
[code]
/**
@迷宫生成程序
@Author :Eastsun
.......

程序可以运行!非常感谢

我想问一个问题:
就是保存在数组MAZE[][]中的数据都有什么数字(比如0,1,2...)
每个数字都代表什么?(几代表墙几代表可以行走几代表墙?墙还分方向吗?)
 楼主| 发表于 2006-12-22 00:13:44 | 显示全部楼层 |阅读模式
  在EM上找到一个你以前发的LAVA程序-<迷宫生成程序>
可以生成39*19/79*39那个,可不可以把源代码发给我
我想研究一下,可以吗?谢谢
我的E-mail:008club@163.com
您需要登录后才可以回帖 登录 | 加入易码

本版积分规则

Archiver|手机版|小黑屋|EMAX Studio

GMT+8, 2025-5-1 00:38 , Processed in 0.011474 second(s), 18 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表