in roboschool/gym_pong.py [0:0]
def global_step(self):
self.frame += 1
if not self.multiplayer:
# Trainer
self.p1x.set_servo_target( self.trainer_x, 0.02, 0.02, 4 )
self.p1y.set_servo_target( self.trainer_y, 0.02, 0.02, 4 )
Scene.global_step(self)
self.ball_x, ball_vx = self.ballx.current_position()
self.ball_y, ball_vy = self.bally.current_position()
if np.abs(self.ball_y) > 1.0 and self.ball_y*ball_vy > 0:
self.bally.reset_current_position(self.ball_y, -ball_vy)
if ball_vx*self.timeout_dir < 0:
if self.timeout_dir < 0:
self.score_left += 0.01*np.abs(ball_vx) # hint for early learning: hit the ball!
else:
self.score_right += 0.01*np.abs(ball_vx)
self.timeout_dir *= -1
self.timeout = 150
self.bounce_n += 1
else:
self.timeout -= 1
if np.abs(self.ball_x) > 1.65 or self.timeout==0:
if self.timeout==0:
self.restart_from_center(self.players_count==1 or ball_vx<0) # send ball in same dir on timeout
elif ball_vx>0:
if self.bounce_n > 0:
self.score_left += 1
self.score_right -= 1
self.restart_from_center(self.players_count==1 or ball_vx>0) # winning streak, let it hit more
else:
if self.bounce_n > 0:
self.score_right += 1.0
self.score_left -= 1
self.restart_from_center(self.players_count==1 or ball_vx>0)