Assume that a function takes s
(origin hexagon), f
(target hexagon) and n
(length of the path) values as parameters and outputs list of all possible paths that has n length. To visualize the problem please check the figure below:
Let's say our origin (s
) is the red dotted hex (2, 3)
and the target (f
) is the blue dotted one (5, 2)
. We want to reach blue dotted hex in 5 steps (n = 5
). Also consider that if a walk reaches a specific hex, it may stay in that hex as well in the next step. In other words, one of the possible paths can be (3, 2) - (4, 2) - (5, 2) - (5, 2) - (5, 2)
. It is also counted as 5-length path.
These are some example paths from (2, 3)
to (5, 2)
:
(1, 3) - (2, 3) - (3, 2) - (4, 3) - (5, 2)
(3, 3) - (4, 4) - (5, 4) - (5, 3) - (5, 2)
(2, 3) - (2, 3) - (3, 3) - (4, 3) - (5, 2)
I want to find all of these paths in a way. However, I could not determine which algorithm gives the most efficient solution to handle this problem. The first thing comes to mind is to use depth-first-search but I wonder is there any better alternative to use in this case.