From b55d5b29f30cad1f23aabac12c6d2acdfa10e2ac Mon Sep 17 00:00:00 2001 From: Jeffer Peng Date: Thu, 29 Apr 2021 16:58:03 -0400 Subject: [PATCH] added back 0 reward if off road to reproduce previous behaviour --- examples/game_of_tag/tag_adapters.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/examples/game_of_tag/tag_adapters.py b/examples/game_of_tag/tag_adapters.py index a994068337..5ddb0ed997 100644 --- a/examples/game_of_tag/tag_adapters.py +++ b/examples/game_of_tag/tag_adapters.py @@ -179,8 +179,12 @@ def predator_reward_adapter(observations, env_reward_signal): if events.off_road: rew -= global_rewards.offroad - # print(f"predator {ego.id.split('-')[0]} reward: {rew} distance {distance_to_target}, laneIndex: {ego.lane_index}") - return rew + # if no prey vehicle avaliable, have 0 reward instead + # TODO: Test to see if this is neccessary + prey_vehicles = list(filter( + lambda v: _is_vehicle_wanted(v.id, PREY_IDS), observations.neighborhood_vehicle_states, + )) + return rew if len(prey_vehicles) > 0 else 0 def prey_reward_adapter(observations, env_reward_signal): @@ -212,4 +216,9 @@ def prey_reward_adapter(observations, env_reward_signal): if events.off_road: rew -= global_rewards.offroad - return rew + # if no predator vehicle avaliable, have 0 reward instead + # TODO: Test to see if this is neccessary + predator_vehicles = list(filter( + lambda v: _is_vehicle_wanted(v.id, PREDATOR_IDS), observations.neighborhood_vehicle_states, + )) + return rew if len(predator_vehicles) > 0 else 0