sprint
Her-darling 2 months ago
parent 8dd76d0494
commit e8f50eea0f

@ -282,17 +282,17 @@ class sprint(gym.Env):
Draw.clear_all()
self.player.terminate()
def generate_random_target(self, x_range=(-12, 12), y_range=(-9, 9)):
while True:
x = np.random.uniform(x_range[0], x_range[1])
y = np.random.uniform(y_range[0], y_range[1])
if np.linalg.norm(np.array([x, y]) - self.Gen_player_pos[:2]) >= 10:
if abs(x) > 15 or abs(y) > 10:
continue
break
x = np.random.uniform(x_range[0], x_range[1])
y = np.random.uniform(y_range[0], y_range[1])
if np.linalg.norm(np.array([x, y]) - self.Gen_player_pos[:2]) < 5:
dir_x = (x - self.Gen_player_pos[0]) / abs (x - self.Gen_player_pos[0])
dir_y = (y - self.Gen_player_pos[1]) / abs (y - self.Gen_player_pos[1])
x = x + 5 * dir_x
y = y + 5 * dir_y
x = np.clip(x, -15, 15)
y = np.clip(y, -15, 15)
self.walk_target = np.array([x, y])
def step(self, action):
@ -342,7 +342,7 @@ class sprint(gym.Env):
robot_speed = r.loc_torso_velocity[0]
direction_error = abs(self.walk_rel_orientation)
direction_error = min(direction_error, 10)
reward = robot_speed * (1.5 - direction_error / 10)
reward = robot_speed * (1 - direction_error / 10)
if self.walk_distance < 0.5:
reward += 20
self.generate_random_target()

Loading…
Cancel
Save