Help with motor encoder storing values and read from array's

So I'm trying to build an obstacle avoiding robot which will drive around and store the encoder values from the front left and right motor.

I've been searching around on google and can't find a full explained project for this.

I've written some code up until this point, but I'm lost on how to use the array and encoder values for such a thing. I've read up and used both things before but very simple.

Have anyone in here done this before or have found a good explained tutorial for storing encoder values obtained from driving around sensing obstacles and avoiding those and after a certain time or maybe 2000 samples stored then the robot will reverse drive back to the starting point again.

Please post your full sketch. If possible you should always post code directly in the forum thread as text using code tags (</> button on the toolbar). This will make it easy for anyone to look at it, which will increase the likelihood of you getting help. If the sketch is longer than the forum will allow then it's ok to add it as an attachment.

When your code requires a library that's not included with the Arduino IDE please always post a link(using the chain link icon on the toolbar to make it clickable) to where you downloaded that library from or if you installed it using Library Manger(Sketch > Include Library > Manage Libraries) then say so and state the full name of the library.

You have to break down the robot movement into pieces of straight moves and curves. Let the encoder counters start at zero, and make the robot move straight ahead. As soon as an obstacle is detected, remember the length (counter values) of that straight move in the first array position. Then your robot will have to make a turn, in order to bypass the obstacle. You'll e.g. make it turn until the obstacle is out of sight, and store the elapsed encoder counts of both wheels in the next array entry. Finally inspect the array for the path taken, and do with it whatever you like.