One of the primary challenges for robotic manure cleaners in pig farming is to plan the shortest path to designated cleaning points under specified conditions with minimal processing cost and time, while avoiding collisions. However, pigs are randomly distributed in actual pig farms, which obstructs the robots' movement and complicates the rapid determination of optimal solutions. To address these issues, this study introduces the concept of interaction among cellular automaton cell neighborhoods and proposes the Cellular Automata Slime Mold Algorithm (CASMA). This enhanced slime mold algorithm accelerates convergence speed and improves search accuracy. To validate its effectiveness, CASMA was compared with four metaheuristic algorithms (ACO, FA, PSO, and WPA) through performance tests and simulated experiments. Results demonstrate that in complex pigsty environments with varying numbers of pigs, CASMA reduces average step consumption by 8.03%, 1.61%, 0.99%, and 4.26% compared with these algorithms and saves processing time by averages of 13.20%, 20.11%, 10.86%, and 6.4%, respectively. In addition, in dynamic obstacle experiments, CASMA achieved average time savings of 48.27% and 56.28% compared with A* and TS, respectively, while reducing step consumption. Overall, CASMA enhances the efficiency of manure‐cleaning robots in pig farms, thereby improving animal welfare.