def sample_parameters(
    num_flavor_prompts_per_player: int = DEFAULT_NUM_FLAVOR_PROMPTS,
    seed: int | None = None,
):
  """Sample parameters of the setting and the backstory for each player."""
  seed = seed if seed is not None else random.getrandbits(63)
  rng = random.Random(seed)
  poor_work_conditions = tuple(
      rng.sample(
          BAD_GARMENT_WORK_CONDITIONS, DEFAULT_NUM_BACKGROUND_BAD_CONDITIONS
      )
  )
  config = WorldConfig(
      year=YEAR,
      location='New York City',
      background_poor_work_conditions=poor_work_conditions,
      seed=seed,
  )

  shuffled_male_names = list(rng.sample(MALE_NAMES, len(MALE_NAMES)))
  shuffled_female_names = list(rng.sample(FEMALE_NAMES, len(FEMALE_NAMES)))

  sampled_railroad_name = rng.choice(FACTORY_NAMES)

  sampled_antagonist_gender = rng.choice(GENDERS)
  if sampled_antagonist_gender == 'male':
    sampled_antagonist_name = shuffled_male_names.pop()
  else:
    sampled_antagonist_name = shuffled_female_names.pop()
  config.antagonist = sampled_antagonist_name

  sampled_organizer_gender = rng.choice(GENDERS)
  if sampled_organizer_gender == 'male':
    sampled_organizer_name = shuffled_male_names.pop()
  else:
    sampled_organizer_name = shuffled_female_names.pop()
  config.organizer = sampled_organizer_name

  shuffled_talking_points = list(
      rng.sample(
          OVERHEARD_ORGANIZER_TALKING_POINTS,
          len(OVERHEARD_ORGANIZER_TALKING_POINTS),
      )
  )
  config.overheard_strike_talk = [
      OVERHEARD_ORGANIZER_INTRO.format(
          organizer_name=config.organizer, talking_point=talking_point
      )
      for talking_point in shuffled_talking_points
  ]

  world_elements = list(
      rng.sample(WORLD_BUILDING_ELEMENTS, NUM_WORLD_BUILDING_ELEMENTS)
  )
  railroad_worker_elements = list(
      rng.sample(GARMENT_WORKER_BIOS, NUM_GARMENT_WORKER_ELEMENTS)
  )
  antagonist_elements = list(
      rng.sample(ANTAGONIST_ELEMENTS, NUM_ANTAGONIST_ELEMENTS)
  )
  organizer_rumors = list(
      rng.sample(LABOR_ORGANIZER_RUMORS, NUM_ORGANIZER_RUMORS)
  )

  formatted_world_elements = []
  formative_memory_prompts = {}
  for element_string in (
      world_elements
      + railroad_worker_elements
      + antagonist_elements
      + organizer_rumors
  ):
    person_name = None
    gender = None
    if 'worker_name' in extract_braces(element_string):
      # Instantiate a new character.
      gender = rng.choice(GENDERS)
      if gender == 'male':
        person_name = shuffled_male_names.pop()
      else:
        person_name = shuffled_female_names.pop()
      salient_poor_conditions = tuple(
          rng.sample(
              poor_work_conditions, DEFAULT_NUM_SALIENT_POOR_WORK_CONDITIONS
          )
      )
      config.append_person(person_name, gender, salient_poor_conditions)
      formative_memory_prompts[person_name] = []
      protagonist_backstory_elements = list(
          rng.sample(
              PROTAGONIST_BACKSTORY_FLAVOR_PROMPTS,
              num_flavor_prompts_per_player,
          )
      )
      protagonist_backstory_elements += PROTAGONIST_BACKSTORY_CRITICAL_PROMPTS
      for protagonist_element_string in protagonist_backstory_elements:
        protagonist_generated = _details_generator(
            element_string=protagonist_element_string,
            person_name=person_name,
            person_gender=gender,
            factory_name=sampled_railroad_name,
            antagonist_name=sampled_antagonist_name,
            antagonist_gender=sampled_antagonist_gender,
            organizer_name=sampled_organizer_name,
            organizer_gender=sampled_organizer_gender,
            rng=rng,
        )
        protagonist_generated['worker_name'] = person_name
        _add_pronouns(protagonist_generated, gender=gender)
        formative_memory_prompts[person_name].append(
            protagonist_element_string.format(**protagonist_generated)
        )

    generated = _details_generator(
        element_string=element_string,
        person_name=person_name,
        person_gender=gender,
        factory_name=sampled_railroad_name,
        antagonist_name=sampled_antagonist_name,
        antagonist_gender=sampled_antagonist_gender,
        organizer_name=sampled_organizer_name,
        organizer_gender=sampled_organizer_gender,
        rng=rng,
    )
    formatted_world_elements.append(element_string.format(**generated))

  antagonist_own_memories = []
  for element_string in ANTAGONIST_OWN_MEMORIES:
    generated = _details_generator(
        element_string=element_string,
        person_name=None,
        person_gender=None,
        factory_name=sampled_railroad_name,
        antagonist_name=sampled_antagonist_name,
        antagonist_gender=sampled_antagonist_gender,
        organizer_name=sampled_organizer_name,
        organizer_gender=sampled_organizer_gender,
        rng=rng,
    )
    antagonist_own_memories.append(element_string.format(**generated))
  organizer_own_memories = []
  for element_string in LABOR_ORGANIZER_OWN_MEMORIES:
    generated = _details_generator(
        element_string=element_string,
        person_name=None,
        person_gender=None,
        factory_name=sampled_railroad_name,
        antagonist_name=sampled_antagonist_name,
        antagonist_gender=sampled_antagonist_gender,
        organizer_name=sampled_organizer_name,
        organizer_gender=sampled_organizer_gender,
        rng=rng,
    )
    organizer_own_memories.append(element_string.format(**generated))

  config.world_elements = formatted_world_elements
  config.formative_memory_prompts = formative_memory_prompts
  config.person_data[sampled_antagonist_name] = dict(
      gender=sampled_antagonist_gender, salient_beliefs=antagonist_own_memories
  )
  config.person_data[sampled_organizer_name] = dict(
      gender=sampled_organizer_gender, salient_beliefs=organizer_own_memories
  )

  config.supporting_player_locations = (
      # Antagonist location
      (
          f'{sampled_antagonist_name} is inspecting the factory today and '
          'walking around the neighborhood.'
      ),
      # Organizer location
      (
          f'{sampled_organizer_name} will have dinner with the other workers '
          'tonight.'
      ),
  )

  if not config.people:
    # Handle unlikely case where no protagonists were generated.
    gender = rng.choice(GENDERS)
    if gender == 'male':
      person_name = shuffled_male_names.pop()
    else:
      person_name = shuffled_female_names.pop()
    salient_poor_conditions = tuple(
        rng.sample(
            poor_work_conditions, DEFAULT_NUM_SALIENT_POOR_WORK_CONDITIONS
        )
    )
    config.append_person(person_name, gender, salient_poor_conditions)

  return config
Sample parameters of the setting and the backstory for each player.
examples/deprecated/modular/environment/modules/garment_factory_labor.py