<s> from game import * <EOL> from learningAgents import ReinforcementAgent <EOL> from featureExtractors import * <EOL> import random <EOL> import util <EOL> import math <EOL> class QLearningAgent ( ReinforcementAgent ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , ** args ) : <EOL> "<STR_LIT>" <EOL> ReinforcementAgent . __init__ ( self , ** args ) <EOL> "<STR_LIT>" <EOL> def getQValue ( self , state , action ) : <EOL> """<STR_LIT>""" <EOL> "<STR_LIT>" <EOL> util . raiseNotDefined ( ) <EOL> def computeValueFromQValues ( self , state ) : <EOL> """<STR_LIT>""" <EOL> "<STR_LIT>" <EOL> util . raiseNotDefined ( ) <EOL> def computeActionFromQValues ( self , state ) : <EOL> """<STR_LIT>""" <EOL> "<STR_LIT>" <EOL> util . raiseNotDefined ( ) <EOL> def getAction ( self , state ) : <EOL> """<STR_LIT>""" <EOL> legalActions = self . getLegalActions ( state ) <EOL> action = None <EOL> "<STR_LIT>" <EOL> util . raiseNotDefined ( ) <EOL> return action <EOL> def update ( self , state , action , nextState , reward ) : <EOL> """<STR_LIT>""" <EOL> "<STR_LIT>" <EOL> util . raiseNotDefined ( ) <EOL> def getPolicy ( self , state ) : <EOL> return self . computeActionFromQValues ( state ) <EOL> def getValue ( self , state ) : <EOL> return self . computeValueFromQValues ( state ) <EOL> class PacmanQAgent ( QLearningAgent ) : <EOL> "<STR_LIT>" <EOL> def __init__ ( self , epsilon = <NUM_LIT> , gamma = <NUM_LIT> , <EOL> alpha = <NUM_LIT> , numTraining = <NUM_LIT:0> , ** args ) : <EOL> """<STR_LIT>""" <EOL> args [ '<STR_LIT>' ] = epsilon <EOL> args [ '<STR_LIT>' ] = gamma <EOL> args [ '<STR_LIT>' ] = alpha <EOL> args [ '<STR_LIT>' ] = numTraining <EOL> self . index = <NUM_LIT:0> <EOL> QLearningAgent . __init__ ( self , ** args ) <EOL> def getAction ( self , state ) : <EOL> """<STR_LIT>""" <EOL> action = QLearningAgent . getAction ( self , state ) <EOL> self . doAction ( state , action ) <EOL> return action <EOL> class ApproximateQAgent ( PacmanQAgent ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , extractor = '<STR_LIT>' , ** args ) : <EOL> self . featExtractor = util . lookup ( extractor , globals ( ) ) ( ) <EOL> PacmanQAgent . __init__ ( self , ** args ) <EOL> self . weights = util . Counter ( ) <EOL> def getWeights ( self ) : <EOL> return self . weights <EOL> def getQValue ( self , state , action ) : <EOL> """<STR_LIT>""" <EOL> "<STR_LIT>" <EOL> util . raiseNotDefined ( ) <EOL> def update ( self , state , action , nextState , reward ) : <EOL> """<STR_LIT>""" <EOL> "<STR_LIT>" <EOL> util . raiseNotDefined ( ) <EOL> def final ( self , state ) : <EOL> "<STR_LIT>" <EOL> PacmanQAgent . final ( self , state ) <EOL> if self . episodesSoFar == self . numTraining : <EOL> "<STR_LIT>" <EOL> pass </s>
