On the formation of alliances in conflict and contests