Beispiel #1
0
class MSBSimulatedEnemyAgent:

	def __init__(self, index, distancer, uniform = False):
		self.index = index
		self.distancer = distancer
		self.weights = {
			"default" : 1
		}

		if uniform:
			self.agent = self
			return

		#currently, this uses BaselineAgents' agents.
		#To use the features/weights in this class, set self.agent = self
		try:
			from BaselineAgents.baselineAgents import OffensiveReflexAgent, DefensiveReflexAgent
			self.agent = OffensiveReflexAgent(index) if index%2==0 else DefensiveReflexAgent(index)
			self.agent.distancer = distancer
		except: #if BaselineAgents isn't accessible, fallback gracefully
			self.agent = self

	def getFeatures(self, state, action):
		return {"default":1}

	def evaluate(self, state, action):
		
		#fall through to another agent if we have one
		if self.agent is None:
			return 0
		elif self.agent != self:
			return max(0, self.agent.evaluate(state, action))

		features = self.getFeatures(state, action)
		amts = [features[i]*self.weights[i] if i in self.weights else 0 for i in features]
		return max(sum(amts), 0)

	def getDistribution(self, gameState):
		
		#get the utilities from the agent and find the maximum
		utilities = {action: self.evaluate(gameState, action) for action in gameState.getLegalActions(self.index)}
		maxUtility = max(utilities.values())
		
		#any action that maximizes utility gets equal probability, all else get 0
		tbr = util.Counter()
		for action in utilities:
			if utilities[action] < maxUtility:
				continue
			tbr[action] = 1
		tbr.normalize()

		return tbr
Beispiel #2
0
	def __init__(self, index, distancer, uniform = False):
		self.index = index
		self.distancer = distancer
		self.weights = {
			"default" : 1
		}

		if uniform:
			self.agent = self
			return

		#currently, this uses BaselineAgents' agents.
		#To use the features/weights in this class, set self.agent = self
		try:
			from BaselineAgents.baselineAgents import OffensiveReflexAgent, DefensiveReflexAgent
			self.agent = OffensiveReflexAgent(index) if index%2==0 else DefensiveReflexAgent(index)
			self.agent.distancer = distancer
		except: #if BaselineAgents isn't accessible, fallback gracefully
			self.agent = self