Please Help me to save shortest path in line maze solver

I am supposed to make a maze solving robot. which will analyse and remember shortest path in first run and will remember shortest path and go through it in 2nd run. Please Help me i need to complete my work before 30-9-18.

i have attached my code with this. Please suggest me the changes needed to save shortest path.

5_sensor_LHR_code.ino (3.85 KB)

  pinMode(Sensor4, INPUT); //Make Sensor1 pin as input pin

Wrong. Useless comments should NOT be copied and pasted. Doing so, without fixing them, makes you look stupid.

  RM = digitalRead(Sensor5);
  R =  digitalRead(Sensor4);
  M = digitalRead(Sensor3);
  L = digitalRead(Sensor2);
  LM = digitalRead(Sensor1);

The relationship between the pin number and the name of the variable holding the state of the pin ought to be obvious without having to backtrack to look at the comments.

You have no idea how long to turn left to execute a right angle turn, do you?

You have no idea how far you travel between turns, do you?

You can't expect to repeat a run, without having recorded any data, without knowing those two critical facts.