added collision detection to generatePositions method