It is almost impossible to lose the game. Even when you are out of moves, you can click the blue button with an inverse arrow to undo your last move.

The button is located in the top right corner of the screen when you play the game. You can use it as many times as you need. Use it to return to the point where you can change the direction of your steps, follow another sequence, and consequently win the game!