Commit 4486a5ab authored by anon's avatar anon
Browse files

Approximate QLearning Agent

parent 70e6164f
......@@ -190,15 +190,22 @@ class ApproximateQAgent(PacmanQAgent):
Should return Q(state,action) = w * featureVector
where * is the dotProduct operator
"""
"*** YOUR CODE HERE ***"
util.raiseNotDefined()
features = self.featExtractor.getFeatures(state, action)
qVal = 0
for feat, val in features.items():
qVal += val * self.weights[feat]
return qVal
def update(self, state, action, nextState, reward):
"""
Should update your weights based on transition
"""
"*** YOUR CODE HERE ***"
util.raiseNotDefined()
features = self.featExtractor.getFeatures(state, action)
difference = (reward + self.discount * self.getValue(nextState)) - self.getQValue(state, action)
for feat, val in features.items():
self.weights[feat] += self.alpha * difference * val
def final(self, state):
"Called at the end of each game."
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment