广告广告
  加入我的最爱 设为首页 风格修改
首页 首尾
 手机版   订阅   地图  繁体 
您是第 2796 个阅读者
 
发表文章 发表投票 回覆文章
  可列印版   加为IE收藏   收藏主题   上一主题 | 下一主题   
凯西男孩
个人文章 个人相簿 个人日记 个人地图
初露锋芒
级别: 初露锋芒 该用户目前不上站
推文 x0 鲜花 x24
分享: 转寄此文章 Facebook Plurk Twitter 复制连结到剪贴簿 转换为繁体 转换为简体 载入图片
推文 x0
[C/C++] 求助【帮改程式码】
这是一个迷宫的程式,8*8的,大致上就是这样,我就是改不好,好心的大大帮个忙吧!谢谢,感激不尽。

#include <iostream.h>
#include <stdio.h>
#include <stdlib.h>

int visit(int, int);

int maze={{1,0,1,1,1,1,1,1},
{0,0,1,0,1,0,0,1},
{1,0,1,0,1,0,1,1},
{1,0,1,0,0,0,0,1},
{1,0,0,0,1,1,0,1},
{1,0,1,0,0,1,0,1},
{1,0,1,0,1,1,0,1},
{1,1,1,1,1,1,2,1}};
int ei = 6, ej = 6;
int success = 0;
int main(void) {
int i, j;
do{
cout << "请输入x座标(0-7):" << endl;
cin >> i;
..

访客只能看到部份内容,免费 加入会员 或由脸书 Google 可以看到全部内容




献花 x0 回到顶端 [楼 主] From:台湾中华电信 | Posted:2005-04-18 18:13 |
s89tsvs62219
数位造型
个人文章 个人相簿 个人日记 个人地图
小人物
级别: 小人物 该用户目前不上站
推文 x0 鲜花 x8
分享: 转寄此文章 Facebook Plurk Twitter 复制连结到剪贴簿 转换为繁体 转换为简体 载入图片

这是小弟做过的老鼠走迷宫~~看一下对你有没有帮助~

复制程式
#include<stdio.h>
#include<stdlib.h>
#include<iostream.h>
#include<conio.h>
#include<time.h>
#include<fstream.h>
//class datalist;
#define fast 200
#define filepath "c:\\迷宫.txt"
       int a[12][12]={
       {1,1,1,1,1,1,1,1,1,1,1,1},
       {99,0,0,1,0,1,0,0,0,0,0,1},
       {1,1,0,1,0,1,0,1,1,1,0,1},
       {1,1,0,1,0,0,0,1,0,0,0,1},
       {1,1,0,1,0,1,0,1,0,1,0,1},
       {1,0,0,1,0,0,0,1,0,0,0,1},
       {1,1,0,1,0,1,0,1,1,1,0,1},
       {1,1,0,0,0,0,0,1,0,0,0,1},
       {1,1,0,1,1,1,1,1,0,1,0,1},
       {1,1,0,1,1,1,1,1,0,1,0,1},
       {1,1,0,0,0,0,0,1,0,1,0,100},
       {1,1,1,1,1,1,1,1,1,1,1,1},};

       void picture()
       {
       for (int i=0;i<=11;i++)
       {for (int j=0;j<=11;j++)
              {if (a[ i ][j]==1)
                     cout << "■";
              else
                     if (a[ i ][j]==0)
                            cout << "  ";
                     else
                            if (a[i][j]==99)
                                   cout<< "@";
                            else
                                   cout<<"╳";
       }

                     cout <<endl;
       }       
       
       }

class datalist
{
public:
       datalist *next;
       int x,y,direct;

    datalist(int xx,int yy,int dd,datalist *hh)
       {x=xx;y=yy;direct=dd;
       next=hh;
       }
       
       ~datalist()
       {
//              cout<< "\n 解构子" <<endl;
//              system("pause");
       } 

};

       void printdata(datalist *head)
       {
              while(head != '\0')
              {
              cout << "x="<<head->x<< "   y="<<head->y<< "   direct="<<head->direct<<endl;
              head=head->next;
              //system("pause");
              }
       
       }

       datalist* comeback(datalist *head)
       {
              int ck;
              datalist *temp;
              do{
                     a[head->y][head->x]=0;
                     temp=head;
                     head=head->next;
                     delete temp;
                     a[head->y][head->x]=99;
                     
                     system("CLS");
                     picture();

                     switch(head->direct)
                     {//1上 2下 4左 8右
                     case 1:
                            head->direct =head->direct-1;
                            break;
                     case 2:
                     case 3:
                     case 6:
                     case 7:
                            head->direct =head->direct-2;
                            break;
                     case 4:
                     case 5:
                            head->direct =head->direct-4;
                            break;
                     case 8:
                     case 9:
                     case 10:
                     case 11:
                     case 12:
                     case 13:
                     case 14:
                     case 15:
                            head->direct =head->direct-8;
                            break;
                     default:
                     cout<< "方向有错"<<endl;
              }
                     ck=clock();
                     while((clock()-ck)<fast)
                     {
                     }
              }while(head->direct==0);
              return head;
       }


       datalist* checkwell(datalist *head,int x, int y)
       {
       if (head !='\0')
              if (head->x  == x && head->y==y)
              return head;
              else
              return checkwell(head->next ,x,y);
       else
              return '\0'
              
       }



void main()
{
       fstream file;
       int x=0,y=1,direct=8,ck;
       datalist *head='\0',*wellhead='\0'
       head=new datalist(x,y,direct,head);
/*
//============================
file.open(filepath,ios::in);
if (!file)
{
       cerr<<"XXXXX"<<endl;
       exit(1);
}
for (int i=0;i<12;i++)
       for (int j=0;j<12;j++)
{
       file>> ck;
       a[i][j]=ck;
}
file.close();
//============================
*/       
       picture();
       system("pause");
  //绘地图

        
        while(a[y][x]!=100)
       {
                     ck=clock();
                     while((clock()-ck)<fast)
                     {
                     }

              if (head->direct==0)
              head=comeback(head);                     

              switch(head->direct)
              {//1上 2下 4左 8右
              case 1:
                     x=head->x;
                     y=head->y-1;
                     break;
              case 2:
              case 3:
              case 6:
              case 7:
                     x=head->x;
                     y=head->y+1;
                     break;
              case 4:
              case 5:
                     x=head->x-1;
                     y=head->y;
                     break;
              case 8:
              case 9:
              case 10:
              case 11:
              case 12:
              case 13:
              case 14:
              case 15:
                     x=head->x+1;
                     y=head->y;
                     break;
              default:
                     cout<< "方向有错"<<endl;
              }
              //判断方向可走
              
              direct=0;
              if(head->direct !=4)
                     if (a[y][x+1]==0 || a[y][x+1]==100)
                     {wellhead=checkwell(head,x+1,y);
                     if (wellhead=='\0')
                            direct=direct+8;
                     else
                            wellhead->direct =wellhead->direct-4;
                     }

              if(head->direct !=8)
                     if (a[y][x-1]==0 || a[y][x-1]==100)
                     {wellhead=checkwell(head,x-1,y);
                     if (wellhead=='\0')
                            direct=direct+4;
                     else
                            wellhead->direct =wellhead->direct-8;
                     }
              if(head->direct !=1)
                     if (a[y+1][x]==0 || a[y+1][x]==100)
                     {wellhead=checkwell(head,x,y+1);
                     if (wellhead=='\0')
                            direct=direct+2;
                     else
                            wellhead->direct =wellhead->direct-1;
                     }
              if(head->direct !=2)
                     if (a[y-1][x]==0 || a[y-1][x]==100)
                     {wellhead=checkwell(head,x,y-1);
                     if (wellhead=='\0')
                            direct=direct+1;
                     else
                            wellhead->direct =wellhead->direct-2;
                     }
              a[head->y][head->x]=0;
              if (a[y][x]!=100) a[y][x]=99;
              head=new datalist(x,y,direct,head);
              system("CLS");
              picture();
                     
              }



//file.open(filepath,ios::out);
//if (!file)
//{
//       cerr<<"XXXXX"<<endl;
//       exit(1);
//}

//for(y=0;y<12;y++)
//{for(x=0;x<12;x++)
//              file<<a[y][x]<< " ";
//file<<endl;}
//file.close();





       while(head->next !='\0')
       {
              a[head->y][head->x]=99;
              head=head->next;
       }

picture();


//cout<<"走出了"<<endl;



       
}


[ 此文章被s89tsvs62219在2005-04-20 00:40重新编辑 ]


献花 x0 回到顶端 [1 楼] From:台湾 台北市 | Posted:2005-04-18 20:15 |
Freelife
数位造型
个人文章 个人相簿 个人日记 个人地图
初露锋芒
级别: 初露锋芒 该用户目前不上站
推文 x2 鲜花 x60
分享: 转寄此文章 Facebook Plurk Twitter 复制连结到剪贴簿 转换为繁体 转换为简体 载入图片

下面是引用凯西男孩于2005-04-18 18:13发表的 求助【帮改程式码】:
这是一个迷宫的程式,8*8的,大致上就是这样,我就是改不好,好心的大大帮个忙吧!谢谢,感激不尽。
[code]#include <iostream.h>
#include <stdio.h>
#include <stdlib.h>
.......


是真得改不好,还是赖得改.....

像这一行:
}while(maze<i>[j]==Ɔ' || maze<i>[j]==ƈ');    
应该是:
  }while(maze[j]==Ɔ' || maze[j]==ƈ');    

