def playGame(actor): random_state = np.random.RandomState(123) n_games = 10 seed = 123 seeds = generate_deterministic_seeds(seed, n_games) env = gym.make("Pendulum-v0") # To use # env = gym.make("BipedalWalker-v3") # agent = doDDPG() rewards = [] for i_episode in trange(n_games): np.random.seed(seeds[i_episode]) random.seed(seeds[i_episode]) env.seed(int(seeds[i_episode])) state = env.reset() done = False total_reward = 0 cur_state = env.reset() while not done: env.render() cur_state = cur_state.reshape((1, env.observation_space.shape[0])) action = actor.act(cur_state) # print(action) new_state, reward, done, info = env.step(action) total_reward += reward if done: print(env) break rewards.append(total_reward) print("Avg reward: {:0.2f}".format(np.mean(rewards))) print("Min reward: {:0.2f}".format(np.min(rewards))) print("Max reward: {:0.2f}".format(np.max(rewards))) print() env.close()
parser.add_argument("-s", "--seed", help="Random seed.", type=np.uint32, default=None) parser.add_argument("-v", "--verbose", action="store_true") parser.add_argument("-sh", "--show_histogram", action="store_true") args = parser.parse_args() return args if __name__ == "__main__": args = parse_args() # Fix the random seed if args.seed is not None: seeds = generate_deterministic_seeds(args.seed, args.num_games) else: seeds = None # Choose a Pacman agent AgentClass = load_agent(args.agent) agent = AgentClass() from misio.pacman.pacman import LocalPacmanGameRunner runner = LocalPacmanGameRunner(layout_dir=args.layout, random_ghosts=args.random_ghosts, show_window=not args.no_graphics, zoom_window=args.zoom, frame_time=args.frame_time) games = [] for i in tqdm.trange(args.num_games, leave=False):
from tqdm import trange import gym import numpy as np import random import time random_state = np.random.RandomState(123) if __name__ == "__main__": # env = gym.make('BipedalWalker-v2') n_games = 100 seed = 123 seeds = generate_deterministic_seeds(seed, n_games) env = gym.make("Pendulum-v0") # env = gym.make("BipedalWalker-v2") rewards = [] for i_episode in trange(n_games): np.random.seed(seeds[i_episode]) random.seed(seeds[i_episode]) env.seed(int(seeds[i_episode])) state = env.reset() done = False total_reward = 0 while not done: # env.render() # time.sleep(0.05)