qlearningAgents.py
def update(self, state, action, nextState, reward):
        """
           Should update your weights based on transition
        """
        features = self.featExtractor.getFeatures(state,action)
        difference = reward + self.discount * self.computeValueFromQValues(nextState) - self.getQValue(state,action)  # seperate because it doesn't work otherwise :///

        useOtherVector = False
        p = state.data.agentStates[0].configuration.pos
        g1 = state.data.agentStates[1]
        g2 = state.data.agentStates[2]
        distg1 = self.featExtractor.paths[(p[0], p[1]), (int(g1.configuration.pos[0]), int(g1.configuration.pos[1]))]
        distg2 = self.featExtractor.paths[(p[0], p[1]), (int(g2.configuration.pos[0]), int(g2.configuration.pos[1]))]
        if (g1.scaredTimer > 0 and distg1 < distg2) or (g2.scaredTimer > 0 and distg2 < distg1):
            useOtherVector = True


        if useOtherVector:
            for feat in features:
                self.weightsScared[feat] += self.alpha * difference * features[feat]  # w_i + alfa * difference * f_i(s,a)
        else:
            for feat in features:
                self.weights[feat] += self.alpha * difference * features[feat]

           Should update your weights based on transition
        
Should update your weights based on transition
Should update your weights based on transition
def update(self, state, action, nextState, reward):
        features = self.featExtractor.getFeatures(state,action)
        difference = reward + self.discount * self.computeValueFromQValues(nextState) - self.getQValue(state,action)  
        useOtherVector = False
        p = state.data.agentStates[0].configuration.pos
        g1 = state.data.agentStates[1]
        g2 = state.data.agentStates[2]
        distg1 = self.featExtractor.paths[(p[0], p[1]), (int(g1.configuration.pos[0]), int(g1.configuration.pos[1]))]
        distg2 = self.featExtractor.paths[(p[0], p[1]), (int(g2.configuration.pos[0]), int(g2.configuration.pos[1]))]
        if (g1.scaredTimer > 0 and distg1 < distg2) or (g2.scaredTimer > 0 and distg2 < distg1):
            useOtherVector = True
        if useOtherVector:
            for feat in features:
                self.weightsScared[feat] += self.alpha * difference * features[feat]  
        else:
            for feat in features:
                self.weights[feat] += self.alpha * difference * features[feat]
def update ( self , state , action , nextState , reward ) : features = self . featExtractor . getFeatures ( state , action ) difference = reward + self . discount * self . computeValueFromQValues ( nextState ) - self . getQValue ( state , action ) useOtherVector = False p = state . data . agentStates [ 0 ] . configuration . pos g1 = state . data . agentStates [ 1 ] g2 = state . data . agentStates [ 2 ] distg1 = self . featExtractor . paths [ ( p [ 0 ] , p [ 1 ] ) , ( int ( g1 . configuration . pos [ 0 ] ) , int ( g1 . configuration . pos [ 1 ] ) ) ] distg2 = self . featExtractor . paths [ ( p [ 0 ] , p [ 1 ] ) , ( int ( g2 . configuration . pos [ 0 ] ) , int ( g2 . configuration . pos [ 1 ] ) ) ] if ( g1 . scaredTimer > 0 and distg1 < distg2 ) or ( g2 . scaredTimer > 0 and distg2 < distg1 ) : useOtherVector = True if useOtherVector : for feat in features : self . weightsScared [ feat ] += self . alpha * difference * features [ feat ] else : for feat in features : self . weights [ feat ] += self . alpha * difference * features [ feat ]
Should update your weights based on transition
Should update your weights based on transition
"""
           Should update your weights based on transition
        """ # seperate because it doesn't work otherwise :/// # w_i + alfa * difference * f_i(s,a)
self
state
action
nextState
reward