连这样的错误,都不自己先解决的话,
很难让其他人想帮你......

只是表达个人的看法,请勿见怪 表情


献花 x0 回到顶端 [2 楼] From:台湾中华电信 | Posted:2005-04-19 10:07 |
凯西男孩
个人文章 个人相簿 个人日记 个人地图
初露锋芒
级别: 初露锋芒 该用户目前不上站
推文 x0 鲜花 x24
分享: 转寄此文章 Facebook Plurk Twitter 复制连结到剪贴簿 转换为繁体 转换为简体 载入图片

那一行是老师教我那样打上去的,我也没有觉的那行有问题,反而是换成这位大大你的那行才变的奇怪了说= =天呀~~~~~~~~~~~~好难呀~~~~~~~~~


献花 x0 回到顶端 [3 楼] From:台湾中华电信 | Posted:2005-04-19 22:02 |
codeboy 手机
个人文章 个人相簿 个人日记 个人地图
社区建设奖
小有名气
级别: 小有名气 该用户目前不上站
推文 x6 鲜花 x331
分享: 转寄此文章 Facebook Plurk Twitter 复制连结到剪贴簿 转换为繁体 转换为简体 载入图片

下面是引用凯西男孩于2005-04-19 22:02发表的 :
那一行是老师教我那样打上去的,我也没有觉的那行有问题,反而是换成这位大大你的那行才变的奇怪了说= =天呀~~~~~~~~~~~~好难呀~~~~~~~~~
因为你贴程式码的时候...没有注意 wind code码
版上的说明文件已经说明了[ i ]会变成 <i>的原因...
去修正你的原始po文吧~ 表情
http://bbs1.mychat.to/read.php?tid=255780&toread=1&fp=1



