A programming approach to collective autonomy