java - Search 2d Array -
so im writing java program should find shortest way entrance "2"
1 of numbers "3"
. can walk on " "
positions. "1"
walls.
11111121 131 1 1 1 1111 1 1 13 1 1 1 11 1 1 1 1 1 1 11111111
my starting idea find entrance in 2d array. done this:
point entrance = new point(0,0); (int = 0; < n; i++) { (int j = 0; j < n; j++){ if(map[i][j] == 2){ entrance.x =i; entrance.y =j; } }
i find 2 "3"
, save them in points. but im not sure how return rute closest "3"
. considering joystick, save direction go, (up, down, left, right). return full list of moves entrance closests 3. got suggestion or ideas how implement ?
what have here non-cannonical representation of graph. have each cell being vertex in graph , have edge between 2 neighboring cells if , if both of them free.
now @ problem in way, find entrance , breadth first search find exit.