Write a clean, efficient algorithm to detect and resolve gridlock conditions in a simulated robotic routing system for Foundation Robotics Labs.