廣告廣告
  加入我的最愛 設為首頁 風格修改
首頁 首尾
 手機版   訂閱   地圖  簡體 
您是第 2792 個閱讀者
 
發表文章 發表投票 回覆文章
  可列印版   加為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.030724 second(s),query:16 Gzip disabled
本站由 瀛睿律師事務所 擔任常年法律顧問 | 免責聲明 | 本網站已依台灣網站內容分級規定處理 | 連絡我們 | 訪客留言