Skip to content

Commit

Permalink
Move number of games and number of players in haggling into WorldConfig
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 675584184
Change-Id: I530103bf6c02a8402440bb94a142b51d3344f9d6
  • Loading branch information
vezhnick authored and copybara-github committed Sep 17, 2024
1 parent 5d52787 commit 1b522f9
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions examples/modular/environment/haggling.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@

DEFAULT_TIME_AND_PLACE_MODULES = ('fruitville_haggling',)

NUM_MAIN_PLAYERS = 3

NUM_GAMES = 2

MAJOR_TIME_STEP = datetime.timedelta(minutes=5)
MINOR_TIME_STEP = datetime.timedelta(seconds=10)

Expand All @@ -83,6 +79,8 @@ class WorldConfig:
only_match_with_support: Whether to only match with supporting players.
buyer_base_reward_min: The minimum base reward for the buyer.
seller_base_reward_max: The maximum base reward for the seller.
num_games: The number of games to play.
num_main_players: The number of main players in the scenario.
"""

year: int
Expand All @@ -97,6 +95,8 @@ class WorldConfig:
only_match_with_support: bool = False
buyer_base_reward_min: int = 5
seller_base_reward_max: int = 2
num_games: int = 2
num_main_players: int = 3


def bargain_statements(
Expand Down Expand Up @@ -199,15 +199,15 @@ def configure_players(
names = sampled_settings.people

player_configs = []
for i in range(NUM_MAIN_PLAYERS):
for i in range(sampled_settings.num_main_players):
name = names[i]
gender = sampled_settings.person_data[name]['gender']

config = configure_player(name, gender, sampled_settings.year, is_main=True)
player_configs.append(config)

for i in range(sampled_settings.num_supporting_players):
name = names[i + NUM_MAIN_PLAYERS]
name = names[i + sampled_settings.num_main_players]
gender = sampled_settings.person_data[name]['gender']

config = configure_player(
Expand Down Expand Up @@ -405,7 +405,7 @@ def configure_scenes(
else:
pairs = _create_all_pairs(players)

for i in range(NUM_GAMES * len(pairs)):
for i in range(sampled_settings.num_games * len(pairs)):

buyer_base_reward = random.randint(
sampled_settings.buyer_base_reward_min, 6
Expand Down Expand Up @@ -537,6 +537,8 @@ def __init__(
time_and_place_module: str | None = None,
num_supporting_player: int = 0,
only_match_with_support: bool = False,
num_games: int = 2,
num_main_players: int = 3,
):
"""Initialize the simulation object.
Expand All @@ -561,6 +563,8 @@ def __init__(
num_supporting_player: the number of supporting players.
only_match_with_support: whether to only match main players with
supporting players.
num_games: the number of games to play.
num_main_players: the number of main players.
"""
# Support for these parameters will be added in a future addition coming
# very imminently.
Expand All @@ -574,6 +578,8 @@ def __init__(
)
sampled_settings.num_supporting_players = num_supporting_player
sampled_settings.only_match_with_support = only_match_with_support
sampled_settings.num_main_players = num_main_players
sampled_settings.num_games = num_games

start_time = datetime.datetime(
year=time_and_place_params.YEAR,
Expand Down

0 comments on commit 1b522f9

Please sign in to comment.