易码技术论坛

 找回密码
 加入易码
搜索
查看: 540738|回复: 10

[教程] 扫雷-算法讨论

[复制链接]
发表于 2006-12-28 12:51:12 | 显示全部楼层
wqx的内存情况~~~
用递归不好把
发表于 2006-12-28 16:25:49 | 显示全部楼层
发错版了~
发表于 2006-12-28 16:32:49 | 显示全部楼层
刚刚用yan的编译器编译,非常完美(+_+)!
发表于 2006-12-28 22:12:20 | 显示全部楼层
我的错位扫雷是用  用递归
为了加快速度,几乎胶尽脑汁。
最后做出来还比汇编的快些。

加快速度大概用了下面几种方法
预先算好格子
贴图简练
减少判断运算
发表于 2006-12-30 00:46:09 | 显示全部楼层
我用的是a*算法的改版,自已优化过,速度很不错....
理论上比递归快,但占全局内存要大些
 楼主| 发表于 2006-12-30 08:11:09 | 显示全部楼层
上面两位能否把代码贴出来看看呢?
我是初学者 ^_^
发表于 2006-12-30 09:22:50 | 显示全部楼层
lava版的很长,看不了的
最近写了个VS 的 算法基本相同,可以用VS的命令提示符 cl mine.c 编译
扫雷的算法其实也没什么好讨论的,只要最后结果行就行了

mine.rar

21 KB, 下载次数: 131

 楼主| 发表于 2006-12-31 19:52:33 | 显示全部楼层
Thx~
发表于 2006-12-31 20:05:12 | 显示全部楼层
对Cloty的Console美工无比崇拜~
 楼主| 发表于 2006-12-31 20:55:04 | 显示全部楼层
附议~~
 楼主| 发表于 2006-12-28 12:48:54 | 显示全部楼层 |阅读模式
最近学C语言,拿Lava练手编了个扫雷.
不知道是递归快还是回溯快?
(本帖公布的代码供学习用,允许任何人转载.)

