def step(self, action): self.evManager.post( Event.MovePlayerEvent(Vector2(action[0], action[1]))) now = pygame.time.get_ticks() delta = (now - self.previous) / 1000.0 self.previous = now self.evManager.post(Event.TickEvent(delta)) car = self.game.character new_state = car.get_state() if car.is_on_path(): self.reward = car.velocity[0] / car.max_front_velocity else: self.reward = -1.0 self.score += self.reward done = not self.keepGoing self.step_counter += 1 if self.step_counter == self.life_span: self.keepGoing = False if not car.is_on_path(): self.step_outside_path_counter += 1 if self.step_outside_path_counter == self.life_span_outside_path: self.keepGoing = False return new_state, self.reward, done, self.info
def run(self): while self.keepGoing: now = pygame.time.get_ticks() delta = (now - self.previous) / 1000.0 self.previous = now self.evManager.post(Event.TickEvent(delta)) pygame.quit()