Exemplo n.º 1
0
    def registerInitialState(self, gameState):
        """
    This method handles the initial setup of the
    agent to populate useful fields (such as what team
    we're on).

    A distanceCalculator instance caches the maze distances
    between each pair of positions, so your agents can use:
    self.distancer.getDistance(p1, p2)

    IMPORTANT: This method may run for at most 15 seconds.
    """
        '''
    Make sure you do not delete the following line. If you would like to
    use Manhattan distances instead of maze distances in order to save
    on initialization time, please take a look at
    CaptureAgent.registerInitialState in captureAgents.py.
    '''
        self.start = gameState.getAgentPosition(self.index)
        self.team = CaptureAgent.getTeam(self, gameState)
        self.food = CaptureAgent.getFood(self, gameState)
        self.foodDefending = CaptureAgent.getFoodYouAreDefending(
            self, gameState)
        self.opponents = CaptureAgent.getOpponents(self, gameState)
        print("Start: ", self.start, "Team: ", self.team, "Food: ", self.food,
              "Food Defending:", self.foodDefending, "Opponent: ",
              self.opponents)
        CaptureAgent.registerInitialState(self, gameState)
        '''
Exemplo n.º 2
0
 def registerInitialState(self, gameState):
     CaptureAgent.registerInitialState(self, gameState)
     self.myAgents = CaptureAgent.getTeam(self, gameState)
     self.opponentsAgents = CaptureAgent.getOpponents(self, gameState)
     self.myFoods = CaptureAgent.getFood(self, gameState).asList()
     self.opponentsFoods = CaptureAgent.getFoodYouAreDefending(
         self, gameState).asList()
Exemplo n.º 3
0
    def isFoodReturned(self, choice):
        '''
    ova funkcija proverava da li ce pacman nakon izabrane akcije vratiti pojedenu hranu na svoj teren.
    kada vrati hranu na svoj teren, atributi jaSamPojeo i _foodEaten se resetuju na pocetno stanje.
    '''
        succState = self.getSuccessor(self._gameState, choice)
        succPosX = succState.getAgentState(self.index).getPosition()[0]
        homeX = CaptureAgent.getFood(self, self._gameState).width // 2

        if succPosX == homeX and self.jaSamPojeo is True:
            self.jaSamPojeo = False
            self._foodEaten = 0
Exemplo n.º 4
0
	def registerInitialState(self, gameState):
		"""
		This method handles the initial setup of the
		agent to populate useful fields (such as what team
		we're on).
		"""

		CaptureAgent.registerInitialState(self, gameState)
		self.myAgents = CaptureAgent.getTeam(self, gameState)
		self.opAgents = CaptureAgent.getOpponents(self, gameState)
		self.myFoods = CaptureAgent.getFood(self, gameState).asList()
		self.opFoods = CaptureAgent.getFoodYouAreDefending(self, gameState).asList()
Exemplo n.º 5
0
    def get_distances_to_food_factor(self, agent_position, agent_index,
                                     enemy_team):
        if (enemy_team):
            food = CaptureAgent.getFoodYouAreDefending(self.root_agent_object,
                                                       self.node_state)
        else:
            food = CaptureAgent.getFood(self.root_agent_object,
                                        self.node_state)

        distances = []

        blue_capsule = (-1, -1)
        red_capsule = (-1, -1)

        for c in self.node_state.data.capsules:
            if c[0] > self.node_state.data.layout.width / 2:
                blue_capsule = c
            else:
                red_capsule = c

        blue_side = agent_index % 2
        if blue_side:
            our_capsule = red_capsule
        else:
            our_capsule = blue_capsule

        for i in range(0, food.width):
            for j in range(0, food.height):
                if food.data[i][j] or our_capsule == (i, j):
                    distance = CaptureAgent.getMazeDistance(
                        self.root_agent_object, agent_position, (i, j))
                    distances.append(distance)

        if (len(distances) == 0): return 1

        #distance_to_food_factor = sum(distances) / float(len(distances))
        distance_to_food_factor = min(distances)
        if (distance_to_food_factor == 0):
            distance_to_food_factor = 1

        distance_to_food_factor = 1 / distance_to_food_factor
        distance_to_food_factor = distance_to_food_factor * 1

        return distance_to_food_factor
Exemplo n.º 6
0
 def returnFood(self):
     '''
 ako sam JA pojeo hranu vrati se nazad
 mora try blok jer baca exception u getMazeDistance, kada probam da
 se pomerim u jednu stranu, a protivnicki pacman me je pojeo.
 Sto sam dalje od kuce to je evalute funkcija losija
 '''
     try:
         predecessor = self.getPreviousObservation()
         if predecessor is not None:
             pojedenaHrana = len(self.getFood(predecessor).asList()) != len(
                 self.getFood(self._gameState).asList())
             if pojedenaHrana is True and self.jaSamPojeo is True:
                 xHome = CaptureAgent.getFood(
                     self, self._gameState).width // 3 + 1
                 yHome = self._gameState.getAgentState(
                     self.index).getPosition()[1]
                 homeCoords = (xHome, yHome)
                 distanceToHome = self._foodEaten * self.getMazeDistance(
                     self._succPos, homeCoords)
                 self._features['distanceToHome'] = distanceToHome
     except:
         pass
Exemplo n.º 7
0
	def registerInitialState(self, gameState):
		CaptureAgent.registerInitialState(self, gameState)
		self.init = gameState.getAgentState(self.index).getPosition()
		self.epsilon = 0.0#exploration prob
		self.alpha = 0.1 #learning rate
		self.discountRate = 0.8
		self.dangeFood = []
		self.mode = 1
		self.weights1 = {'closest-food': 2.35219445732408, 'bias': 2.579502234147277, 'closest-capsule': 2.473714473123398}
		self.weights2 = {'closest-food': 1.02910769618005556, 'bias': -6.112936837778204, 'closest-ghosts': -10.11587156566253, 'closest-capsule': 1.257363246901937, 'num-of-walls': -10.4903928122119086, 'time-of-scared-ghosts': 1.6265815562445105, 'reverse': -2.732599631268455}
		self.weights3 = {'bias': -0.1619191782335229, 'closest-ghosts': -18.645334316865307, 'num-of-walls': -10.45335435502801, 'distance-back-to-home': 2.0996715469522775, 'time-of-scared-ghosts': 0.7966612961334337, 'reverse': -2.732599631268455,'closest-capsule': 4.523232232232323}										
		self.weights4 = {'bias': 6.802602309336149, 'distance-back-to-home': 12.7541385540534}
		self.finish = False
		self.myAgents = CaptureAgent.getTeam(self, gameState)
		self.opAgents = CaptureAgent.getOpponents(self, gameState)
		self.myFoods = CaptureAgent.getFood(self, gameState).asList()
		self.opFoods = CaptureAgent.getFoodYouAreDefending(self, gameState).asList()
		self.lostFoods = []
		self.gamescore = 0

		self.midWidth = gameState.data.layout.width / 2
		self.height = gameState.data.layout.height
		self.width = gameState.data.layout.width
		self.midHeight = gameState.data.layout.height / 2