i have three question about these two differente rewardfunction 1 : from…
- User
i have three question about these two differente rewardfunction
1 :
from rlgym.utils.common_values import BLUE_TEAM, BLUE_GOAL_BACK, ORANGE_GOAL_BACK, ORANGE_TEAM, BALL_MAX_SPEED,
CAR_MAX_SPEED, BALL_RADIUS, GOAL_HEIGHT, CEILING_Z, BACK_NET_Y, BACK_WALL_Y, SIDE_WALL_X import numpy as np from rlgym.utils.gamestates import PlayerData, GameState from rlgym.utils.reward_functions import RewardFunction from rlgym.utils.math import cosine_similarity from Constants_kickoff import FRAME_SKIPfrom numpy.linalg import norm
from typing import Tuple, List from rlgym.utils.common_values import BOOST_LOCATIONS
def _closest_to_ball(state: GameState) -> Tuple[int, int]: # returns [blue_closest, orange_closest] length = len(state.players) dist_list: List[float] = [100_000] * length blue_closest = -1 orange_closest = -1 for i, player in enumerate(state.players): dist = np.linalg.norm(player.car_data.position - state.ball.position) dist_list[i] = dist if state.players[i].team_num == BLUE_TEAM and blue_closest == -1: blue_closest = i elif state.players[i].team_num == ORANGE_TEAM and orange_closest == -1: orange_closest = i elif state.players[i].team_num == BLUE_TEAM and dist <= dist_list[blue_closest]: if dist == dist_list[blue_closest]: if state.players[i].car_data.position[0] > state.players[blue_closest].car_data.position[0]: blue_closest = i continue else: blue_closest = i continue elif state.players[i].team_num == ORANGE_TEAM and dist <= dist_list[orange_closest]: if dist == dist_list[orange_closest]: if state.players[i].car_data.position[0] < state.players[orange_closest].car_data.position[0]: orange_closest = i continue else: orange_closest = i continue return blue_closest, orange_closest
class ZeroSumReward(RewardFunction): # framework for zerosum comes from Nexto code (Rolv and Soren) # (https://github.com/Rolv-Arild/Necto/blob/master/training/reward.py) def init( self, goal_w=0, # go to 10 after working concede_w=0, velocity_pb_w=0, # 0.01, velocity_bg_w=0, # 0.05, touch_grass_w=0, # -0.005, acel_ball_w=0, # 1.5, boost_gain_w=0, # 1.5, boost_spend_w=1.5, # 1.5 is default punish_boost=False, # punish once they start wasting and understand the game a bit jump_touch_w=0, # 3, cons_air_touches_w=0, # 6, wall_touch_w=0, # 0.25, demo_w=0, # 3, # 6, got_demoed_w=0, # -3, # -6, kickoff_w=0, # 0.1, double_tap_w=0, aerial_goal_w=0, flip_reset_w=0, inc_flip_reset_w=0, flip_reset_goal_w=0, flip_reset_help_w=0, has_flip_reset_vbg_w=0, quick_flip_reset_w=0, quick_flip_reset_norm_sec=1, punish_low_touch_w=0, punish_ceiling_pinch_w=0, ball_opp_half_w=0, kickoff_special_touch_ground_w=0, kickoff_final_boost_w=0, kickoff_vpb_after_0_w=0, dribble_w=0, forward_ctrl_w=0, exit_velocity_w=0, exit_vel_angle_w=0, req_reset_exit_vel=False, punish_car_ceiling_w=0, punish_action_change_w=0, decay_punish_action_change_w=0, goal_speed_exp=1, # fix this eventually min_goal_speed_rewarded_kph=0, touch_height_exp=1, tick_skip=FRAME_SKIP, team_spirit=0, # increase as they learn zero_sum=True, prevent_chain_reset=False, touch_ball_w=0, boost_remain_touch_w=0, supersonic_bonus_vpb_w=0, turtle_w=0, zero_touch_grass_if_ss=False, final_reward_ball_dist_w=0, final_reward_boost_w=0, punish_directional_changes=False, punish_bad_spacing_w=0, ): self.punish_bad_spacing_w = punish_bad_spacing_w self.forward_ctrl_w = forward_ctrl_w self.final_reward_boost_w = final_reward_boost_w self.punish_directional_changes = punish_directional_changes self.decay_punish_action_change_w = decay_punish_action_change_w self.final_reward_ball_dist_w = final_reward_ball_dist_w self.zero_touch_grass_if_ss = zero_touch_grass_if_ss self.turtle_w = turtle_w self.supersonic_bonus_vpb_w = supersonic_bonus_vpb_w self.boost_remain_touch_w = boost_remain_touch_w self.touch_ball_w = touch_ball_w self.end_object_tracker = 0 self.min_goal_speed_rewarded = min_goal_speed_rewarded_kph * 27.78 # to uu self.exit_vel_angle_w = exit_vel_angle_w self.quick_flip_reset_w = quick_flip_reset_w self.req_reset_exit_vel = req_reset_exit_vel self.cons_resets = 0 self.goal_w = goal_w self.concede_w = concede_w if zero_sum: self.concede_w = 0 self.velocity_pb_w = velocity_pb_w self.velocity_bg_w = velocity_bg_w * (tick_skip / 8) self.touch_grass_w = touch_grass_w self.acel_ball_w = acel_ball_w self.boost_gain_w = boost_gain_w if punish_boost: self.boost_spend_w = boost_spend_w * self.boost_gain_w * ((33.3334 / (120 / tick_skip)) * 0.01) else: self.boost_spend_w = 0 self.jump_touch_w = jump_touch_w self.cons_air_touches_w = cons_air_touches_w self.wall_touch_w = wall_touch_w self.demo_w = demo_w self.got_demoed_w = got_demoed_w if zero_sum: self.got_demoed_w = 0 self.kickoff_w = kickoff_w * (tick_skip / 8) self.double_tap_w = double_tap_w self.aerial_goal_w = aerial_goal_w self.flip_reset_w = flip_reset_w self.inc_flip_reset_w = inc_flip_reset_w self.flip_reset_goal_w = flip_reset_goal_w self.flip_reset_help_w = flip_reset_help_w self.has_flip_reset_vbg_w = has_flip_reset_vbg_w self.prevent_chain_reset = prevent_chain_reset self.punish_low_touch_w = punish_low_touch_w self.punish_ceiling_pinch_w = punish_ceiling_pinch_w self.ball_opp_half_w = ball_opp_half_w self.kickoff_special_touch_ground_w = kickoff_special_touch_ground_w self.kickoff_final_boost_w = kickoff_final_boost_w self.kickoff_vpb_after_0_w = kickoff_vpb_after_0_w self.dribble_w = dribble_w self.exit_velocity_w = exit_velocity_w self.punish_car_ceiling_w = punish_car_ceiling_w self.punish_action_change_w = punish_action_change_w self.previous_action = None self.goal_speed_exp = goal_speed_exp self.touch_height_exp = touch_height_exp self.rewards = None self.current_state = None self.last_state = None self.touch_timeout = 8 * 120 // tick_skip # 120 ticks at 8 tick skip is 8 seconds self.kickoff_timeout = 5 * 120 // tick_skip self.quick_flip_reset_norm_steps = quick_flip_reset_norm_sec * 120 // tick_skip self.kickoff_timer = 0 self.closest_reset_blue = -1 self.closest_reset_orange = -1 self.blue_touch_timer = self.touch_timeout + 1 self.orange_touch_timer = self.touch_timeout + 1 self.blue_toucher = None self.orange_toucher = None self.team_spirit = team_spirit self.n = 0 self.cons_touches = 0 self.zero_sum = zero_sum self.num_touches = [] # for double tap self.backboard_bounce = False self.floor_bounce = False self.got_reset = [] # for aerial goal self.blue_touch_height = -1 self.orange_touch_height = -1 self.last_touched_frame = [-1] * 6 self.reset_timer = -100000 self.flip_reset_delay_steps = 0.25 * (120 // tick_skip) self.last_touch_time = -100_000 self.exit_vel_arm_time_steps = 0.15 * (120 // tick_skip) self.exit_rewarded = [False] * 6 self.last_touch_car = None self.launch_angle_car = [None] * 6 self.exit_vel_save = [None] * 6 self.big_boosts = [BOOST_LOCATIONS[i] for i in [3, 4, 15, 18, 29, 30]] self.big_boost = np.asarray(self.big_boosts) self.big_boost[:, -1] = 18 # fix the boost height self.last_action_change = None
- Assistant
- User
can you give example of the proof for the 3. please
- Assistant
- User
is both of these reward is saving more reward ressource than a normal rewardfunction
- Assistant