recursively go to the four directions and check if the next pos is visited and be careful about the duplicate path