Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AurelianTactics/c297b3b76410552220bdb99f1774e205 to your computer and use it in GitHub Desktop.
Save AurelianTactics/c297b3b76410552220bdb99f1774e205 to your computer and use it in GitHub Desktop.
reward_by_max_waypoint
prev_max_distance_reward = 0
--only get reward for going over prior max
--calculates reward based on where you are in terms of waypoints and progress to next waypoint
function reward_by_max_waypoint()
frame_count = frame_count + 1
local level_done = calc_progress(data)
--local reward = reward_by_ring(data)
local reward = 0
calc_waypoint(data) --increments waypoint
if waypoint_reward_scale == nil then
local total_distance = get_total_distance(prev_x,prev_y)
waypoint_reward_scale = 9000.0/total_distance
prev_same_screen_y = data.screen_y
prev_anchor_y = nil
end
--deaths aren't registed right away but sonic will move a lot on the y axis
--this is a rough check for that
if (data.x == prev_x) and (data.screen_y == prev_screen_y) then
prev_same_x = prev_same_x + 1
prev_same_screen_y = prev_same_screen_y + 1
else
prev_same_x = 0
prev_same_screen_y = 0
prev_anchor_y = data.y
end
if (prev_same_x <= 20) or (math.abs((data.y-prev_anchor_y)) < 65) then
--local curr_distance = math.sqrt((data.x-waypoint_x)^2 + (data.y-waypoint_y)^2)
local curr_distance = waypoint_distance_table[current_waypoint] - (math.abs((data.x-waypoint_x)) + math.abs((data.y-waypoint_y)))
local distance_reward = curr_distance*waypoint_reward_scale
if distance_reward > prev_max_distance_reward then
reward = reward + (distance_reward - prev_max_distance_reward)
prev_max_distance_reward = distance_reward
end
end
prev_x = data.x
prev_y = data.y
prev_screen_y = data.screen_y
if level_done >= 1 then
reward = reward + (1 - clip(frame_count/frame_limit, 0, 1)) * 1000
end
return reward
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment