This commit is contained in:
2024-07-08 19:27:55 +08:00
parent 675529e9dc
commit a825670fda
6 changed files with 9 additions and 435 deletions

View File

@ -192,12 +192,21 @@ class ApproximateQAgent(PacmanQAgent):
where * is the dotProduct operator
"""
"*** YOUR CODE HERE ***"
featureVector = self.featExtractor.getFeatures(state, action)
qValue = 0
for feature in featureVector:
qValue += self.weights[feature] * featureVector[feature]
return qValue
def update(self, state, action, nextState, reward: float):
"""
Should update your weights based on transition
"""
"*** YOUR CODE HERE ***"
featureVector = self.featExtractor.getFeatures(state, action)
difference = reward + self.discount * self.computeValueFromQValues(nextState) - self.getQValue(state, action)
for feature in featureVector:
self.weights[feature] += self.alpha * difference * featureVector[feature]
def final(self, state):