Example #1
0
    def applyAction(state, action, ghostIndex):

        legal = GhostRules.getLegalActions(state, ghostIndex)
        if action not in legal:
            raise Exception("Illegal ghost action " + str(action))

        ghostState = state.data.agentStates[ghostIndex]
        speed = GhostRules.GHOST_SPEED
        if ghostState.scaredTimer > 0:
            # speed /= 2.0
            pass
        vector = Actions.directionToVector(action, speed)
        ghostState.configuration = ghostState.configuration.generateSuccessor(
            vector)
Example #2
0
    def applyAction(state, action, pacmanIndex):
        """
        Edits the state to reflect the results of the action.
        """
        legal = PacmanRules.getLegalActions(state, pacmanIndex)
        if action not in legal:
            raise Exception("Illegal action " + str(action))

        pacmanState = state.data.agentStates[0]

        # Update Configuration
        vector = Actions.directionToVector(action, PacmanRules.PACMAN_SPEED)
        pacmanState.configuration = pacmanState.configuration.generateSuccessor(
            vector)

        # Eat
        next = pacmanState.configuration.getPosition()
        nearest = nearestPoint(next)
        if manhattanDistance(nearest, next) <= 0.5:
            # Remove food
            PacmanRules.consume(nearest, state)
Example #3
0
def getFeatures(player, state, action):
    features = Counter()
    walls = state.layout.walls
    food = state.layout.food
    features['bias'] = 1.0
    x, y = player.pos
    dx, dy = Actions.directionToVector(action)
    next_x, next_y = int(x + dx), int(y + dy)
    ghosts = state.aliveGhosts()
    features['1-step-away-capsules'] = sum(
        (next_x, next_y) in Actions.getLegalNeighbors(c, walls)
        for c in state.capsules)

    features['1-step-away-ghosts'] = sum(
        (next_x, next_y) in Actions.getLegalNeighbors(g.pos, walls)
        for g in ghosts)
    if not features["1-step-away-ghosts"] and food[next_x][next_y]:
        features["eats-food"] = 1.0

    ghosts = state.aliveGhosts()

    if player.super > 0:
        features['super'] = 1.0
    nearestGhost = None
    minG = 1e10
    for g in ghosts:
        d = util.manhattanDistance(g.pos, player.pos)
        if minG > d:
            minG = d
            nearestGhost = g

    features['nearest-ghost'] = float(minG) / (walls.width * walls.height)

    dist = closestFood(player.pos, food, walls)
    if dist is not None:
        features["closest-food"] = float(dist) / (walls.width * walls.height)

    features.divideAll(10.0)
    return features