Professional Documents
Culture Documents
py
###################################################################
# FEATURES #
# STOP: 50 si la accion es STOP. 0 Si es otra cosa. #
# NEAREST_GHOST: MD al fantasma mas Cercano #
# NEAREST_CAPSULE: MD a la capsula mas cercana #
# FOOD: Lista de MDs a las 5 comidas mas cercanas #
# CAPSULE COUNT: # de Capsulas que existen #
# SCORE: Score actual #
# ASUSTADITOS: # de Fantasmas asustados #
###################################################################
features = util.Counter()
# Feature de STOP
features["STOP"] = int(action == Directions.STOP)
x,y = pac_pos
meanghosts=[]
for ghostState in ghostStates:
if ghostState.scaredTimer == 0:
meanghosts.append(ghostState.getPosition())
if (x,y+1) in meanghosts:
features["UP"] = 0
else:
features["UP"] = 1
if (x,y-1) in meanghosts:
features["DOWN"] = 0
else:
features["DOWN"] = 1
if (x+1,y) in meanghosts:
features["RIGHT"] = 0
else:
features["RIGHT"] = 1
if (x-1,y) in meanghosts:
features["LEFT"] = 0
else:
features["LEFT"] = 1
capsules = successor.getCapsules()
state_food = state.getFood()
food = [(x, y) #enlista las posiciones donde hay comida
for x, row in enumerate(state_food)
for y, food in enumerate(row)
if food]
nearest_ghosts = sorted([util.manhattanDistance(pac_pos, i) for i in ghosts])
# Feature de Fantasmita Mas Cercano #a cuanta distancia manhattan esta el
fantasma mas cercano
features["nearest_ghost"] = nearest_ghosts[0]
# Feature de Score
features["score"] = float(state.getScore())/2000
return features
#===========================================================
class LeftTurnAgent(game.Agent): # from pacmanAgents.py
"An agent that turns left at every opportunity"
#================================================================
def enhancedPacmanFeatures(state, action):
###################################################################
# FEATURES #
# STOP: 50 si la accion es STOP. 0 Si es otra cosa. #
# NEAREST_GHOST: MD al fantasma mas Cercano #
# NEAREST_CAPSULE: MD a la capsula mas cercana #
# FOOD: Lista de MDs a las 5 comidas mas cercanas #
# CAPSULE COUNT: # de Capsulas que existen #
# SCORE: Score actual #
# ASUSTADITOS: # de Fantasmas asustados #
###################################################################
features = util.Counter()
# Feature de STOP
features["STOP"] = int(action == Directions.STOP)
x,y = pac_pos
meanghosts=[]
for ghostState in ghostStates:
if ghostState.scaredTimer == 0:
meanghosts.append(ghostState.getPosition())
if (x,y+1) in meanghosts:
features["UP"] = 0
else:
features["UP"] = 1
if (x,y-1) in meanghosts:
features["DOWN"] = 0
else:
features["DOWN"] = 1
if (x+1,y) in meanghosts:
features["RIGHT"] = 0
else:
features["RIGHT"] = 1
if (x-1,y) in meanghosts:
features["LEFT"] = 0
else:
features["LEFT"] = 1
capsules = successor.getCapsules()
state_food = state.getFood()
food = [(x, y) #enlista las posiciones donde hay comida
for x, row in enumerate(state_food)
for y, food in enumerate(row)
if food]
nearest_ghosts = sorted([util.manhattanDistance(pac_pos, i) for i in ghosts])
# Feature de Score
features["score"] = float(state.getScore())/2000
return features