Esempio n. 1
0
  def chooseAction(self, gameState):
    
    actions = gameState.getLegalActions(self.index)
    default = 'Stop'
    capsules = CaptureAgent.getCapsulesYouAreDefending(self, gameState)
    
    if(capsules):
      capsuleToGoTo = capsules[0]
      myPos = gameState.getAgentPosition(self.index)
      
      if(myPos != capsuleToGoTo and not self.onGuard):
        for action in actions: 
          newState = self.getSuccessor(gameState, action)
          newDis = CaptureAgent.getMazeDistance(self, newState.getAgentState(self.index).getPosition(),capsuleToGoTo);
          currentDis = CaptureAgent.getMazeDistance(self, myPos,capsuleToGoTo);
          if newDis < currentDis:
              return action
      else:
        if not self.onGuard:
          default = actions[0]
          self.onGuard = True
 
    return default