Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
def reward_function(params):
'''
Example of rewarding the agent to follow center line
'''
# Read input parameters
track_width = params['track_width']
distance_from_center = params['distance_from_center']
all_wheels_on_track = params['all_wheels_on_track']
speed = params['speed']
SPEED_THRESHOLD = 1.0
# Calculate 3 markers that are at varying distances away from the center line
marker_1 = 0.1 * track_width
marker_2 = 0.25 * track_width
marker_3 = 0.5 * track_width
# Give higher reward if the car is closer to center line and vice versa
if distance_from_center <= marker_1:
reward = 1.0
elif distance_from_center <= marker_2:
reward = 0.5
elif distance_from_center <= marker_3:
reward = 0.1
else:
reward = 1e-3 # likely crashed/ close to off track
if not all_wheels_on_track:
reward = 1e-3 # Penalize if the car goes off track
elif speed < SPEED_THRESHOLD:
reward *= 0.5 # Penalize if the car goes too slow
return float(reward)
@0emanresuym
Copy link

0emanresuym commented Dec 11, 2020

trying

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment