function actions_samples = generate_actions_samples(world_state, P)

% generate actions for all other entities (i.e. except for entity id#1) based on
% a set of parent samples (all corresponding to one Hero action)

% algorithm: take all combinations of goals for other entites
% j=1:number_samples; k=1:length(entities)
% action_samples(j,k)


empty_sample.action = [];
empty_sample.likelihood = 1;

if length(P.cars) < 2
  actions_samples = [];
  return
end

% get car2 samples
car2_distribution = P.cars(2).action_distribution(world_state, P);

if length(P.cars) == 2
  %  actions_samples(:, 1) = empty_sample;
  actions_samples(:, 2) = car2_distribution.samples;
  return
end


car3_distribution = P.cars(3).action_distribution(world_state, P);
if length(P.cars) == 3
  combs = combvec(1:length(car2_distribution.samples), 1:length(car3_distribution.samples));
  %  actions_samples(:, 1) = empty_sample;
  actions_samples(:, 2) = car2_distribution.samples(combs(:, 1));
  actions_samples(:, 3) = car3_distribution.samples(combs(:, 2));
  return
end


car4_distribution = P.cars(4).action_distribution(world_state, P);
if length(P.cars) == 4
  combs = combvec(1:length(car2_distribution.samples), 1:length(car3_distribution.samples), 1:length(car4_distribution.samples));
  %  actions_samples(:, 1) = empty_sample;
  actions_samples(:, 2) = car2_distribution.samples(combs(1, :));
  actions_samples(:, 3) = car3_distribution.samples(combs(2, :));
  actions_samples(:, 4) = car4_distribution.samples(combs(3, :));
  return
end

car5_distribution = P.cars(5).action_distribution(world_state, P);
if length(P.cars) == 5
  combs = combvec(1:length(car2_distribution.samples), 1:length(car3_distribution.samples), ...
                  1:length(car4_distribution.samples), 1:length(car5_distribution.samples));
  %  actions_samples(:, 1) = empty_sample;
  actions_samples(:, 2) = car2_distribution.samples(combs(1, :));
  actions_samples(:, 3) = car3_distribution.samples(combs(2, :));
  actions_samples(:, 4) = car4_distribution.samples(combs(3, :));
  actions_samples(:, 5) = car5_distribution.samples(combs(4, :));
  return
end

car6_distribution = P.cars(6).action_distribution(world_state, P);
if length(P.cars) == 6
  combs = combvec(1:length(car2_distribution.samples), 1:length(car3_distribution.samples), ...
                  1:length(car4_distribution.samples), 1:length(car5_distribution.samples), ...
                  1:length(car6_distribution.samples));
  %  actions_samples(:, 1) = empty_sample;
  actions_samples(:, 2) = car2_distribution.samples(combs(1, :));
  actions_samples(:, 3) = car3_distribution.samples(combs(2, :));
  actions_samples(:, 4) = car4_distribution.samples(combs(3, :));
  actions_samples(:, 5) = car5_distribution.samples(combs(4, :));
  actions_samples(:, 6) = car6_distribution.samples(combs(5, :));    
  return
end

car7_distribution = P.cars(7).action_distribution(world_state, P);
if length(P.cars) == 7
  combs = combvec(1:length(car2_distribution.samples), 1:length(car3_distribution.samples), ...
                  1:length(car4_distribution.samples), 1:length(car5_distribution.samples), ...
                  1:length(car6_distribution.samples), 1:length(car7_distribution.samples));
  %  actions_samples(:, 1) = empty_sample;
  actions_samples(:, 2) = car2_distribution.samples(combs(1, :));
  actions_samples(:, 3) = car3_distribution.samples(combs(2, :));
  actions_samples(:, 4) = car4_distribution.samples(combs(3, :));
  actions_samples(:, 5) = car5_distribution.samples(combs(4, :));
  actions_samples(:, 6) = car6_distribution.samples(combs(5, :));    
  actions_samples(:, 7) = car7_distribution.samples(combs(6, :));    
  return
end

car8_distribution = P.cars(8).action_distribution(world_state, P);
if length(P.cars) == 8
  combs = combvec(1:length(car2_distribution.samples), 1:length(car3_distribution.samples), ...
                  1:length(car4_distribution.samples), 1:length(car5_distribution.samples), ...
                  1:length(car6_distribution.samples), 1:length(car7_distribution.samples), ...
                  1:length(car8_distribution.samples));
  %  actions_samples(:, 1) = empty_sample;
  actions_samples(:, 2) = car2_distribution.samples(combs(1, :));
  actions_samples(:, 3) = car3_distribution.samples(combs(2, :));
  actions_samples(:, 4) = car4_distribution.samples(combs(3, :));
  actions_samples(:, 5) = car5_distribution.samples(combs(4, :));
  actions_samples(:, 6) = car6_distribution.samples(combs(5, :));    
  actions_samples(:, 7) = car7_distribution.samples(combs(6, :));    
  actions_samples(:, 8) = car7_distribution.samples(combs(7, :));
  return
end

