def close(self): """ Call this function, once you're done with PyTux """ if self.k is not None: self.k.stop() del self.k pystk.clean()
def main(): config = pystk.GraphicsConfig.hd() config.screen_width = 800 config.screen_height = 600 pystk.init(config) config = pystk.RaceConfig() config.num_kart = 2 # config.track ='battleisland' config.track = 'stadium' config.players[0].controller = pystk.PlayerConfig.Controller.PLAYER_CONTROL config.players[0].team = 0 # NOTE: Add 4 players for _ in range(3): config.players.append( # pystk.PlayerConfig(args.kart, pystk.PlayerConfig.Controller.AI_CONTROL, (args.team + 1) % 2)) pystk.PlayerConfig('', pystk.PlayerConfig.Controller.AI_CONTROL, 1)) config.mode = config.RaceMode.THREE_STRIKES # TODO: Look at step size? # config.step_size = args.step_size race = pystk.Race(config) race.start() race.step() uis = [gui.UI(gui.VT['IMAGE']) for i in range(4)] state = pystk.WorldState() state.update() t0 = time() if not all(ui.pause for ui in uis): race.step(uis[0].current_action) state.update() for ui, d in zip(uis, race.render_data): ui.show(d) input('press enter to continue') race.stop() del race pystk.clean()
def __init__(self, _): print("calling __init__") gfx_config = pystk.GraphicsConfig.ld() gfx_config.screen_width = 160 gfx_config.screen_height = 120 gfx_config.render_window = True pystk.clean() pystk.init(gfx_config) # Current action space is only steering left/right #self.action_space = gym.spaces.Tuple([gym.spaces.Box(low=-1.0, high=1.0, shape=(1,)), gym.spaces.Discrete(2)]) self.action_space = gym.spaces.Box(np.array( [-1, 0, 0, 0]), np.array([1, 1, 1, 1])) # steer, gas, brake, fire self.observation_space = gym.spaces.Box(low=0.0, high=1.0, shape=(120, 160, 3)) self.race = None self.max_step = 4000 self.curr_iter = 0 self.prev_distance = 0
def __del__(self): if self.race is not None: self.race.stop() del self.race pystk.clean()
print(' ', state.soccer.goal_line) for ui, d in zip(uis, race.render_data): ui.show(d) if args.save_dir: image = np.array(race.render_data[0].image) action = action_dict(uis[0].current_action) player_info = state.karts[0] Image.fromarray(image).save(args.save_dir / ('image_%06d.png' % n)) (args.save_dir / ('action_%06d.txt' % n)).write_text(str(action)) with open(args.save_dir / ('player_info_%06d' % n), 'wb') as output: pickle.dump(player_info, output, -1) if save_depth: depth = np.array(race.render_data[0].depth).astype('uint8') np.save(args.save_dir / ('depth_%06d' % n), depth) if save_labels: label = np.array(race.render_data[0].instance) #& 0xffffff np.save(args.save_dir / ('label_%06d' % n), label) # Make sure we play in real time n += 1 delta_d = n * config.step_size - (time() - t0) if delta_d > 0: ui.sleep(delta_d) race.stop() del race pystk.clean()
def __del__(self): self.race.stop() self.race = None self.track = None pystk.clean()