I recommend looking into different pathfinding algorithms, such as the A star algorithm which is commonly used for looped maze solving. You might also find my post here helpful as well; it has details of the methods I used in a 2014 looped maze solving competition we did with our local robotics club.
Brandon
