Re: [請益] 踩地雷的踩空處理

看板Prob_Solve作者 (喲)時間11年前 (2012/09/28 08:40), 編輯推噓1(102)
留言3則, 3人參與, 最新討論串2/3 (看更多)
※ 引述《EdisonX (閉上眼的魚)》之銘言: : (3) 關鍵在於 M$ 點到 0 的時候會自動再往外爆開,但這個怎麼做? : 目前想法是,當遇到 0 的時候,開啟後,以 bfs 方向繼續往四個方向搜尋, : 搜尋到非零的時候就停下來, 從一格往四方向搜尋一定會重覆, 造成遞迴的困難, 應該要避開重覆. 像以下例子,先呼叫 expand_h(array, i, j) 然後 expand_w(array, i, j) 就可以安全結束. function expand_h ( array[][], i, j ) if array[i][j] =/= 0 exit function show(array[i][j]) expand1(array, i-1, j, "up") expand1(array, i+1, j, "down") expand_h(array, i, j-1) expand_h(array, i, j+1) function expand_w (array[][], i, j) if array[i][j] =/= 0 exit function show(aray[i][j]) expand1(array, i, j-1, "left") expand1(array, i, j+1, "right") expand_w(array, i-1, j) expand_w(array, i+1, j) function expand1 ( array[][], i, j , direction ) if array[i][j] =/= 0 exit function show(array[i][j]) case direction of "up": expand1 ( array, i-1, j, direction) "down": expand1 (array, i+1, j, direction) "left": expand1 (array, i, j-1, direction) "right": expand1 ( array, i, j+1, direction) -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 118.167.50.85

09/28 17:16, , 1F
您說的缺點確實我沒考慮,不過您的code我想半天還在想 orz
09/28 17:16, 1F

09/28 19:49, , 2F
沒時間,所以亂寫一堆pseudo code
09/28 19:49, 2F

09/28 22:00, , 3F
不會重複造成困難 原原PO的code有標記
09/28 22:00, 3F
文章代碼(AID): #1GPF7mKK (Prob_Solve)
文章代碼(AID): #1GPF7mKK (Prob_Solve)