The ghosts are unable to reverse direction in Pac-Man. You should have your agent read this: https://pacman.holenet.info/
They only reverse on their own when the mode changes or you get a power pellet, otherwise they have to wait until a corner, otherwise you end up with behavior like you see in this where you both quickly dance back and forth on the otherside of a wall