def __init__(self, **args): "Initialize Q-values" # Separamos los argumentos de la superclase BusterAgent bustersArgs = {} bustersArgs['ghostAgents'] = args['ghostAgents'] # y los de la clase ReinforcementAgent reinforcementArgs = {} for i in ('alpha', 'epsilon', 'gamma'): reinforcementArgs[i] = args[i] reinforcementArgs['actionFn'] = self.getPossibleActions BustersAgent.__init__(self, **bustersArgs) ReinforcementAgent.__init__(self, **reinforcementArgs) # Traza comun de arranque en todos los agentes self.trace('Init::AgentName=' + self.getAgentName()) for creator in enumerate(CREATORS): self.trace('Init::Creator ' + str(creator[0] + 1) + ' ' + str(creator[1]) + '>' + CREATORS[creator[1]]) self.trace('Init::Q-Learning initialization values') for i in ('alpha', 'epsilon', 'gamma'): self.trace(' ' + str(i) + '=' + str(args[i])) if not os.path.exists(self.getQTableFileName()): self.createInitialQTable() self.table_file = open(self.getQTableFileName(), "r+") # Try to read and then to write to detect problems at the beginning self.q_table = self.readQtable() self.writeQtable() # Statictics initialization self.stats = {'ticks': 0, 'finalScore': 0, 'QTableUpdates': 0}
def run_game(): lay = layout.getLayout('q1/1-ExactObserve') gameDisplay = graphicsDisplay.PacmanGraphics( frameTime=0.1 ) # initialize the display of the playing field, needed here for the Pacman agent ghosts = [trackingTestClasses.SeededRandomGhostAgent(1) ] # controls the behavior of a random ghost mr_pacman = BustersAgent( ghostAgents=ghosts, inference=inference.ExactInference, elapseTimeEnable=False) # controls the pacman behavior game = rules.newGame(lay, mr_pacman, ghostAgents=ghosts, display=gameDisplay, maxMoves=50) # instantiate a Game instance, see below game.run() # run the game, until Pacman catches a ghost.
def registerInitialState(self, gameState): BustersAgent.registerInitialState(self, gameState) self.distancer = Distancer(gameState.data.layout, False) self.countActions = 0
def registerInitialState(self, gameState): "Pre-computes the distance between every two points." BustersAgent.registerInitialState(self, gameState) self.distancer = Distancer(gameState.data.layout, False)