Skip to content

Commit

Permalink
flick roll back to 14910 and add angle exit velocity mult, make no z …
Browse files Browse the repository at this point in the history
…exit, min goal speed, terminal attacker close to goal.
  • Loading branch information
Kaiyotech committed Dec 12, 2022
1 parent 4a998e8 commit 8621c09
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Constants_flick.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FRAME_SKIP = 4
TIME_HORIZON = 6 # horizon in seconds
TIME_HORIZON = 4 # horizon in seconds
T_STEP = FRAME_SKIP / 120 # real time per rollout step
ZERO_SUM = True
STEP_SIZE = 500_000
Expand Down
1 change: 1 addition & 0 deletions mybots_terminals.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ def is_terminal(self, current_state: GameState) -> bool:
current_state.players[self.toucher].ball_touched:
return True
elif current_state.players[self.toucher].ball_touched:
self.armed = False
self.no_touch_steps = 10_000_000
return False

Expand Down
12 changes: 7 additions & 5 deletions rewards.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ def __init__(
self.last_touch_time = -1000
self.exit_vel_arm_time_steps = 0.15 * (120 // tick_skip)
self.exit_rewarded = False
self.launch_angle_car = None

def pre_step(self, state: GameState):
if state != self.current_state:
Expand Down Expand Up @@ -260,6 +261,8 @@ def pre_step(self, state: GameState):

# not touched
else:
if last.ball_touched:
self.launch_angle_car = player.car_data.forward()[:-1] / np.linalg.norm(player.car_data.forward()[:-1])
if self.kickoff_timer - self.last_touch_time > self.exit_vel_arm_time_steps and not self.exit_rewarded:
self.exit_rewarded = True
# rewards 1 for a 120 kph flick (3332 uu/s), 11 for a 6000 uu/s (max speed)
Expand All @@ -272,11 +275,10 @@ def pre_step(self, state: GameState):
ang_mult = 1
if self.exit_vel_angle_w != 0:
# 0.785 is 45
unit_vector_1 = player.car_data.forward()[:-1] / np.linalg.norm(player.car_data.forward()[:-1])
unit_vector_2 = state.ball.position[:-1] / np.linalg.norm(state.ball.position[:-1])
dot_product = np.dot(unit_vector_1, unit_vector_2)
angle = min(abs(np.arccos(dot_product)), 0.785) / 0.785
ang_mult = self.exit_velocity_w * angle + 0.1 # 0.1 is a small mult to still reward 0 angle
unit_vector_2 = state.ball.linear_velocity[:-1] / np.linalg.norm(state.ball.linear_velocity[:-1])
dot_product = np.dot(self.launch_angle_car, unit_vector_2)
angle = min(np.arccos(dot_product), 0.785) / 0.785
ang_mult = self.exit_velocity_w * max(angle, 0.1) # 0.1 is a small mult to still reward 0 angle
vel_mult = self.exit_velocity_w * 0.5 * ((xy_norm_ball_vel ** 5) / (3332 ** 5) + ((xy_norm_ball_vel ** 2) / (3332 ** 2)))
player_rewards[i] += vel_mult * req_reset * ang_mult

Expand Down
4 changes: 2 additions & 2 deletions worker_flick.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@
extra_boost_info=True, embed_players=True),
action_parser=CoyoteAction(),
terminal_conditions=[GoalScoredCondition(),
BallTouchGroundCondition(min_time_sec=2,
BallTouchGroundCondition(min_time_sec=0.5,
tick_skip=Constants_flick.FRAME_SKIP,
time_after_ground_sec=0.25,
min_height=100,
neg_z_check=True),
PlayerTwoTouch(time_to_arm=1, tick_skip=Constants_flick.FRAME_SKIP),
PlayerTwoTouch(time_to_arm=0.5, tick_skip=Constants_flick.FRAME_SKIP),
TimeoutCondition(fps * 100),
AttackerTouchCloseGoal(distance=1000),
],
Expand Down

0 comments on commit 8621c09

Please sign in to comment.