1 / 6

資料結構實習 - 七

資料結構實習 - 七. 迷宮的表示方法. 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 0 0 0 1 1 1 1 1 0 1 1 1 1 0 0 1 0 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1. 一個二維陣列的迷宮 maze[row][col]: 表示迷宮中 第 row 列第 col 行的位置 0: 可通行路徑 1: 障礙 移動方向 北 (N) 、東北 (NE) 、東 (E) 、 東南 (SE) 、南 (S) 、西南 (SW) 、 西 (W) 、西北 (NW). 迷宮路徑的儲存.

larya
Download Presentation

資料結構實習 - 七

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 資料結構實習-七

  2. 迷宮的表示方法 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 0 0 0 1 1 1 1 1 0 1 1 1 1 0 0 1 0 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 • 一個二維陣列的迷宮 • maze[row][col]:表示迷宮中 第row列第col行的位置 • 0:可通行路徑 • 1:障礙 • 移動方向 • 北(N)、東北(NE)、東(E)、 東南(SE)、南(S)、西南(SW)、 西(W)、西北(NW)

  3. 迷宮路徑的儲存 #define MAX_STACK_SIZE 100 typedef struct { short int row; short int col ; short int dir ; }element; element stack[MAX_STACK_SIZE]; R 4 C 4 D 3 R 3 C 3 D 3 R 4 C 2 D 5 R 3 C 2 D 2 R 2 C 2 D 2 R 1 C 1 D 3

  4. dir的表示方法 typedef struct { short int vert; short int horiz; }dir; dir dirs[8];

  5. maze[1][1]: entrance 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 0 0 0 1 1 1 1 1 0 1 1 1 1 0 0 1 0 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 Initially set mark[1][1]=1 R 4 C 4 D 3 R 3 C 3 D 3 R 4 C 2 D 5 R 3 C 2 D 2 R 2 C 2 D 2 maze[5][5]: exit R 1 C 1 D 3 R 1 C 1 D 1

  6. 迷宮--練習 • 請完成一個程式找出迷宮中”所有”能夠到達終點的路徑,並將所有路徑輸出在螢幕。 • Path1:1 1 3 2 2 2 3 2 2 …… Path2:1 1 3 2 2 3 ……

More Related