So I am trying to make code for a robot that solves a maze. The way it solves the maze is using the left hand rule - if there is a left, go left; if no, go straight; if no, go right; if none available, turn around. What I want it to do is once it goes through a maze once, it optimizes its path according to the decisions it made while going through the maze. For instance, if the robot went left, turned around, then went left again, the whole thing is equivalent to just going straight.
So what I have thought up is storing the decisions of the first run in an array (say something like moves[] = {'L', 'S', 'T', 'L'}), then modifying that according to the rules at the end of this question (so the moves[] array should become {'L', 'R'} because STL --> R).
So my question is, how do I make a program that goes through the initial moves[] array, finds the patterns, modifies, and repeats until the array is optimized? This doesn't just involve replacing elements but reducing the size of the array.
RTS = L; LTS = R; STS = T; STR = L; STL = R
RTL = T; RTR = S; LTL = S; LTR = T