def make(self): if self.env is None: from retro_contest.local import make if self.record: self.env = SonicEnvWrapper(make(game=self.game, state=self.state, bk2dir=self.path)) else: self.env = SonicEnvWrapper(make(game=self.game, state=self.state))
def make_val(env_idx, stack=True, scale_rew=True): """ Create an environment with some standard wrappers. """ dicts = [ {'game': 'SonicTheHedgehog-Genesis', 'state': 'SpringYardZone.Act1'}, {'game': 'SonicTheHedgehog-Genesis', 'state': 'GreenHillZone.Act2'}, {'game': 'SonicTheHedgehog-Genesis', 'state': 'StarLightZone.Act3'}, {'game': 'SonicTheHedgehog-Genesis', 'state': 'ScrapBrainZone.Act1'}, {'game': 'SonicTheHedgehog2-Genesis', 'state': 'MetropolisZone.Act3'}, {'game': 'SonicTheHedgehog2-Genesis', 'state': 'HillTopZone.Act2'}, {'game': 'SonicTheHedgehog2-Genesis', 'state': 'CasinoNightZone.Act2'}, {'game': 'SonicAndKnuckles3-Genesis', 'state': 'LavaReefZone.Act1'}, {'game': 'SonicAndKnuckles3-Genesis', 'state': 'FlyingBatteryZone.Act2'}, {'game': 'SonicAndKnuckles3-Genesis', 'state': 'HydrocityZone.Act1'}, {'game': 'SonicAndKnuckles3-Genesis', 'state': 'AngelIslandZone.Act2'} ] print(dicts[env_idx]['game'], dicts[env_idx]['state'], flush=True) env = make(game=dicts[env_idx]['game'], state=dicts[env_idx]['state'])#, bk2dir='/tmp')#, record='/tmp') env = SonicDiscretizer(env) if scale_rew: env = RewardScaler(env) env = WarpFrame96(env) if stack: env = FrameStack(env, 4) env = AllowBacktracking(env) return env
def main(self): self.env = make(game='SonicTheHedgehog-Genesis', state='SpringYardZone.Act3') obs = self.env.reset() self.total_reward = 0 done = False inercia = 5 while True: key = msvcrt.getch() # print(k) if key == b'a': state, rew, done, info = self.press(self.actions[0], inercia) if key == b'd': state, rew, done, info = self.press(self.actions[1], inercia) if key == b'w': state, rew, done, info = self.press(self.actions[8], inercia) if key == b's': state, rew, done, info = self.press(self.actions[3], inercia) if key == b'e': state, rew, done, info = self.press(self.actions[4], inercia) if key == b'b': state, rew, done, info = self.press(self.actions[5], inercia) if key == b'\x00': state, rew, done, info = self.press(self.actions[7], inercia) # x1 = 0 # x2 = 0 # x2 = info['x'] # speed = x2 - x1 # x1 = x2 # print('speed: ', speed) if done: obs = self.env.reset()
def main(): """Run DQN until the environment throws an exception.""" env = make(game='SonicTheHedgehog-Genesis', state='GreenHillZone.Act1') env = AllowBacktracking(make_local_env(env, stack=False, scale_rew=False)) env = BatchedFrameStack(BatchedGymEnv([[env]]), num_images=4, concat=False) config = tf.ConfigProto() config.gpu_options.allow_growth = True # pylint: disable=E1101 with tf.Session(config=config) as sess: dqn = DQN(*rainbow_models(sess, env.action_space.n, gym_space_vectorizer(env.observation_space), min_val=-200, max_val=200)) player = NStepPlayer(BatchedPlayer(env, dqn.online_net), 3) optimize = dqn.optimize(learning_rate=1e-4) sess.run(tf.global_variables_initializer()) dqn.train(num_steps=num_steps, # Make sure an exception arrives before we stop. player=player, replay_buffer=PrioritizedReplayBuffer(500000, 0.5, 0.4, epsilon=0.1), optimize_op=optimize, train_interval=1, target_interval=8192, batch_size=32, min_buffer_size=20000) print(tf.trainable_variables()) save_path='/home/noob/retro-noob/rainbow/params/params' utils.save_state(save_path+'_tf_saver') with tf.variable_scope('model'): params = tf.trainable_variables() ps = sess.run(params) joblib.dump(ps, save_path + '_joblib')
def main(): """Run DQN until the environment throws an exception.""" env = make(game='SonicTheHedgehog-Genesis', state='GreenHillZone.Act1') env = BatchedFrameStack(BatchedGymEnv([[env]]), num_images=4, concat=False) config = tf.ConfigProto() config.gpu_options.allow_growth = True # pylint: disable=E1101 with tf.Session(config=config) as sess: dqn = DQN(*rainbow_models(sess, env.action_space.n, gym_space_vectorizer(env.observation_space), min_val=-200, max_val=200)) player = NStepPlayer(BatchedPlayer(env, dqn.online_net), 3) optimize = dqn.optimize(learning_rate=1e-4) sess.run(tf.global_variables_initializer()) dqn.train( num_steps=2000000, # Make sure an exception arrives before we stop. player=player, replay_buffer=PrioritizedReplayBuffer(500000, 0.5, 0.4, epsilon=0.1), optimize_op=optimize, train_interval=1, target_interval=8192, batch_size=32, min_buffer_size=20000)
def make_env(stack=True, scale_rew=True, local=False, level_choice=None): """ Create an environment with some standard wrappers. """ print(stack, scale_rew, local) if local: # Select Random Level if local from retro_contest.local import make levels = [ 'SpringYardZone.Act3', 'SpringYardZone.Act2', 'GreenHillZone.Act3', 'GreenHillZone.Act1', 'StarLightZone.Act2', 'StarLightZone.Act1', 'MarbleZone.Act2', 'MarbleZone.Act1', 'MarbleZone.Act3', 'ScrapBrainZone.Act2', 'LabyrinthZone.Act2', 'LabyrinthZone.Act1', 'LabyrinthZone.Act3' ] if not level_choice: level_choice = levels[random.randrange(0, 13, 1)] else: level_choice = levels[level_choice] env = make(game='SonicTheHedgehog-Genesis', state=level_choice) else: print('connecting to remote environment') env = grc.RemoteEnv('tmp/sock') print('starting episode') if scale_rew: env = RewardScaler(env) env = WarpFrame(env) if stack: env = FrameStack(env, 4) return env
def main(): env = make( game='Vectorman-Genesis', state=-1) #'SonicTheHedgehog-Genesis', state='LabyrinthZone.Act1') obs = env.reset() c = 0 maxRuns = 4 while True: act = env.action_space.sample() act[7] = 1 obs, rew, done, info = env.step(act) #env.action_space.sample() #env.render() if done: print(obs.shape, '\n', info) obs = env.reset() c += 1 plt.figure(figsize=(8, 8)) #plt.subplot(131) #plt.imshow(obs[:,:,0]) #plt.subplot(132) #plt.imshow(obs[:,:,1]) #plt.subplot(133) plt.imshow(obs[:, :, 0] / 3 + obs[:, :, 1] / 3 + obs[:, :, 2] / 3, cmap='gray') plt.savefig('./screens/sampleScreen%i.png' % c) if (c > maxRuns): env.close() break
def make_env(env_idx): dicts = [ {'game': 'SonicTheHedgehog-Genesis', 'state': 'SpringYardZone.Act3'}, {'game': 'SonicTheHedgehog-Genesis', 'state': 'SpringYardZone.Act2'}, {'game': 'SonicTheHedgehog-Genesis', 'state': 'GreenHillZone.Act3'}, {'game': 'SonicTheHedgehog-Genesis', 'state': 'GreenHillZone.Act1'}, {'game': 'SonicTheHedgehog-Genesis', 'state': 'StarLightZone.Act2'}, {'game': 'SonicTheHedgehog-Genesis', 'state': 'StarLightZone.Act1'}, {'game': 'SonicTheHedgehog-Genesis', 'state': 'MarbleZone.Act2'}, {'game': 'SonicTheHedgehog-Genesis', 'state': 'MarbleZone.Act1'}, {'game': 'SonicTheHedgehog-Genesis', 'state': 'MarbleZone.Act3'}, {'game': 'SonicTheHedgehog-Genesis', 'state': 'ScrapBrainZone.Act2'}, {'game': 'SonicTheHedgehog-Genesis', 'state': 'LabyrinthZone.Act2'}, {'game': 'SonicTheHedgehog-Genesis', 'state': 'LabyrinthZone.Act1'}, {'game': 'SonicTheHedgehog-Genesis', 'state': 'LabyrinthZone.Act3'} ] print(dicts[env_idx]['game'], dicts[env_idx]['state'], flush=True) env = make(game=dicts[env_idx]['game'], state=dicts[env_idx]['state'], bk2dir="./records") env = ActionsDiscretizer(env) env = RewardScaler(env) env = PreprocessFrame(env) env = FrameStack(env, 4) env = AllowBackTracking(env) return env
def main(): """Run JERK on the attached environment.""" # env = grc.RemoteEnv('tmp/sock') env = make(game='SonicTheHedgehog-Genesis', state='SpringYardZone.Act1') env = TrackedEnv(env) new_ep = True solutions = [] while True: if new_ep: if (solutions and random.random() < EXPLOIT_BIAS + env.total_steps_ever / TOTAL_TIMESTEPS): solutions = sorted(solutions, key=lambda x: np.mean(x[0])) best_pair = solutions[-1] new_rew = exploit(env, best_pair[1]) best_pair[0].append(new_rew) print('replayed best with reward %f' % new_rew) continue else: env.reset() new_ep = False rew, new_ep = move(env, 100) # if not new_ep and rew >= 50: # print('50 _ backtracking due to negative reward: %f' % rew) # _, new_ep = move(env, 20, left=True) if not new_ep and rew <= 0: print('backtracking due to negative reward: %f' % rew) _, new_ep = move(env, 100, left=True, jump_repeat=0, jump_prob=0) if new_ep: solutions.append(([max(env.reward_history)], env.best_sequence()))
def make_test(): """ Create an environment with some standard wrappers. """ envIdx = 0 # Here we add record because we want to output a video env = make(game=dicts[envIdx]['game'], state=dicts[envIdx]['state']) # Build the actions array, env = ActionsDiscretizer(env, dicts[envIdx]['game']) # Scale the rewards #env = RewardScaler(env) # PreprocessFrame env = PreprocessFrame(env) # Stack 4 frames env = FrameStack(env, 4) # Allow back tracking that helps agents are not discouraged too heavily # from exploring backwards if there is no way to advance # head-on in the level. env = AllowBacktracking(env) return env
def make_env(stack=True, scale_rew=True, game=None, state=None, seed=0, render=False): """ Create an environment with some standard wrappers. """ # if not is_remote: # if game is None or state is None: # import data_set_reader # train_set = data_set_reader.read_train_set() # game, state = random.choice(train_set) # print("it's local env: ", game, state) # from retro_contest.local import make # env = make(game=game, state=state) # else: # print("it's remote env") # import gym_remote.client as grc # env = grc.RemoteEnv('tmp/sock') env = make(game=game, state=state) env.seed(seed) env = AllowBacktracking(env) env = Monitor(env, logger.get_dir() and os.path.join(logger.get_dir(), str(seed)), allow_early_resets=True) env = SonicDiscretizer(env, render) if scale_rew: env = RewardScaler(env) env = WarpFrame(env) if stack: env = FrameStack(env, 4) return env
def valid(self): from retro_contest.local import make agent = CNQAgent(12, self.AGENT_NAME) agent.load_model() agent.epsilon = 0.1 self.env = make(game='SonicTheHedgehog-Genesis', state='SpringYardZone.Act3') self.state = self.env.reset() self.reward = 0 self.action = np.zeros(7) self.train = False while True: self.action = agent.act(self.state, self.action, self.reward, 0) # print(action) self.do() self.state = self.next_state if self.done: obs = self.env.reset() frame = cv2.putText(self.state, str(round(self.reward, 1)), (150, 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 255, 255)) frame = cv2.putText(frame, str(self.action), (150, 30), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 255, 255)) cv2.imshow('AGENT VALIDATION', frame) cv2.waitKey(60)
def main(): parser = argparse.ArgumentParser() parser.add_argument('--game', '-g', default='Airstriker-Genesis', help='the name or path for the game to run') parser.add_argument('--state', '-t', default=STATE_DEFAULT, nargs='?', help='the initial state file to load, minus the extension') parser.add_argument('--scenario', '-s', default='scenario', help='the scenario file to load, minus the extension') parser.add_argument('--record', '-r', action='store_true', help='record bk2 movies') parser.add_argument('--verbose', '-v', action='count', default=1, help='increase verbosity (can be specified multiple times)') parser.add_argument('--quiet', '-q', action='count', default=0, help='decrease verbosity (can be specified multiple times)') parser.add_argument('--obs-type', '-o', default='image', help='the observation type, either image (default) or ram') parser.add_argument('--render', '-e', action='store_true', help='render the environment on screen') parser.add_argument('--agent', '-a', default='random', help='choose the agent, default random') args = parser.parse_args() agents = { 'random': RandomAgent, 'random-tf': RandomTFAgent, 'greedy': GreedyAgent, } try: env = make(args.game, args.state) # , scenario=args.scenario, record=args.record, obs_type=args.obs_type except FileNotFoundError: env = gym.make(args.game) agent = agents[args.agent](env) do_render = args.render verbosity = args.verbose - args.quiet # plt.ion() # enables interactive mode Experiment(env, agent, do_render, verbosity).run() exit(0)
def __init__(self, is_remote, game, state, max_timesteps, env_wrapper, do_render, monitor_path): if is_remote: import gym_remote.client as grc self.env = env_wrapper(grc.RemoteEnv('tmp/sock'), float('inf'), do_render, monitor_path) else: from retro_contest.local import make self.env = env_wrapper(make(game, state), max_timesteps, do_render, monitor_path)
def run(game, state, params_dir): config = tf.ConfigProto() config.gpu_options.allow_growth = True env = make(game=game, state=state, bk2dir='bk2dir/') env = make_local_env(env, stack=True, scale_rew=True) load_path = 'params/ppo_v2/' + game + state + 'checkpoints/0092' def env_fn(): return env with tf.Session(config=config): model = ppo2.Model(policy=policies.CnnPolicy, ob_space=env.observation_space, ac_space=env.action_space, nbatch_act=1, nsteps=4096, nbatch_train=4096 // 4, ent_coef=0.01, vf_coef=0.5, max_grad_norm=0.5) print(env.observation_space) print(env.action_space) model.load(params_dir) runner = ppo2.Runner(env=DummyVecEnv([env_fn]), model=model, nsteps=4096, gamma=0.99, lam=0.95) runner.run()
def main(): training_episodes = 1000 env = make(game='SonicAndKnuckles3-Genesis', state='AngelIslandZone.Act1') obs = env.reset() espio = DDQN() espio.obs = obs score = 0 # training for e in range(0, training_episodes): action = env.action_space.sample() obs, rew, done, info = env.step(action) score_prime = info['score'] delta_score = score_prime - score print(delta_score) espio.experience_replay.append( [espio.obs, action, rew, delta_score, obs, done]) # env.render() # espio.train() if done: obs = env.reset() self.obs = obs score = 0 score = score_prime # finished training while True: obs, rew, done, info = env.step(env.action_space.sample()) # env.render() if done: obs = env.reset()
def make_sonic_env( game, state, remote_env=False, scale_rew=True, video_dir="", short_life=False, backtracking=False, ): """ Create an environment with some standard wrappers. """ if remote_env: env = grc.RemoteEnv("tmp/sock") else: env = make(game=game, state=state, bk2dir=video_dir) env = SonicDiscretizer(env) if scale_rew: env = RewardScaler(env) env = WarpFrame(env) # if stack: # env = FrameStack(env, 4) if short_life: env = ShortLife(env) if backtracking: env = AllowBacktracking(env) return env
def make_env(env_idx): """ Create an environment with some standard wrappers. """ # Make the environment print(dicts[env_idx]['game'], dicts[env_idx]['state'], flush=True) #record_path = "./records/" + dicts[env_idx]['state'] env = make( game=dicts[env_idx]['game'], state=dicts[env_idx]['state']) #, bk2dir="./records")#record='/tmp') # Build the actions array, env = ActionsDiscretizer(env, dicts[env_idx]['game']) # Scale the rewards #env = RewardScaler(env) # PreprocessFrame env = PreprocessFrame(env) # Stack 4 frames env = FrameStack(env, 4) #env = SkipEnv(env, 2) # Allow back tracking that helps agents are not discouraged too heavily # from exploring backwards if there is no way to advance # head-on in the level. env = AllowBacktracking(env) return env
def main(): envs = [('SonicTheHedgehog-Genesis','GreenHillZone.Act',('1','3')), ('SonicTheHedgehog-Genesis','LabyrinthZone.Act',('1','2','3')), ('SonicTheHedgehog-Genesis','MarbleZone.Act',('1','2','3')), ('SonicTheHedgehog-Genesis','ScrapBrainZone.Act',('2')), ('SonicTheHedgehog-Genesis','SpringYardZone.Act',('2','3')), ('SonicTheHedgehog-Genesis','StarLightZone.Act',('1','2')), ('SonicTheHedgehog2-Genesis','AquaticRuinZone.Act',('1','2')), ('SonicTheHedgehog2-Genesis','CasinoNightZone.Act',('1')), ('SonicTheHedgehog2-Genesis','ChemicalPlantZone.Act',('1','2')), ('SonicTheHedgehog2-Genesis','EmeraldHillZone.Act',('1','2')), ('SonicTheHedgehog2-Genesis','HillTopZone.Act',('1')), ('SonicTheHedgehog2-Genesis','MetropolisZone.Act',('1','2')), ('SonicTheHedgehog2-Genesis','MysticCaveZone.Act',('1','2')), ('SonicTheHedgehog2-Genesis','OilOceanZone.Act',('1','2')), ('SonicAndKnuckles3-Genesis','AngelIslandZone.Act',('2')), ('SonicAndKnuckles3-Genesis','CarnivalNightZone.Act',('1','2')), ('SonicAndKnuckles3-Genesis','DeathEggZone.Act',('1','2')), ('SonicAndKnuckles3-Genesis','FlyingBatteryZone.Act',('1')), ('SonicAndKnuckles3-Genesis','HydrocityZone.Act',('2')), ('SonicAndKnuckles3-Genesis','IcecapZone.Act',('1','2')), ('SonicAndKnuckles3-Genesis','LaunchBaseZone.Act',('1','2')), ('SonicAndKnuckles3-Genesis','LavaReefZone.Act',('2')), ('SonicAndKnuckles3-Genesis','MarbleGardenZone.Act',('1','2')), ('SonicAndKnuckles3-Genesis','MushroomHillZone.Act',('1','2')), ('SonicAndKnuckles3-Genesis','SandopolisZone.Act',('1','2'))] observation_hashes = {} info = {} frame_stuff = {} action = np.array([0,0,0,0,0,0,0,0,0,0,0,0]) f = {} for j in envs: for k in range(len(j[2])): print("Current Game: {}. Current Stage: {}. Current Act: {}.".format(j[0], j[1], k+1,)) #env = make(game='SonicAndKnuckles3-Genesis', state='SandopolisZone.Act2') env = make(game=j[0], state=j[1] + j[2][k]) model = bebna() model.setup(env, observation_hashes) obs = env.reset() for i in range(1000): frame_stuff = {} frame_stuff['info'] = info frame_stuff['action'] = action.tolist() action = model.process_data(obs.astype(np.float32) / 255.0, frame_stuff, f) #obs, rew, done, info = env.step(env.action_space.sample()) obs, rew, done, info = env.step(action) #print('Info: {}'.format(info)) #model.animate_data(obs, obs) #env.render() if done: obs = env.reset() env.close() with open("frame_data.json","w") as temp_file: json.dump(f, temp_file) '''
class AllowBacktracking(gym.Wrapper): def __init__(self, env): super(AllowBacktracking, self).__init__(env) self._cur_x = 0 self._max_x = 0 return self.env.reset(**kwargs) def reset(self, **kwargs): # pylint: disable=E0202 self._cur_x = 0 self._max_x = 0 return self.env.reset(**kwargs) def step(self, action): # pylint: disable=E0202 obs, rew, done, info = self.env.step(action) self._cur_x += rew rew = max(0, self._cur_x - self._max_x) self._max_x = max(self._max_x, self._cur_x) return obs, rew, done, info def make_env(env_idx): dicts = [ {'game': 'SonicTheHedgehog-Genesis', 'state': 'SpringYardZone.Act3'}, {'game': 'SonicTheHedgehog-Genesis', 'state': 'SpringYardZone.Act2'}, {'game': 'SonicTheHedgehog-Genesis', 'state': 'GreenHillZone.Act3'}, {'game': 'SonicTheHedgehog-Genesis', 'state': 'GreenHillZone.Act1'}, {'game': 'SonicTheHedgehog-Genesis', 'state': 'StarLightZone.Act2'}, {'game': 'SonicTheHedgehog-Genesis', 'state': 'StarLightZone.Act1'}, {'game': 'SonicTheHedgehog-Genesis', 'state': 'MarbleZone.Act2'}, {'game': 'SonicTheHedgehog-Genesis', 'state': 'MarbleZone.Act1'}, {'game': 'SonicTheHedgehog-Genesis', 'state': 'MarbleZone.Act3'}, {'game': 'SonicTheHedgehog-Genesis', 'state': 'ScrapBrainZone.Act2'}, {'game': 'SonicTheHedgehog-Genesis', 'state': 'LabyrinthZone.Act2'}, {'game': 'SonicTheHedgehog-Genesis', 'state': 'LabyrinthZone.Act1'}, {'game': 'SonicTheHedgehog-Genesis', 'state': 'LabyrinthZone.Act3'} ] # Make the environment print(dicts[env_idx]['game'], dicts[env_idx]['state'], flush=True) #record_path = "./records/" + dicts[env_idx]['state'] env = make(game=dicts[env_idx]['game'], state=dicts[env_idx]['state'], bk2dir="./records")#record='/tmp') # Build the actions array, env = ActionsDiscretizer(env) # Scale the rewards env = RewardScaler(env) # PreprocessFrame env = PreprocessFrame(env) # Stack 4 frames env = FrameStack(env, 4) # Allow back tracking that helps agents are not discouraged too heavily # from exploring backwards if there is no way to advance # head-on in the level. env = AllowBacktracking(env) return env
def env_fn(): env = make(game, state=state, bk2dir=bk2dir) env = StuckReset(env) env = AllowBacktracking(env) env = SonicDiscretizer(env) return env
def __init__(self, actions, n_episodes=100, game='SonicTheHedgehog-Genesis', state='LabyrinthZone.Act1', record=False): self.actions = actions self.n_episodes = n_episodes self.game = game self.state = state self.record = record if self.record: self.env = SonicEnvWrapper( make(game=game, state=state, bk2dir='./recordings')) else: self.env = SonicEnvWrapper(make(game=game, state=state))
def main(): env = make(game='SonicTheHedgehog-Genesis', state='LabyrinthZone.Act1') obs = env.reset() while True: obs, rew, done, info = env.step(env.action_space.sample()) env.render() if done: obs = env.reset()
def restart(): # rg = int(random.random() * len(train_level)) global current_level rg = (current_level + 10) % level_num env = make(game=train_level[rg][0], state=train_level[rg][1]) # print(train_level[rg][0], train_level[rg][1]) return env, train_level[rg][0], train_level[rg][1]
def make_retro(env_id, state_id, game_states=None): env = make(game=env_id, state=state_id) env = RandomEnvironment(env, game_states) env = SonicDiscretizer(env) env = SonicRescale84x84(env) env = AllowBacktracking(env) env = FrameStack(env, 4) return env
def make_env(env_idx): #create an environment with standard wrappers dicts = [{ 'game': 'SonicTheHedgehog2-Genesis', 'state': 'EmeraldHillZone.Act1' }, { 'game': 'SonicTheHedgehog2-Genesis', 'state': 'ChemicalPlantZone.Act2' }, { 'game': 'SonicTheHedgehog2-Genesis', 'state': 'ChemicalPlantZone.Act1' }, { 'game': 'SonicTheHedgehog2-Genesis', 'state': 'MetropolisZone.Act1' }, { 'game': 'SonicTheHedgehog2-Genesis', 'state': 'MetropolisZone.Act2' }, { 'game': 'SonicTheHedgehog2-Genesis', 'state': 'OilOceanZone.Act1' }, { 'game': 'SonicTheHedgehog2-Genesis', 'state': 'OilOceanZone.Act2' }, { 'game': 'SonicAndKnuckles3-Genesis', 'state': 'LavaReefZone.Act2' }, { 'game': 'SonicAndKnuckles3-Genesis', 'state': 'CarnivalNightZone.Act2' }, { 'game': 'SonicAndKnuckles3-Genesis', 'state': 'CarnivalNightZone.Act1' }, { 'game': 'SonicAndKnuckles3-Genesis', 'state': 'MushroomHillZone.Act2' }, { 'game': 'SonicAndKnuckles3-Genesis', 'state': 'MushroomHillZone.Act1' }, { 'game': 'SonicAndKnuckles3-Genesis', 'state': 'AngelIslandZone.Act1' }] print(dicts[env_idx]['game'], dicts[env_idx]['state'], flush=True) env = make(game=dicts[env_idx]['game'], state=dicts[env_idx]['state']) #build actions array env = ActionsDiscretizer(env) #scale rewards env = RewardScaler(env) #Preprocess Frame env = PreprocessFrame(env) #Stack em' env = FrameStack(env, 4) #Allow for backgracking. env = AllowBacktracking(env) return env
def get_environment(): if is_local: from retro_contest.local import make env = make(game='SonicTheHedgehog-Genesis', state='LabyrinthZone.Act1') else: import gym_remote.exceptions as gre import gym_remote.client as grc env = grc.RemoteEnv('tmp/sock') return env
def main(): env = make(game='SonicTheHedgehog-Genesis', state='SpringYardZone.Act3') obs = env.reset() while True: time.sleep(0.2) obs, rew, done, info = env.step(np.array([1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])) env.render() if done: obs = env.reset()
def main(): global args args = parser.parse_args() env = make(game='SonicTheHedgehog-Genesis', state='LabyrinthZone.Act1') current_state = get_screen(env) for epoch in range(args.epochs): env.reset()
def make_extra(env_idx, stack=True, scale_rew=True): """ Create an environment with some standard wrappers. """ dicts = [ {'game': 'SonicTheHedgehog-Sms', 'state': 'sonic-sms-0-0'}, {'game': 'SonicTheHedgehog-Sms', 'state': 'sonic-sms-0-1'}, {'game': 'SonicTheHedgehog-Sms', 'state': 'sonic-sms-1-0'}, {'game': 'SonicTheHedgehog-Sms', 'state': 'sonic-sms-1-1'}, {'game': 'SonicTheHedgehog-Sms', 'state': 'sonic-sms-2-0'}, {'game': 'SonicTheHedgehog-Sms', 'state': 'sonic-sms-3-0'}, {'game': 'SonicTheHedgehog-Sms', 'state': 'sonic-sms-3-1'}, {'game': 'SonicTheHedgehog-Sms', 'state': 'sonic-sms-3-2'}, {'game': 'SonicTheHedgehog-Sms', 'state': 'sonic-sms-4-0'}, {'game': 'SonicTheHedgehog-Sms', 'state': 'sonic-sms-4-1'}, {'game': 'SonicTheHedgehog-Sms', 'state': 'sonic-sms-5-0'}, {'game': 'SonicTheHedgehog-Sms', 'state': 'sonic-sms-5-1'}, {'game': 'SonicTheHedgehog2-Sms', 'state': 'sonic2-sms-0-0'}, # 12 {'game': 'SonicTheHedgehog2-Sms', 'state': 'sonic2-sms-0-1'}, {'game': 'SonicTheHedgehog2-Sms', 'state': 'sonic2-sms-0-2'}, {'game': 'SonicTheHedgehog2-Sms', 'state': 'sonic2-sms-1-0'}, {'game': 'SonicTheHedgehog2-Sms', 'state': 'sonic2-sms-1-1'}, {'game': 'SonicTheHedgehog2-Sms', 'state': 'sonic2-sms-1-2'}, {'game': 'SonicTheHedgehog2-Sms', 'state': 'sonic2-sms-2-0'}, {'game': 'SonicTheHedgehog2-Sms', 'state': 'sonic2-sms-2-1'}, {'game': 'SonicTheHedgehog2-Sms', 'state': 'sonic2-sms-2-2'}, {'game': 'SonicTheHedgehog2-Sms', 'state': 'sonic2-sms-3-0'}, {'game': 'SonicTheHedgehog2-Sms', 'state': 'sonic2-sms-3-1'}, {'game': 'SonicTheHedgehog2-Sms', 'state': 'sonic2-sms-3-2'}, {'game': 'SonicTheHedgehog2-Sms', 'state': 'sonic2-sms-4-0'}, {'game': 'SonicTheHedgehog2-Sms', 'state': 'sonic2-sms-4-1'}, {'game': 'SonicTheHedgehog2-Sms', 'state': 'sonic2-sms-4-2'}, {'game': 'SonicTheHedgehog2-Sms', 'state': 'sonic2-sms-5-1'}, {'game': 'SonicAdvance-Gba', 'state': 'sonica-0-0'}, # 28 {'game': 'SonicAdvance-Gba', 'state': 'sonica-0-1'}, {'game': 'SonicAdvance-Gba', 'state': 'sonica-1-0'}, {'game': 'SonicAdvance-Gba', 'state': 'sonica-1-1'}, {'game': 'SonicAdvance-Gba', 'state': 'sonica-2-0'}, {'game': 'SonicAdvance-Gba', 'state': 'sonica-2-1'}, {'game': 'SonicAdvance-Gba', 'state': 'sonica-3-0'}, {'game': 'SonicAdvance-Gba', 'state': 'sonica-3-1'}, {'game': 'SonicAdvance-Gba', 'state': 'sonica-4-0'}, {'game': 'SonicAdvance-Gba', 'state': 'sonica-4-1'}, {'game': 'SonicAdvance-Gba', 'state': 'sonica-5-0'}, {'game': 'SonicAdvance-Gba', 'state': 'sonica-6-0'}, ] print(dicts[env_idx]['game'], dicts[env_idx]['state'], flush=True) env = make(game=dicts[env_idx]['game'], state=dicts[env_idx]['state'])#, bk2dir='/tmp')#, record='/tmp') env = SonicDiscretizer(env) if scale_rew: env = RewardScaler(env) env = WarpFrame96(env) if stack: env = FrameStack(env, 4) env = AllowBacktracking(env) return env
def main(): env = make(game='SonicTheHedgehog-Genesis', state='LabyrinthZone.Act1', bk2dir='./data') obs = env.reset() while True: action = env.action_space.sample() action[7] = 1 obs, rew, done, info = env.step(action) env.render() if done: break # obs = env.reset() env.close()
def make_env(env_idx): """ Create an environment with some standard wrappers. """ dicts = [ {'game': 'SonicTheHedgehog2-Genesis', 'state': 'EmeraldHillZone.Act1'}, {'game': 'SonicTheHedgehog2-Genesis', 'state': 'ChemicalPlantZone.Act2'}, {'game': 'SonicTheHedgehog2-Genesis', 'state': 'ChemicalPlantZone.Act1'}, {'game': 'SonicTheHedgehog2-Genesis', 'state': 'MetropolisZone.Act1'}, {'game': 'SonicTheHedgehog2-Genesis', 'state': 'MetropolisZone.Act2'}, {'game': 'SonicTheHedgehog2-Genesis', 'state': 'OilOceanZone.Act1'}, {'game': 'SonicTheHedgehog2-Genesis', 'state': 'OilOceanZone.Act2'}, {'game': 'SonicAndKnuckles3-Genesis', 'state': 'LavaReefZone.Act2'}, {'game': 'SonicAndKnuckles3-Genesis', 'state': 'CarnivalNightZone.Act2'}, {'game': 'SonicAndKnuckles3-Genesis', 'state': 'CarnivalNightZone.Act1'}, {'game': 'SonicAndKnuckles3-Genesis', 'state': 'MushroomHillZone.Act2'}, {'game': 'SonicAndKnuckles3-Genesis', 'state': 'MushroomHillZone.Act1'}, {'game': 'SonicAndKnuckles3-Genesis', 'state': 'AngelIslandZone.Act1'} ] # Make the environment print(dicts[env_idx]['game'], dicts[env_idx]['state'], flush=True) #record_path = "./records/" + dicts[env_idx]['state'] env = make(game=dicts[env_idx]['game'], state=dicts[env_idx]['state'])#, bk2dir="./records")#record='/tmp') # Build the actions array, env = ActionsDiscretizer(env) # Scale the rewards env = RewardScaler(env) # PreprocessFrame env = PreprocessFrame(env) # Stack 4 frames env = FrameStack(env, 4) # Allow back tracking that helps agents are not discouraged too heavily # from exploring backwards if there is no way to advance # head-on in the level. env = AllowBacktracking(env) return env
def make_test(): """ Create an environment with some standard wrappers. dicts = [ {'game': 'SonicTheHedgehog2-Genesis', 'state': 'EmeraldHillZone.Act1'}, {'game': 'SonicTheHedgehog2-Genesis', 'state': 'ChemicalPlantZone.Act2'}, {'game': 'SonicTheHedgehog2-Genesis', 'state': 'ChemicalPlantZone.Act1'}, {'game': 'SonicTheHedgehog2-Genesis', 'state': 'MetropolisZone.Act1'}, {'game': 'SonicTheHedgehog2-Genesis', 'state': 'MetropolisZone.Act2'}, {'game': 'SonicTheHedgehog2-Genesis', 'state': 'OilOceanZone.Act1'}, {'game': 'SonicTheHedgehog2-Genesis', 'state': 'OilOceanZone.Act2'}, {'game': 'SonicAndKnuckles3-Genesis', 'state': 'LavaReefZone.Act2'}, {'game': 'SonicAndKnuckles3-Genesis', 'state': 'CarnivalNightZone.Act2'}, {'game': 'SonicAndKnuckles3-Genesis', 'state': 'CarnivalNightZone.Act1'}, {'game': 'SonicAndKnuckles3-Genesis', 'state': 'MushroomHillZone.Act2'}, {'game': 'SonicAndKnuckles3-Genesis', 'state': 'MushroomHillZone.Act1'}, {'game': 'SonicAndKnuckles3-Genesis', 'state': 'AngelIslandZone.Act1'} ] """ # Here we add record because we want to output a video env = make(game="SonicAndKnuckles3-Genesis", state="AngelIslandZone.Act1") # Build the actions array, env = ActionsDiscretizer(env) # Scale the rewards env = RewardScaler(env) # PreprocessFrame env = PreprocessFrame(env) # Stack 4 frames env = FrameStack(env, 4) # Allow back tracking that helps agents are not discouraged too heavily # from exploring backwards if there is no way to advance # head-on in the level. env = AllowBacktracking(env) return env