calculate the adjacent positions