def sample_parameters(
    seed: int | None = None,
):
  """Returns a config dict for the simulation."""
  seed = seed if seed is not None else random.getrandbits(63)
  rng = random.Random(seed)
  shuffled_village_names = list(
      rng.sample(VILLAGE_NAMES, len(VILLAGE_NAMES))
  )
  shuffled_male_names = list(rng.sample(MALE_NAMES, len(MALE_NAMES)))
  shuffled_female_names = list(rng.sample(FEMALE_NAMES, len(FEMALE_NAMES)))

  representative_a, representative_a_gender = _sample_name_and_gender(
      rng, shuffled_male_names, shuffled_female_names
  )
  representative_b, representative_b_gender = _sample_name_and_gender(
      rng, shuffled_male_names, shuffled_female_names
  )

  shared_epic_poem_key = rng.choice(list(SHARED_EPIC_POEMS.keys()))

  choices = dict(
      village_a=shuffled_village_names.pop(),
      village_b=shuffled_village_names.pop(),
      representative_a=representative_a,
      representative_b=representative_b,
      mythical_hero=rng.choice(MYTHICAL_HEROES),
      mythical_evil=rng.choice(MYTHICAL_EVIL_NAMES),
      mythical_tree=rng.choice(MYTHICAL_TREE_NAMES),
      mythical_title=rng.choice(MYTHICAL_TITLES),
      moon_goddess=rng.choice(MOON_GODDESS_NAMES),
      sun_god=rng.choice(SUN_GOD_NAMES),
      mythical_secondary_character_a=rng.choice(
          MYTHICAL_SECONDARY_CHARACTER_A_NAMES
      ),
      mythical_secondary_character_b=rng.choice(
          MYTHICAL_SECONDARY_CHARACTER_B_NAMES
      ),
      media_type=rng.choice(MEDIA_TYPES),
      spiritual_journey=rng.choice(SPIRITUAL_JOURNEY_TAKER_NAMES),
  )

  collective_unconscious = rng.sample(
      COLLECTIVE_UNCONSCIOUS_ELEMENTS, _NUM_COLLECTIVE_UNCONSCIOUS_ELEMENTS
  )
  shared_epic_poem = rng.sample(
      SHARED_EPIC_POEMS[shared_epic_poem_key], _NUM_SHARED_EPIC_POEM_ELEMENTS
  )

  villages = {}
  for key in ('a', 'b'):
    villages[key] = _sample_village_elements(
        rng=rng,
        key=key,
        collective_unconscious=collective_unconscious,
        shared_epic_poem=shared_epic_poem,
    )
    villages[key]['shared_task_elements'] = SHARED_TASK_ELEMENTS

  results = {'a': [], 'b': []}
  for selections in villages['a'].values():
    for text in selections:
      results['a'].append(text.format(**choices))
  for selections in villages['b'].values():
    for text in selections:
      results['b'].append(text.format(**choices))

  main_characters = {
      'a': dict(name=representative_a, gender=representative_a_gender),
      'b': dict(name=representative_b, gender=representative_b_gender),
  }

  config = config_dict.ConfigDict()

  config.times = config_dict.ConfigDict()
  config.times.setup = _SETUP_TIME
  config.times.start = _START_TIME
  config.times.meeting = _HILL_TIME
  config.times.post_meeting = _POST_HILL_TIME
  config.times.return_home = _RETURN_HOME_TIME
  config.times.decision = _DECISION_TIME
  config.times.debrief = _DEBRIEF_TIME

  config.village_a_name = choices['village_a']
  config.village_b_name = choices['village_b']

  config.basic_setting = BASIC_SETTING.format(
      village_a_name=config.village_a_name, village_b_name=config.village_b_name
  )

  config.villages = config_dict.FrozenConfigDict(results)

  config.main_characters = config_dict.FrozenConfigDict(main_characters)

  config.supporting_characters = config_dict.ConfigDict()
  config.supporting_characters.a = tuple((
      _sample_name_and_gender(rng, shuffled_male_names, shuffled_female_names)
      for _ in range(_NUM_SUPPORTING_CHARACTERS_PER_VILLAGE)
  ))
  config.supporting_characters.b = tuple((
      _sample_name_and_gender(rng, shuffled_male_names, shuffled_female_names)
      for _ in range(_NUM_SUPPORTING_CHARACTERS_PER_VILLAGE)
  ))

  config.barbarian_raid_info = list(
      rng.sample(BARBARIAN_RUMORS, _NUM_BARBARIAN_RUMORS)
  ) + [' The barbarian raids have become more frequent of late.']

  config.activities = (
      FREE_TIME_ACTIVITY,
      FARMING_ACTIVITY,
      WARRIOR_TRAINING_ACTIVITY,
  )
  config.free_time_activity = FREE_TIME_ACTIVITY
  config.farming_activity = FARMING_ACTIVITY
  config.warrior_training_activity = WARRIOR_TRAINING_ACTIVITY

  config.num_years = rng.randint(_MIN_YEARS, _MAX_YEARS)

  config.home_scene_premise = _HOME_SCENE_PREMISE

  config.defense_threshold = _DEFENSE_THRESHOLD
  config.starvation_threshold = _STARVATION_THRESHOLD

  config.sample_event_of_failing_to_repel_barbarians = lambda: rng.choice(
      _FAILED_TO_REPEL_BARBARIAN_RAID_EVENT_DESCRIPTIONS)
  config.sample_event_of_success_repelling_barbarians = lambda: rng.choice(
      _SUCCEEDED_TO_REPEL_BARBARIAN_RAID_EVENT_DESCRIPTIONS)
  config.sample_event_of_failing_to_grow_food = lambda: rng.choice(
      _FAILED_TO_GROW_ENOUGH_FOOD_EVENT_DESCRIPTIONS)
  config.sample_event_of_success_growing_food = lambda: rng.choice(
      _SUCCEEDED_TO_GROW_ENOUGH_FOOD_EVENT_DESCRIPTIONS)
  config.sample_event_no_treaty_in_effect = lambda: rng.choice(
      _NO_TREATY_IN_EFFECT_DESCRIPTIONS)
  config.sample_event_treaty_in_effect = lambda: rng.choice(
      _TREATY_IN_EFFECT_DESCRIPTIONS)

  config.meeting_location = 'the hill of accord'

  config.villager_how_things_are_constant = config_dict.ConfigDict()
  config.villager_how_things_are_constant.village_a = (
      'Everyone in {name}\'s family has always been a '
      'farmer. As long as anyone can remember, they have farmed their '
      'ancestral lands near {village_name}. {name} hates the idea of spending '
      'time on any activity other than farming or leisure.'
  )
  config.villager_how_things_are_constant.village_b = (
      '{name}\'s family values strength and believes in the importance of '
      'training for war. They have always felt that they would like to train '
      'more but the village\'s lack of food security has always made it hard. '
      'If one spends too much time training then they compromise farming and '
      'risk starvation. But if freedom from the threat of famine could be '
      'achieved then {name} would gladly spend more time training for war.'
  )
  config.home_phase_premise = (
      'Elder {player_name} is home in {village_name}, and knows it will '
      'be critical to gain the support of influential stakeholders '
      '{and_supporting_characters} '
      'if any agreement is to last. '
      '{player_name} should start seeking '
      'their support now. There is no time to rest.'
  )
  config.supporting_character_home_phase_premise = (
      '{player_name} is currently in {village_name} and has no intention of '
      'leaving today.'
  )
  config.negotiation_phase_premise = (
      'Elder {player_name} left {village_name} early in the morning and'
      f' arrived just now at {config.meeting_location}. The reason for this'
      ' meeting of the two elder representatives of their respective villages'
      f' ({config.main_characters.a.name} representing'
      f' {config.village_a_name} and'
      f' {config.main_characters.b.name} representing {config.village_b_name})'
      ' is as follows: barbarian raiders have been pillaging and burning the'
      ' land, and menacing both villages. It has been suggested that an'
      ' alliance for mutual defense against the barbarian threat would be'
      ' beneficial. The elders are meeting today to try to negotiate such an'
      ' alliance.'
  )
  config.negotiation_phase_extra_premise = (
      'Agriculture is critical to both villages. But, the more time spent '
      'training for war, the less time can be devoted to farming. Therefore '
      'the threat of starvation motivates poor attention to defense. If only '
      'the risk of starvation could be mitigated, then more time could be '
      'devoted to training for war and other pursuits, to the benefit of all.'
  )
  config.negotiation_phase_premise_addendum = (
      "There is no time to waste on small talk. It's important to get"
      ' down to business immediately by proposing specific provisions for'
      ' the alliance and responding to the proposals of others.'
  )
  config.negotiation_objective_thought = (
      'Thought: Specialization and division of labor is a good '
      'idea, perhaps one village could specialize in agriculture '
      'while the other specializes in their common defense. But '
      'such an arrangement could only work if the threat of '
      'starvation could be alleviated for the village specializing '
      'in training for war over agriculture.'
  )

  return config
Returns a config dict for the simulation.
examples/deprecated/modular/environment/modules/pre_state_villages.py