From what I see in your post , it should be fairly simple using A , although I don ' t know if you will get the results you want or if you even want to use that algorithm to generate tunnels . Your 2 D matrix consists of nodes in your maze , each with a value that corresponds to the type of material at said node right ? For A then , when using the priority queue , you are going to want to modify the weights of the new nodes you are pushing on as you traverse the maze aka graph . First will be Manhattan distance from your start node to the end node you want to nudge your search towards the end . Second will be an weight based on the type of material the new node is for floors , smaller for walls vs . stone so that it is more difficult to move through harder materials Finally the distance from the start node itself your entrance to the levelThe total weight of a new node pushed onto the PQ when searching is then weightn distn Manhattann typenOr some such . There is more to it , like the admissibility of the search heuristic in this case , the heuristic is Manhattann typen , but that might not be needed for a project like this . I think that answers the question you are asking , but if not let me know .