def timeout_test(self, agentName): stats = {} if agentName == 'alphabeta': stats = run('smallClassic', submission.AlphaBetaAgent(depth=2), [DirectionalGhost(i + 1) for i in range(2)], name='%s (depth %d)' % ('alphabeta', 2)) elif agentName == 'minimax': stats = run('smallClassic', submission.MinimaxAgent(depth=2), [DirectionalGhost(i + 1) for i in range(2)], name='%s (depth %d)' % ('minimax', 2)) else: stats = run('smallClassic', submission.ExpectimaxAgent(depth=2), [DirectionalGhost(i + 1) for i in range(2)], name='%s (depth %d)' % ('expectimax', 2)) print(agentName) print(stats['timeouts']) self.assertLessEqual(stats['timeouts'], 0, msg=f'Your {agentName} agent timed out on smallClassic. No autograder feedback will be provided.')
def OBOB_test(self, agentName): if agentName not in self.gamePlay: if agentName == 'minimax': self.gamePlay[agentName] = comparison_checking(submission.MinimaxAgent(depth=2), {}, agentName) elif agentName == 'alphabeta': self.gamePlay[agentName] = comparison_checking(submission.AlphaBetaAgent(depth=2), {agentName: 'True'}, agentName) elif agentName == 'expectimax': self.gamePlay[agentName] = comparison_checking(submission.ExpectimaxAgent(depth=2), {agentName: 'True'}, agentName) else: raise Exception("Unexpected agent name: " + agentName) timeout, offByOne, partialPlyBug, totalSuboptimal = self.gamePlay[agentName] self.assertFalse(timeout, msg=f'Your {agentName} agent timed out on smallClassic. No autograder feedback will be provided.') self.assertFalse(offByOne, 'Depth off by 1')
def replayGame( layout, actions, display ): import submission, ghostAgents rules = ClassicGameRules() # If replaying, change the agent from ExpectimaxAgent to whatever agent with which you want to play agents = [submission.ExpectimaxAgent()] + [ghostAgents.RandomGhost(i+1) for i in range(layout.getNumGhosts())] game = rules.newGame( layout, agents[0], agents[1:], display ) state = game.state display.initialize(state.data) for action in actions: # Execute the action state = state.generateSuccessor( *action ) # Change the display display.update( state.data ) # Allow for game specific conditions (winning, losing, etc.) rules.process(state, game) display.finish()
def replayGame(layout, actions, display): import submission, ghostAgents rules = ClassicGameRules() agents = [submission.ExpectimaxAgent()] + [ ghostAgents.RandomGhost(i + 1) for i in range(layout.getNumGhosts()) ] game = rules.newGame(layout, agents[0], agents[1:], display) state = game.state display.initialize(state.data) for action in actions: state = state.generateSuccessor(*action) display.update(state.data) rules.process(state, game) display.finish()
def main(args=None): from optparse import OptionParser usage = "usage: %prog [options]" parser = OptionParser(usage=usage) parser.add_option("-t", "--train", dest="train", action="store_true", default=False, help="Train TD Player") parser.add_option("-d", "--draw", dest="draw", action="store_true", default=False, help="Draw game") parser.add_option("-n", "--num", dest="numgames", default=1, help="Num games to play") parser.add_option("-p", "--player1", dest="player1", default="random", help="Choose type of first player") parser.add_option("-e", "--eval", dest="eval", action="store_true", default=False, help="Play with the better eval function for player") (opts, args) = parser.parse_args(args) weights = None if opts.train: weights = train() if opts.eval: weights = load_weights(weights) evalFn = submission.logLinearEvaluation evalArgs = weights else: evalFn = submission.simpleEvaluation evalArgs = None p1 = None if opts.player1 == 'random': p1 = agent.RandomAgent(game.Game.TOKENS[0]) elif opts.player1 == 'reflex': p1 = submission.ReflexAgent(game.Game.TOKENS[0], evalFn, evalArgs) elif opts.player1 == 'expectimax': p1 = submission.ExpectimaxAgent(game.Game.TOKENS[0], evalFn, evalArgs) elif opts.player1 == 'human': p1 = agent.HumanAgent(game.Game.TOKENS[0]) p2 = agent.RandomAgent(game.Game.TOKENS[1]) if p1 is None: print "Please specify legitimate player" import sys sys.exit(1) test([p1, p2], numGames=int(opts.numgames), draw=opts.draw)