连结有问题请来信,我会尽快修正~^^
通报时请附上是"哪一篇失效"...这样我才能去修正~麻烦各位好心人士了~

[连结失效通报][ 网页.伺服.程式 讨论区]
----------------------在世界中心呼喊爱情----------------------
深深思念一个人的时候,我们不知不觉的地活在世界的中心...
献花 x0 回到顶端 [4 楼] From:台湾中华电信 | Posted:2005-04-19 22:19 |
kk889180
个人头像
个人文章 个人相簿 个人日记 个人地图
小人物
级别: 小人物 该用户目前不上站
推文 x0 鲜花 x61
分享: 转寄此文章 Facebook Plurk Twitter 复制连结到剪贴簿 转换为繁体 转换为简体 载入图片

下面是引用凯西男孩于2005-04-18 18:13发表的 求助【帮改程式码】:
这是一个迷宫的程式,8*8的,大致上就是这样,我就是改不好,好心的大大帮个忙吧!谢谢,感激不尽。
[code]#include <iostream.h>
#include <stdio.h>
#include <stdlib.h>
.......

  if(success != 0 && maze<i>[j+1] == 1) visit(i, j+1);
  if(success != 0 && maze[i+1][j] == 1) visit(i+1, j);
  if(success != 0 && maze<i>[j-1] == 1) visit(i, j-1);
  if(success != 0 && maze[i-1][j] == 1) visit(i-1, j);

判别式有点问题
当maze[j]==1 那你出口(maze[j]==2)就走不进去啦 (过门而不入的老鼠 )


[ 此文章被kk889180在2005-04-22 11:53重新编辑 ]


献花 x0 回到顶端 [5 楼] From:台湾教育部 | Posted:2005-04-20 14:59 |

首页  发表文章 发表投票 回覆文章
Powered by PHPWind v1.3.6
Copyright © 2003-04 PHPWind
Processed in 0.024109 second(s),query:16 Gzip disabled
本站由 瀛睿律师事务所 担任常年法律顾问 | 免责声明 | 本网站已依台湾网站内容分级规定处理 | 连络我们 | 访客留言