本帖最后由 stu 于 2015-10-8 08:58 AM 编辑
假如地圖範例如下 :
┌─┬─┬─┬─┬─┐
│ │ │ │ │
├ ┼ ┼ ┼ ┼ ┤
│ │ │ │
├ ┼─┼─┼ ┼ ┤
│ │ │★ │ │
├ ┼ ┼ ┼─┼ ┤
│ │ │
├ ┼ ┼─┼ ┼─┤
│ │ │ │
└─┴─┴─┴─┴─┘
★:代表當前位置
小弟我將上圖轉成數字陣列
1,0,1,0,1,1,1,0,1
1,0,1,0,1,0,1,0,1
1,1,1,1,1,0,1,0,1
1,0,0,0,0,0,1,0,1
1,0,1,0,2,1,1,0,1
1,0,1,0,1,0,0,0,1
1,1,1,0,1,1,1,1,1
1,0,1,0,0,0,1,0,0
1,0,1,1,1,0,1,1,1
0:無路
1:有路
2:當前未置
弄成座標位置是:
座標位置 = {東,西,南,北}
map[0][0] = {0,0,0,1}
map[0][1] = {1,0,0,1}
map[0][2] = {0,1,0,0}
map[0][3] = {1,0,0,1}
map[0][4] = {0,1,0,0}
map[1][0] = {1,0,1,1}
map[1][1] = {0,1,1,1}
map[1][2] = {1,0,0,1}
map[1][3] = {1,1,1,0}
map[1][4] = {0,1,0,1}
map[2][0] = {0,0,1,1}
map[2][1] = {0,0,1,0}
map[2][2] = {1,0,1,0}
map[2][3] = {0,1,0,1}
map[2][4] = {0,0,1,1}
map[3][0] = {1,0,1,1}
map[3][1] = {1,1,0,1}
map[3][2] = {0,1,0,1}
map[3][3] = {0,0,1,1}
map[3][4] = {0,0,1,1}
map[4][0] = {0,0,1,0}
map[4][1] = {0,0,1,0}
map[4][2] = {1,0,1,0}
map[4][3] = {0,1,1,0}
map[4][4] = {0,0,1,0}
左下角座標是0,0 右上角座標是4,4
如要從當前座標點2,2 走到座標點0,4的話
這部分的程式該怎麼著手去寫呢?
請各位大大幫忙解惑一下,謝謝 ! |