递归代码如下:
  1. //=======================
  2. //= 程序:挖地雷      =
  3. //= 核心算法:递归     =
  4. //= 作者:闫茂源      =
  5. //= 地点:HB.JM.龙泉中学 =
  6. //= 时间:2006/12/17    =
  7. //=======================
  8. #define FALSE 0
  9. #define TURE 1
  10. #define SMILE 1
  11. #define OU 2
  12. #define LAUGH 3
  13. #define SAD 4
  14. #define MARK 9
  15. #define CROSS 10
  16. #define BLACK 11
  17. #define MINE 12
  18. #define ENTER 13
  19. #define KPD 14
  20. #define KPU 19
  21. #define KU 20
  22. #define KD 21
  23. #define KR 22
  24. #define KL 23
  25. #define KH 25
  26. #define ESC 27
  27. #define KF1 28
  28. #define KSP 32
  29. /*字符数据 0123456789*/
  30. char number_0[]={0x3C,0x42,0x42,0x42,0x42,0x00,0x42,0x42,0x42,0x42,0x3C};
  31. char number_1[]={0x00,0x02,0x02,0x02,0x02,0x00,0x02,0x02,0x02,0x02,0x00};
  32. char number_2[]={0x3C,0x02,0x02,0x02,0x02,0x3C,0x40,0x40,0x40,0x40,0x3C};
  33. char number_3[]={0x3C,0x02,0x02,0x02,0x02,0x3C,0x02,0x02,0x02,0x02,0x3C};
  34. char number_4[]={0x00,0x42,0x42,0x42,0x42,0x3C,0x02,0x02,0x02,0x02,0x00};
  35. char number_5[]={0x3C,0x40,0x40,0x40,0x40,0x3C,0x02,0x02,0x02,0x02,0x3C};
  36. char number_6[]={0x3C,0x40,0x40,0x40,0x40,0x3C,0x42,0x42,0x42,0x42,0x3C};
  37. char number_7[]={0x3C,0x02,0x02,0x02,0x02,0x00,0x02,0x02,0x02,0x02,0x00};
  38. char number_8[]={0x3C,0x42,0x42,0x42,0x42,0x3C,0x42,0x42,0x42,0x42,0x3C};
  39. char number_9[]={0x3C,0x42,0x42,0x42,0x42,0x3C,0x02,0x02,0x02,0x02,0x3C};
  40. /*左侧表情数据*/
  41. char face_smile[]={0x07,0xF0,0x08,0x08,0x10,0x04,0x20,0x02,0x20,0x02,0x40,0x01,0x4C,0x19,0x40,0x01,0x40,0x01,0x40,0x01,0x22,0x22,0x21,0xC2,0x10,0x04,0x08,0x08,0x07,0xF0,0x00,0x00};
  42. char face_ou[]={0x07,0xF0,0x08,0x08,0x10,0x04,0x20,0x02,0x20,0x02,0x40,0x01,0x4C,0x19,0x4C,0x19,0x40,0x01,0x40,0x01,0x21,0xC2,0x22,0x22,0x11,0xC4,0x08,0x08,0x07,0xF0,0x00,0x00};
  43. char face_laugh[]={0x07,0xF0,0x08,0x08,0x10,0x04,0x20,0x02,0x20,0x02,0x4F,0xF9,0x5F,0x7D,0x6E,0x3B,0x40,0x01,0x40,0x01,0x20,0x02,0x24,0x12,0x13,0xE4,0x08,0x08,0x07,0xF0,0x00,0x00};
  44. char face_sad[]={0x07,0xF0,0x08,0x08,0x10,0x04,0x20,0x02,0x20,0x02,0x4A,0x29,0x44,0x11,0x4A,0x29,0x40,0x01,0x40,0x01,0x21,0xC2,0x22,0x22,0x10,0x04,0x08,0x08,0x07,0xF0,0x00,0x00};
  45. /*雷区图形数据*/
  46. char pic_blank[]={0xA8,0x50,0xA8,0x50,0xA8};
  47. char pic_black[]={0xF8,0xF8,0xF8,0xF8,0xF8};
  48. char pic_mine[]={0xA8,0x70,0xF8,0x70,0xA8};
  49. char pic_mark[]={0x00,0x08,0x10,0xA0,0x40};
  50. char pic_cross[]={0x88,0x50,0x20,0x50,0x88};
  51. char pic_1[]={0x20,0x20,0x20,0x20,0x20};
  52. char pic_2[]={0x70,0x10,0x70,0x40,0x70};
  53. char pic_3[]={0x70,0x10,0x70,0x10,0x70};
  54. char pic_4[]={0x50,0x50,0x70,0x10,0x10};
  55. char pic_5[]={0x70,0x40,0x70,0x10,0x70};
  56. char pic_6[]={0x70,0x40,0x70,0x50,0x70};
  57. char pic_7[]={0x70,0x10,0x10,0x10,0x10};
  58. char pic_8[]={0x70,0x50,0x70,0x50,0x70};
  59. /*热线帮助数据*/
  60. char HELP[]={"***** 热线帮助 *****====== 挖地雷 ======   --= 规则 =--   把所有没有地雷的方块挖开则胜;挖到地雷则失败;被挖开方块上的数字表示附近方块中地雷的数目。        --= 游戏界面 =--  分隔线右边是雷区,左上角显示游戏难度和剩余未标记的数目,左下角为时间。        --= 按键功能 =--  <><><><>移动光标<输入>挖开一个方块  <空格>标记一个方块  <> 连续挖开多个方块<F1>重新开局        --= 声明 =--   作者:Windy.Bell    日期:2006/12/16    QQ:115150813      = All rights left! ="};
  61. /*声明全局变量*/
  62. int Map[21][13];
  63. int sum,mark;
  64. /*把数字(8*11)写到缓存坐标 x,y 处*/
  65. void ShowNumber(int x,int y,int n)
  66. {
  67.    if(n==0)WriteBlock(x,y,8,11,0,number_0);
  68.    if(n==1)WriteBlock(x,y,8,11,0,number_1);
  69.    if(n==2)WriteBlock(x,y,8,11,0,number_2);
  70.    if(n==3)WriteBlock(x,y,8,11,0,number_3);
  71.    if(n==4)WriteBlock(x,y,8,11,0,number_4);
  72.    if(n==5)WriteBlock(x,y,8,11,0,number_5);
  73.    if(n==6)WriteBlock(x,y,8,11,0,number_6);
  74.    if(n==7)WriteBlock(x,y,8,11,0,number_7);
  75.    if(n==8)WriteBlock(x,y,8,11,0,number_8);
  76.    if(n==9)WriteBlock(x,y,8,11,0,number_9);
  77. }
  78. /*将表情(16*16)写到缓存坐标 8,32 处*/
  79. void Face(int type)
  80. {
  81.    if(type==SMILE)WriteBlock(8,32,16,16,0,face_smile);
  82.    if(type==OU)WriteBlock(8,32,16,16,0,face_ou);
  83.    if(type==LAUGH)WriteBlock(8,32,16,16,0,face_laugh);
  84.    if(type==SAD)WriteBlock(8,32,16,16,0,face_sad);
  85. }
  86. /*把图片(5*5)写到缓存*/
  87. void ShowPic(int x,int y,int type)
  88. {
  89.    x=x*6+34;
  90.    y=y*6+2;
  91.    if(type==0)WriteBlock(x,y,5,5,0,pic_blank);
  92.    if(type==1)WriteBlock(x,y,5,5,0,pic_1);
  93.    if(type==2)WriteBlock(x,y,5,5,0,pic_2);
  94.    if(type==3)WriteBlock(x,y,5,5,0,pic_3);
  95.    if(type==4)WriteBlock(x,y,5,5,0,pic_4);
  96.    if(type==5)WriteBlock(x,y,5,5,0,pic_5);
  97.    if(type==6)WriteBlock(x,y,5,5,0,pic_6);
  98.    if(type==7)WriteBlock(x,y,5,5,0,pic_7);
  99.    if(type==8)WriteBlock(x,y,5,5,0,pic_8);
  100.    if(type==MARK)WriteBlock(x,y,5,5,0,pic_mark);
  101.    if(type==CROSS)WriteBlock(x,y,5,5,0,pic_cross);
  102.    if(type==BLACK)WriteBlock(x,y,5,5,0,pic_black);
  103.    if(type==MINE)WriteBlock(x,y,5,5,0,pic_mine);
  104. }
  105. /*清屏*/
  106. void Cls()
  107. {
  108.    ClearScreen();
  109.    Refresh();
  110. }
  111. /*将时间(24*11)写到左下侧(缓存 5,66)*/
  112. void Timer(int time)
  113. {
  114.    int a,b,c;
  115.    a=time/100;
  116.    b=(time-a*100)/10;
  117.    c=time-a*100-b*10;
  118.    ShowNumber(5,66,a);
  119.    ShowNumber(13,66,b);
  120.    ShowNumber(21,66,c);
  121. }
  122. /*显示剩余地雷数*/
  123. void MineNum(int i)
  124. {
  125.    int a;
  126.    a=i/10;
  127.    i=i-a*10;
  128.    ShowNumber(16,17,a);
  129.    ShowNumber(24,17,i);
  130. }
  131. /*查看帮助*/
  132. void Help()
  133. {
  134.    int key,i;
  135.    char temp[1600];
  136.    GetBlock(0,0,160,80,0,temp);
  137.    Cls();
  138.    SetScreen(0);
  139.    key=0;i=0;
  140.    while(key!=ESC)
  141.    {
  142.       memcpy(_TEXT,HELP+i*20,100);
  143.       UpdateLCD(0);
  144.       key=getchar();
  145.       if(key==KU)i--;
  146.       if(key==KD)i++;
  147.       if(key==KL)i=0;
  148.       if(key==KR)i=19;
  149.       if(key==KPU)i=i-5;
  150.       if(key==KPD)i=i+5;
  151.       if(i>19)i=19;
  152.       if(i<0)i=0;
  153.    }
  154.    WriteBlock(0,0,160,80,0,temp);
  155.    Refresh();
  156. }
  157. /*标记(x,y)处方块,已标记则撤消标记*/
  158. void Mark(int x,int y)
  159. {
  160.    int i;
  161.    i=Map[x][y];
  162.    if(i<5)
  163.    {
  164.       if(i>1)
  165.       {
  166.         Map[x][y]=i-2;
  167.         ShowPic(x,y,BLACK);
  168.         mark--;
  169.       }
  170.       else
  171.       {
  172.         Map[x][y]=i+2;
  173.         mark++;
  174.         ShowPic(x,y,MARK);
  175.       }
  176.    }
  177. }
  178. [color=orangered]/*挖开方块(x,y),扫描(x,y)周围八个方块中的地雷数并显示*/
  179. void Scan(int x,int y)
  180. {
  181.    int a,b,i,s;
  182.    s=0;
  183.    for(a=-1;a<2;a++)
  184.    {
  185.       for(b=-1;b<2;b++)
  186.       {
  187.         if(x+a>=0&&y+b>=0&&x+a<21&&y+b<13)
  188.         {
  189.            i=Map[x+a][y+b];
  190.            if(i==1||i==3)s++;
  191.         }
  192.       }
  193.    }
  194.    sum++;
  195.    ShowPic(x,y,s);
  196.    Refresh();
  197.    Map[x][y]=s+10;
  198. }
  199. /*从(x,y)处开始搜索可翻开的方块*/
  200. void Sreach(int x,int y)
  201. {
  202.    int i;
  203.    int tx,ty;
  204.    int s[8],a[8],b[8];/*八个方向*/
  205.    a[0]=-1;b[0]=-1;
  206.    a[1]=-1;b[1]=0;
  207.    a[2]=-1;b[2]=1;
  208.    a[3]=0;b[3]=1;
  209.    a[4]=1;b[4]=1;
  210.    a[5]=1;b[5]=0;
  211.    a[6]=1;b[6]=-1;
  212.    a[7]=0;b[7]=-1;
  213.    if(Map[x][y]==0)Scan(x,y);
  214.    if(Map[x][y]==10)
  215.    {
  216.       Map[x][y]=19;
  217.       for(i=0;i<8;i++)
  218.       {
  219.         tx=x+a[i];
  220.         ty=y+b[i];
  221.         if(tx>=0&&ty>=0&&tx<21&&ty<13)
  222.         {
  223.            if(Map[tx][ty]==0)Scan(tx,ty);
  224.            if(Map[tx][ty]==10)Sreach(tx,ty);
  225.         }
  226.       }
  227.    }
  228. }[/color]/*连续翻开(x,y)周围的方块*/
  229. int Around(int x,int y)
  230. {
  231.    int tx,ty;
  232.    int a[8],b[8];
  233.    int s[8],s1,s2,i;
  234.    s1=0;s2=0;
  235.    Face(OU);
  236.    Refresh();
  237. /*定义八个方向向量*/
  238.    a[0]=-1;b[0]=-1;
  239.    a[1]=-1;b[1]=0;
  240.    a[2]=-1;b[2]=1;
  241.    a[3]=0;b[3]=1;
  242.    a[4]=1;b[4]=1;
  243.    a[5]=1;b[5]=0;
  244.    a[6]=1;b[6]=-1;
  245.    a[7]=0;b[7]=-1;
  246. /*扫描标记总数s1和错误标记数目s2*/
  247.    for(i=0;i<8;i++)
  248.    {
  249.       tx=x+a[i];
  250.       ty=y+b[i];
  251.       if(tx>=0&&tx<21&&ty>=0&&ty<13)
  252.       {
  253.         s[i]=Map[tx][ty];
  254.         if(s[i]==2||s[i]==3)s1++;
  255.         if(s[i]==1)s2++;
  256.       }
  257.    }
  258.    i=FALSE;/*返回值初始化*/
  259. /*标记总数正确时连续翻开并改变返回值,否则直接返回FALSE*/
  260.    if(s1==Map[x][y]-10)
  261.    {
  262.       for(i=0;i<8;i++)
  263.       {
  264.         tx=x+a[i];
  265.         ty=y+b[i];
  266.         if(tx>=0&&tx<21&&ty>=0&&ty<13)
  267.         {
  268.            if(s[i]==0)Sreach(tx,ty);
  269.            if(s[i]==1)ShowPic(tx,ty,MINE);
  270.         }
  271.       }
  272. /*有错误标记时返回TURE否则返回FALSE*/
  273.       if(s2)i=TURE;
  274.       else  i=FALSE;
  275.    }
  276.    Face(SMILE);
  277.    Refresh();
  278.    return i;
  279. }
  280. struct TIME
  281. {
  282.    int year;
  283.    char month,day,hour,minute,second,week;
  284. };
  285. void main()
  286. {
  287.    int max;
  288.    int x,y;
  289.    int done,lost;
  290.    int i,key;
  291.    int t,h,m,s;
  292.    struct TIME time;
  293.    while(1)
  294.    {
  295. /*选择游戏难度*/
  296.       i=5;
  297.       key=0;
  298.       Cls();
  299.       Rectangle(56,36,104,44,2);
  300.       Rectangle(50,20,110,47,1);
  301.       Rectangle(51,48,110,49,1);
  302.       Rectangle(111,21,112,49,1);
  303.       TextOut(60,23,"难度:",0);
  304.       while(key!=ENTER)
  305.       {
  306.         Rectangle(i*5+53,38,i*5+57,42,1);
  307.         ShowNumber(92,23,i);
  308.         key=0;
  309.         Refresh();
  310.         key=getchar();
  311.         Rectangle(i*5+53,38,i*5+57,42,0);
  312.         if(key==KR&&i<9)i++;
  313.         if(key==KL&&i>1)i--;
  314.         if(key==ESC)exit(0);
  315.       }
  316.       max=i*10;
  317.       key=0;
  318.       while(key!=ESC)
  319.       {
  320. /*开新局*/
  321.         Cls();
  322.         TextOut(44,32,"载入中...",0xc0);
  323.         Box(40,28,120,51,0,1);
  324.         Box(41,52,120,53,1,1);
  325.         Box(121,29,122,53,1,1);
  326. /*绘制游戏界面到缓冲区*/
  327.         TextOut(2,2,"Lv ",0);
  328.         TextOut(2,16,"剩",0);
  329.         TextOut(4,50,"时间",0);
  330.         ShowNumber(16,2,max/10);
  331.         MineNum(max);
  332.         Timer(0);
  333.         Face(SMILE);
  334.         Rectangle(4,64,29,78,1);
  335.         Rectangle(32,1,32,79,1);
  336.         Rectangle(0,0,159,0,1);
  337. /*刷新雷区*/
  338.         for(y=0;y<13;y++)
  339.         {
  340.            for(x=0;x<21;x++)
  341.            {
  342.               Map[x][y]=0;
  343.               ShowPic(x,y,BLACK);
  344.            }
  345.         }
  346. /*随机设置地雷位置*/
  347.         x=rand()%21;
  348.         y=rand()%13;
  349.         for(i=0;i<max;i++)
  350.         {
  351.            while(Map[x][y])
  352.            {
  353.               x=rand()%21;
  354.               y=rand()%13;
  355.            }
  356.         Map[x][y]=1;
  357.         }
  358.         Refresh();
  359. /*初始化游戏参数*/
  360.         x=0;y=0;
  361.         mark=0;
  362.         sum=0;
  363.         done=FALSE;
  364.         lost=FALSE;
  365.         key=getchar();
  366.         if(key==KH)Help();
  367.         GetTime(time);
  368.         h=time.hour;
  369.         m=time.minute;
  370.         s=time.second;
  371. /*游戏控制部分*/
  372.         while(key!=ESC&&key!=KF1&&lost==FALSE&done==FALSE)
  373.         {
  374.            GetTime(time);
  375.            t=(time.hour-h)*3600+(time.minute-m)*60+(time.second-s);
  376.            if(t>999)t=999;
  377.            Timer(t);
  378.            MineNum(max-mark);
  379.            Refresh();
  380.            Box(x*6+33,y*6+1,x*6+39,y*6+7,1,2);
  381.            key=Inkey();
  382.            if(key)
  383.            {
  384.               if(key==KR)
  385.               {
  386.                 x++;
  387.                 Delay(100);
  388.                 if(x>20)x=0;
  389.               }
  390.               if(key==KL)
  391.               {
  392.                 x--;
  393.                 Delay(100);
  394.                 if(x<0)x=20;
  395.               }
  396.               if(key==KU)
  397.               {
  398.                 y--;
  399.                 Delay(100);
  400.                 if(y<0)y=12;
  401.               }
  402.               if(key==KD)
  403.               {
  404.                 y++;
  405.                 Delay(100);
  406.                 if(y>12)y=0;
  407.               }
  408.               if(key==KH)
  409.               {
  410.                 Help();
  411.                 Delay(500);
  412.               }
  413.               if(key==KSP)
  414.               {
  415.                 Mark(x,y);
  416.                 Delay(200);
  417.               }
  418.               if(key==ENTER)
  419.               {
  420.                 Face(OU);
  421.                 Refresh();
  422.                 if(Map[x][y]==0)Sreach(x,y);
  423.                 if(Map[x][y]==1)
  424.                 {
  425.                    lost=TURE;
  426.                    ShowPic(x,y,MINE);
  427.                 }
  428.                 Face(SMILE);
  429.                 Refresh();
  430.               }
  431.               if(key==KPU&&Map[x][y]>10)lost=Around(x,y);
  432.            }
  433.            if(sum==273-max)done=TURE;
  434.            ReleaseKey(128);
  435.         }
  436. /*判断胜负,并显示地雷*/
  437.         /*失败*/
  438.         if(lost)
  439.         {
  440.            Face(OU);
  441.            for(x=0;x<21;x++)
  442.            {
  443.               for(y=0;y<13;y++)
  444.               {
  445.                 if(Map[x][y]==1)ShowPic(x,y,MINE);
  446.                 if(Map[x][y]==2)ShowPic(x,y,CROSS);
  447.                 Refresh();
  448.               }
  449.            }
  450.            Face(SAD);
  451.            Refresh();
  452.         }
  453.         /*胜利*/
  454.         if(done)
  455.         {
  456.            Face(OU);
  457.            for(x=0;x<21;x++)
  458.            {
  459.               for(y=0;y<13;y++)
  460.               {
  461.                 if(Map[x][y]==1)ShowPic(x,y,MARK);
  462.                 Refresh();
  463.               }
  464.            }
  465.            Face(LAUGH);
  466.            Refresh();
  467.         }
  468. /*若游戏因得出胜负而结束,则暂停在结束画面*/
  469.         while(key!=ESC&&key!=KF1)
  470.         {
  471.            key=getchar();
  472.            if(key==KH)
  473.            {
  474.               Help();
  475.               Delay(500);
  476.            }
  477.         }
  478.       }
  479.    }
  480. }
  481. --------------------------------------------------------------------------
  482. 回溯如下:
  483. /*从(x,y)处开始搜索可翻开的方块*/
  484. void Sreach(int x,int y)
  485. {
  486.    int i;
  487.    int step;/*步长*/
  488.    int sa,sb,sc,sd,se,sf,sg,sh;/*八个方向*/
  489.    int xx[273],yy[273];
  490.    step=0;
  491.    xx[step]=x;
  492.    yy[step]=y;
  493.    if(Map[x][y]==0)Scan(x,y);
  494.    if(Map[x][y]==10)
  495.    {
  496.       L1:
  497.       xx[step]=x;
  498.       yy[step]=y;
  499.       Map[x][y]=19;
  500.       do
  501.       {
  502.         if(x>0&&y>0)
  503.         {
  504.            sa=Map[x-1][y-1];
  505.            if(sa==0)
  506.            {
  507.               Scan(x-1,y-1);
  508.               sa=Map[x-1][y-1];
  509.            }
  510.         }
  511.         if(x>0)
  512.         {
  513.            sb=Map[x-1][y];
  514.            if(sb==0)
  515.            {
  516.               Scan(x-1,y);
  517.               sb=Map[x-1][y];
  518.            }
  519.         }
  520.         if(x>0&&y<12)
  521.         {
  522.            sc=Map[x-1][y+1];
  523.            if(sc==0)
  524.            {
  525.               Scan(x-1,y+1);
  526.               sc=Map[x-1][y+1];
  527.            }
  528.         }
  529.         if(y<12)
  530.         {
  531.            sd=Map[x][y+1];
  532.            if(sd==0)
  533.            {
  534.               Scan(x,y+1);
  535.               sd=Map[x][y+1];
  536.            }
  537.         }
  538.         if(x<20&&y<12)
  539.         {
  540.            se=Map[x+1][y+1];
  541.            if(se==0)
  542.            {
  543.               Scan(x+1,y+1);
  544.               se=Map[x+1][y+1];
  545.            }
  546.         }
  547.         if(x<20)
  548.         {
  549.            sf=Map[x+1][y];
  550.            if(sf==0)
  551.            {
  552.               Scan(x+1,y);
  553.               sf=Map[x+1][y];
  554.            }
  555.         }
  556.         if(x<20&&y>0)
  557.         {
  558.            sg=Map[x+1][y-1];
  559.            if(sg==0)
  560.            {
  561.               Scan(x+1,y-1);
  562.               sg=Map[x+1][y-1];
  563.            }
  564.         }
  565.         if(y>0)
  566.         {
  567.            sh=Map[x][y-1];
  568.            if(sh==0)
  569.            {
  570.               Scan(x,y-1);
  571.               sh=Map[x][y-1];
  572.            }
  573.         }
  574.         if(x>0&&y>0&&sa==10)
  575.         {
  576.            x--;
  577.            y--;
  578.            step++;
  579.            goto L1;
  580.         }
  581.         if(x>0&&sb==10)
  582.         {
  583.            x--;
  584.            step++;
  585.            goto L1;
  586.         }
  587.         if(x>0&&y<12&&sc==10)
  588.         {
  589.            x--;
  590.            y++;
  591.            step++;
  592.            goto L1;
  593.         }
  594.         if(y<12&&sd==10)
  595.         {
  596.            y++;
  597.            step++;
  598.            goto L1;
  599.         }
  600.         if(x<20&&y<12&&se==10)
  601.         {
  602.            x++;
  603.            y++;
  604.            step++;
  605.            goto L1;
  606.         }
  607.         if(x<20&&sf==10)
  608.         {
  609.            x++;
  610.            step++;
  611.            goto L1;
  612.         }
  613.         if(x<20&&y>0&&sg==10)
  614.         {
  615.            x++;
  616.            y--;
  617.            step++;
  618.            goto L1;
  619.         }
  620.         if(y>0&&sh==10)
  621.         {
  622.            y--;
  623.            step++;
  624.            goto L1;
  625.         }
  626.         step--;
  627.         x=xx[step];
  628.         y=yy[step];
  629.       }
  630.       while (step>0);
  631.    }
  632. }
复制代码
--------------------------------------------------------------------------
我感觉是递归好些吧

挖地雷.rar

11 KB, 下载次数: 118

您需要登录后才可以回帖 登录 | 加入易码

本版积分规则

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

GMT+8, 2024-4-20 12:53 , Processed in 0.022554 second(s), 21 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

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