1
2
3
4
5
6
7
8
9
10
11
|
data = Import["R:\\maze.png", "Data"];
data[[;; 60, ;; 60]] = {255, 255, 255, 255};
maze = Map[If[# != {255, 255, 255, 255}, 1, 0] &, data, {2}];
size = Dimensions@maze;
edgeH = Table[ If[maze[[i, j]] + maze[[i, j + 1]] == 2, UndirectedEdge[{i, j}, {i, j + 1}]], {i, 1, size[[1]]}, {j, 1, size[[2]] - 1}];
edgeV = Table[ If[maze[[i, j]] + maze[[i + 1, j]] == 2, UndirectedEdge[{i, j}, {i + 1, j}]], {i, 1, size[[1]] - 1}, {j, 1, size[[2]]}];
graphEdges = Union[Select[Flatten[{edgeH, edgeV}], Length@# >= 2 &]];
{start, end}=Cases[ Position[maze,1], {1|641, _} ];
mazePath=FindShortestPath[Graph[graphEdges], start, end ];
RedValues = Extract[data, mazePath][[All, 1]][[2 ;; -1 ;; 2]];
Export["r:\\a.zip", FromCharacterCode[RedValues], "String"];
|