I have just completed the 'which way to turn' puzzle using the following algorithm: if blocked turn left, else if blocked right move forward, else turn right, move forward. It works with this order of sequence but not if the order of the first two is reversed - which seems more logical in the context of the puzzle layout.
What is the explanation?
Comments
Correct me if I'm wrong
When I read your algorithm, this is what I interpreted:
1. If I cannot go forward, I should turn left.
2. If I can go forward, but cannot go right, then I should take a step forward.
3. If I can go forward, but can also go right, then I should turn right and take a step.
From looking at the puzzle, that appears to make sense.
If I reverse the first two steps in your logic, I get the following:
1. If I cannot go right, then I should take a step forward.
2. If I can go right, but cannot go forward, I should turn left.
3. If I can go right and can also go forward, then I should turn right and take a step.
This fails because I would attempt to go forward whenever the way to the right is blocked, regardless of whether or not the way forward is clear.
If I did not interpret your post correctly, let me know.
Another way
If I misinterpreted your question , please forgive me . I just thought of a simple way:
if blocked-right and blocked-left
take a step forward
else if blocked-right
turn left
else turn right