Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def update(self, dt):
- global brain
- global last_reward
- global scores
- global last_distance
- global goal_x
- global goal_y
- global longueur
- global largeur
- global lastTime
- longueur = self.width
- largeur = self.height
- if first_update:
- init()
- # code you want to evaluate
- start_time = timeit.default_timer()
- xx = goal_x - self.car.x
- yy = goal_y - self.car.y
- orientation = Vector(*self.car.velocity).angle((xx,yy))/180.
- last_signal = [self.car.signal1, self.car.signal2, self.car.signal3, orientation, -orientation]
- action = brain.update(last_reward, last_signal)
- scores.append(brain.score())
- rotation = action2rotation[action]
- self.car.move(rotation)
- distance = np.sqrt((self.car.x - goal_x)**2 + (self.car.y - goal_y)**2)
- self.ball1.pos = self.car.sensor1
- self.ball2.pos = self.car.sensor2
- self.ball3.pos = self.car.sensor3
- elapsed = timeit.default_timer() - start_time
- lastTime += elapsed
- if sand[int(self.car.x),int(self.car.y)] > 0:
- self.car.velocity = Vector(1, 0).rotate(self.car.angle)
- last_reward = -1
- else: # otherwise
- self.car.velocity = Vector(6, 0).rotate(self.car.angle)
- last_reward = -0.05 * lastTime
- if distance < last_distance:
- last_reward = 0.1
- if self.car.x < 10:
- self.car.x = 10
- last_reward = -1
- if self.car.x > self.width - 10:
- self.car.x = self.width - 10
- last_reward = -1
- if self.car.y < 10:
- self.car.y = 10
- last_reward = -1
- if self.car.y > self.height - 10:
- self.car.y = self.height - 10
- last_reward = -1
- if distance < 100:
- last_reward = -0.4 * lastTime + 1
- print lastTime
- lastTime = 0
- goal_x = self.width-goal_x
- goal_y = self.height-goal_y
- last_distance = distance
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement