def play(self, path): runner = LocalPacmanGameRunner(layout_path=path, random_ghosts=True, show_window=True, zoom_window=1.0, frame_time=0.1, timeout=-1000) game = runner.run_game(self)
def playOneGame(layouts, numberOfGames, training, optilio, numTraining): for layout in layouts: with open("weights.txt") as f: weights = [float(x) for x in f.readline().split()] agent = ApproxAgent(train=training, optilio=optilio, numTraining=numTraining, weights_values=weights) runner = LocalPacmanGameRunner(layout, random_ghosts=False) game = runner.run_game(agent)
def load_runners(): paths = ['pacman_layouts/' + f for f in os.listdir('pacman_layouts')] random_ghosts = [False, True] runners, names = [], [] for p in paths: for rg in random_ghosts: runner = LocalPacmanGameRunner(layout_path=p, random_ghosts=rg, frame_time=0) runners.append(runner) names.append(p.split('/')[1] + '__random_ghosts={}'.format(rg)) assert len(runners) == len(names) return runners, names
def playGame(layouts, numberOfGames, training, optilio, numTraining): for layout in layouts: print(">>> ------------------------------ >>>") print(layout) with open("weights.txt") as f: weights = [float(x) for x in f.readline().split()] # weights = [0,0,0,0] # weights = [-27.9914705800362, -3394.38754114026, 334.87185911475, -60.5944964389825] # random # 237.0996722631916 -4588.853575536811 245.5868697927386 -84.61209079023303 # zeros # 131.6082538875898 -3662.5998496219695 293.8740546541827 -29.798118394469327 # 157.61426275835402 -3713.705833105122 -35.71944232589656 296.6912552309395 # again from above # -14.760990254051723 -4567.035436781129 372.17484562084405 274.64338077262755 agent = ApproxAgent(train=training, optilio=optilio, numTraining=numTraining, weights_values=weights) runner = LocalPacmanGameRunner(layout, random_ghosts=False) games = [] for i in range(numberOfGames): game = runner.run_game(agent) games.append(game) scores = [game.state.getScore() for game in games] results = np.array([game.state.isWin() for game in games]) print("Avg score >>: {:0.2f}".format(np.mean(scores))) print("Median score: {:0.2f}".format(np.median(scores))) print("Win Rate: {}/{} {:0.2f}".format(results.sum(), len(results), results.mean()))
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): if seeds is not None: random.seed(seeds[i]) game = runner.run_game(agent) games.append(game) scores = [game.state.getScore() for game in games] results = np.array([game.state.isWin() for game in games]) print("Avg score: {:0.2f}".format(np.mean(scores))) print("Best score: {:0.2f}".format(max(scores))) print("Median score: {:0.2f}".format(np.median(scores))) print("Worst score: {:0.2f}".format(min(scores)))
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_path=args.layout, random_ghosts=not args.smart_ghosts, show_window=not args.no_graphics, zoom_window=args.zoom, frame_time=args.frame_time, timeout=-1000) games = [] for i in tqdm.trange(args.num_games, leave=False): if seeds is not None: random.seed(seeds[i]) game = runner.run_game(agent) games.append(game) scores = [game.state.getScore() for game in games] results = np.array([game.state.isWin() for game in games]) print("Avg score: {:0.2f}".format(np.mean(scores))) print("Best score: {:0.2f}".format(max(scores))) print("Median score: {:0.2f}".format(np.median(scores))) print("Worst score: {:0.2f}".format(min(scores)))
import numpy as np from lab6.qlearningAgents import PacmanQAgent from misio.pacman.pacman import LocalPacmanGameRunner if __name__ == "__main__": agent = PacmanQAgent() "*** DISABLE TRAINING HERE ***" all_results = [] for (dirpath, dirnames, filenames) in walk("sample_solution/pacman_layouts"): for layout in filenames: runner = LocalPacmanGameRunner(layout_path=f"{dirpath}/{layout}", random_ghosts=True, show_window=False, timeout=-1000) games = [] for i in range(10): game = runner.run_game(agent) games.append(game) scores = [game.state.getScore() for game in games] results = np.array([game.state.isWin() for game in games]) all_results += list(results) print(layout) print(f"Avg score: {np.mean(scores):0.2f}") print(f"Best score: {max(scores):0.2f}") print(f"Median score: {np.median(scores):0.2f}")
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() runner = LocalPacmanGameRunner(args.layout, not args.smart_ghosts, not args.no_graphics, args.zoom, args.frame_time) games = [] for i in tqdm.trange(args.num_games, leave=False): if seeds is not None: random.seed(seeds[i]) game = runner.run_game(agent) games.append(game) scores = [game.state.getScore() for game in games] results = np.array([game.state.isWin() for game in games]) print("Avg score: {:0.2f}".format(np.mean(scores))) print("Best score: {:0.2f}".format(max(scores))) print("Median score: {:0.2f}".format(np.median(scores))) print("Worst score: {:0.2f}".format(min(scores)))