From 1f795b15d68e59e1ca3f5e497b253a089d76e1b7 Mon Sep 17 00:00:00 2001 From: John Agapiou Date: Tue, 28 May 2024 05:55:45 -0700 Subject: [PATCH] Fix edge cases caught by pylint PiperOrigin-RevId: 637869856 Change-Id: Ida1bc9fe47ec76eef11c0dd157f8b58158782a66 --- .../bach_or_stravinsky_in_the_matrix__arena.py | 15 ++++++++------- .../bach_or_stravinsky_in_the_matrix__repeated.py | 15 ++++++++------- meltingpot/configs/substrates/fruit_market.py | 11 ++++++----- .../substrates/paintball__capture_the_flag.py | 6 +++++- .../substrates/paintball__king_of_the_hill.py | 4 +++- .../configs/substrates/reaction_graph_utils.py | 10 ++-------- 6 files changed, 32 insertions(+), 29 deletions(-) diff --git a/meltingpot/configs/substrates/bach_or_stravinsky_in_the_matrix__arena.py b/meltingpot/configs/substrates/bach_or_stravinsky_in_the_matrix__arena.py index 8c98ff27..d3d80b19 100644 --- a/meltingpot/configs/substrates/bach_or_stravinsky_in_the_matrix__arena.py +++ b/meltingpot/configs/substrates/bach_or_stravinsky_in_the_matrix__arena.py @@ -483,16 +483,17 @@ def create_avatar_objects( if player_idx % 2 == 0: row_player = True color = (50, 100, 200) - elif player_idx % 2 == 1: + else: row_player = False color = (200, 100, 50) + elif role == "bach_fan": + row_player = True + color = (50, 100, 200) + elif role == "stravinsky_fan": + row_player = False + color = (200, 100, 50) else: - if role == "bach_fan": - row_player = True - color = (50, 100, 200) - elif role == "stravinsky_fan": - row_player = False - color = (200, 100, 50) + raise ValueError(f"Unsupported role: {role}") avatar = create_avatar_object(player_idx, color, row_player) avatar_objects.append(avatar) readiness_marker = the_matrix.create_ready_to_interact_marker(player_idx) diff --git a/meltingpot/configs/substrates/bach_or_stravinsky_in_the_matrix__repeated.py b/meltingpot/configs/substrates/bach_or_stravinsky_in_the_matrix__repeated.py index 0f42b494..61119d9c 100644 --- a/meltingpot/configs/substrates/bach_or_stravinsky_in_the_matrix__repeated.py +++ b/meltingpot/configs/substrates/bach_or_stravinsky_in_the_matrix__repeated.py @@ -480,16 +480,17 @@ def create_avatar_objects( if player_idx % 2 == 0: row_player = True color = (50, 100, 200) - elif player_idx % 2 == 1: + else: row_player = False color = (200, 100, 50) + elif role == "bach_fan": + row_player = True + color = (50, 100, 200) + elif role == "stravinsky_fan": + row_player = False + color = (200, 100, 50) else: - if role == "bach_fan": - row_player = True - color = (50, 100, 200) - elif role == "stravinsky_fan": - row_player = False - color = (200, 100, 50) + raise ValueError(f"Unsupported role: {role}") avatar = create_avatar_object(player_idx, color, row_player) avatar_objects.append(avatar) diff --git a/meltingpot/configs/substrates/fruit_market.py b/meltingpot/configs/substrates/fruit_market.py index 1cb9b7b3..882c5727 100644 --- a/meltingpot/configs/substrates/fruit_market.py +++ b/meltingpot/configs/substrates/fruit_market.py @@ -1160,13 +1160,14 @@ def create_avatar_objects(roles: Sequence[str], # farmers and odd numbered players to be apple farmers. if player_idx % 2 == 1: specialty = "apple" - elif player_idx % 2 == 0: + else: specialty = "banana" + elif role == "apple_farmer": + specialty = "apple" + elif role == "banana_farmer": + specialty = "banana" else: - if role == "apple_farmer": - specialty = "apple" - elif role == "banana_farmer": - specialty = "banana" + raise ValueError(f"Unsupported role: {role}") game_object = create_avatar_object(player_idx, specialty, max_stamina_bar_states - 1) diff --git a/meltingpot/configs/substrates/paintball__capture_the_flag.py b/meltingpot/configs/substrates/paintball__capture_the_flag.py index 95b0d46b..a61c2826 100644 --- a/meltingpot/configs/substrates/paintball__capture_the_flag.py +++ b/meltingpot/configs/substrates/paintball__capture_the_flag.py @@ -432,6 +432,8 @@ def create_flag_prefab(team: str): flag_color = RED_COLOR elif team == "blue": flag_color = BLUE_COLOR + else: + raise ValueError(f"Unsupported team : {team}") prefab = { "name": "{}_flag".format(team), @@ -714,7 +716,7 @@ def _even_vs_odd_team_assignment(num_players, for player_idx in range(0, num_players): if player_idx % 2 == 0: team = "red" - elif player_idx % 2 == 1: + else: team = "blue" game_object = create_avatar_object(player_idx, team, override_taste_kwargs=taste_kwargs) @@ -733,6 +735,8 @@ def _low_vs_high_team_assignment(num_players, team = "blue" elif player_idx > median: team = "red" + else: + raise ValueError("num_players must be even") game_object = create_avatar_object(player_idx, team, override_taste_kwargs=taste_kwargs) avatar_objects.append(game_object) diff --git a/meltingpot/configs/substrates/paintball__king_of_the_hill.py b/meltingpot/configs/substrates/paintball__king_of_the_hill.py index 68c8476c..697e2faa 100644 --- a/meltingpot/configs/substrates/paintball__king_of_the_hill.py +++ b/meltingpot/configs/substrates/paintball__king_of_the_hill.py @@ -694,7 +694,7 @@ def _even_vs_odd_team_assignment(num_players, for player_idx in range(0, num_players): if player_idx % 2 == 0: team = "red" - elif player_idx % 2 == 1: + else: team = "blue" game_object = create_avatar_object(player_idx, team, override_taste_kwargs=taste_kwargs) @@ -713,6 +713,8 @@ def _low_vs_high_team_assignment(num_players, team = "blue" elif player_idx > median: team = "red" + else: + raise ValueError("num_players must be even") game_object = create_avatar_object(player_idx, team, override_taste_kwargs=taste_kwargs) avatar_objects.append(game_object) diff --git a/meltingpot/configs/substrates/reaction_graph_utils.py b/meltingpot/configs/substrates/reaction_graph_utils.py index db8d4d48..4fd3b72a 100644 --- a/meltingpot/configs/substrates/reaction_graph_utils.py +++ b/meltingpot/configs/substrates/reaction_graph_utils.py @@ -224,15 +224,9 @@ def create_cell_prefab(compound_name, compounds, reactivity_levels, if sprites: def get_palette(sprite_color): - if len(sprite_color) == 3: - x_color = EMPTY_COLOR[0:3] - a_color = (252, 252, 252) - elif len(sprite_color) == 4: - x_color = EMPTY_COLOR - a_color = (252, 252, 252, 255) return { - "x": x_color, - "a": a_color, + "x": EMPTY_COLOR[0:len(sprite_color)], + "a": (252,) * len(sprite_color), "b": sprite_color, "c": multiply_tuple(sprite_color, 0.2), "d": sprite_color