MDP Agents 2
MDP Agents 2
py
# parsons/20-nov-2017
# Version 1
# http://ai.berkeley.edu/
# Licensing Information: You are free to use or extend these projects for
# solutions, (2) you retain this notice, and (3) you provide clear
# Student side autograding was added by Brad Miller, Nick Hay, and
# pacmanAgents.py
import api
import random
import game
import util
rewardCapsule = 50
rewardEdibleGhost = 100
rewardGhost = -1000
dangerzone = 3
danger = 200
iterations = 50
class MDPAgent(Agent):
def __init__(self):
name = "Pacman"
self.map = None
self.walls = None
self.corners = None
self.height = self.width = None
self.values = {}
self.policy = {}
print api.whereAmI(state)
self.walls = api.walls(state)
self.corners = api.corners(state)
self.width = state.getWalls().width
self.height = state.getWalls().height
self.map = self.initial_map()
if Directions.NORTH == action:
return current_position
def initial_map(self):
PakMap = [
for j in range(self.height)
for i in range(self.width)
return PakMap
#def printValues(self):
# row = []
# if value is None:
# else:
# print " ".join(row) # Combine all entries in the row into a string
for _ in range(iterations):
new_values = self.values.copy()
for x in range(self.width):
for y in range(self.height):
self.values = new_values
max_value = float('-inf')
return max_value
closestGhost = None
closestGhostDist = float('inf')
closestEdibleGhost = None
closestEdibleGhostDist = float('inf')
if not is_edible:
closestGhostDist = dist
closestGhost = g
else:
closestEdibleGhostDist = dist
closestEdibleGhost = g
_rewardGhost = 0
else:
_rewardEdibleGhost = 0
_rewardEdibleGhost = rewardEdibleGhost
*(1.5/(closestEdibleGhostDist + 1))
reward = rewardEmptyLocation
if position in api.food(state):
reward = rewardFood
else:
reward = rewardCapsule
self.valueIteration(state)
best_action = None
max_value = float('-inf')
pacman = api.whereAmI(state)
legal = api.legalActions(state)
if Directions.STOP in legal:
legal.remove(Directions.STOP)
max_value = value
best_action = action
self.policy[state] = best_action
#self.printValues()
#raw_input("Press Enter")