Exemple #1
0
def followActionBasis(self, observedState, action):
	allowedDirections = observedState.getLegalPacmanActions()
	pacmanPosition = observedState.getPacmanPosition()

	if action == 'good':
		target = classifyGhosts.getNearestGoodGhost(observedState, self.distancer)
	elif action == 'bad':
		target = classifyGhosts.getNearestBadGhost(observedState, self.distancer)
	elif action == 'capsule':
		target = classifyCapsule.closest(observedState, self.distancer)
	else:
		raise Exception("Unknown action '%s' passed to action basis" % action)

	# find the direction that moves closes to target
	best_action = Directions.STOP
	best_dist = np.inf
	for la in allowedDirections:
		if la == Directions.STOP:
			continue
		successor_pos = Actions.getSuccessor(pacmanPosition,la)
		new_dist = self.distancer.getDistance(successor_pos,target)
		if new_dist < best_dist:
			best_action = la
			best_dist = new_dist
	return best_action
Exemple #2
0
def ghostPosition(self,observedState):
	pacmanPosition = observedState.getPacmanPosition()
	ghost_positions = [ classifyGhosts.getNearestGoodGhost(observedState, self.distancer), classifyGhosts.getNearestBadGhost(observedState, self.distancer)]
	
	bins = 5
	xBinner = xbinner( (0,observedState.layout.width), bins )	
	yBinner = xbinner( (0,observedState.layout.height), bins )

	state = (xBinner(pacmanPosition[0]), yBinner(pacmanPosition[1]))
	for pos in ghost_positions:
		state += (xBinner(pos[0]),yBinner(pos[1]))
	
	return state
Exemple #3
0
def goodBadGhostCapsuleDistances(self,observedState):
	pacmanPosition = observedState.getPacmanPosition()
	goodGhost = classifyGhosts.getNearestGoodGhost(observedState, self.distancer)
	badGhost = classifyGhosts.getNearestBadGhost(observedState, self.distancer)
	capsule = classifyCapsule.closest(observedState, self.distancer)

	distBinner = xbinner( \
		(0,math.sqrt(observedState.layout.width**2 + observedState.layout.width**2)), \
		goodBadGhostCapsuleDistances.buckets )

	goodGhostDistance = distBinner(self.distancer.getDistance(pacmanPosition, goodGhost))
	badGhostDistance = distBinner(self.distancer.getDistance(pacmanPosition, badGhost))
	capsuleDistance = distBinner(self.distancer.getDistance(pacmanPosition, capsule))
	hasCapsule = observedState.scaredGhostPresent()
	return (goodGhostDistance,badGhostDistance,capsuleDistance,int(hasCapsule))
Exemple #4
0
def localNeighborhood(self, observedState):
	radius = 4
	pacmanPosition = observedState.getPacmanPosition()

	xBinner = xbinner( (pacmanPosition[0]-radius, pacmanPosition[0]+radius), localNeighborhood.buckets )
	yBinner = xbinner( (pacmanPosition[1]-radius, pacmanPosition[1]+radius), localNeighborhood.buckets )

	goodGhost = classifyGhosts.getNearestGoodGhost(observedState, self.distancer)
	badGhost = classifyGhosts.getNearestBadGhost(observedState, self.distancer)
	capsule = classifyCapsule.closest(observedState, self.distancer)
	hasCapsule = observedState.scaredGhostPresent()


	print pacmanPosition, goodGhost, badGhost, capsule, hasCapsule

	# bin the x/y position for each object of interest 
	b = []
	for p in [goodGhost, badGhost, capsule]:
		b += [xBinner(p[0]), yBinner(p[1])]
	return tuple(b + [int(hasCapsule)])