Esempio n. 1
0
def highScoreEvaluationFunction(current):
    """
    * if there are any capsules left, move towards them
    * if we are out of capsules, gather remaining food
    * Try _really_ hard to get a scared ghost if we can
    * if there is a chance of death, don't risk it
    """
    pacman    = current.getPacmanPosition()
    foods     = current.getFood()
    walls     = current.getWalls()
    ghosts    = current.getGhostStates()
    distance  = util.manhattanDistance
    capsules  = current.getCapsules()
    score     = current.getScore()

    if len(capsules) > 0:
          score += 5 * (1.0 / any_capsule_find(current))
    else: score += 1 * (1.0 / any_food_find(current))
        
    max_scared = 0 
    for ghost in ghosts:
        gp = ghost.getPosition()
        gt = ghost.scaredTimer
         
        if gt > 0:
            distance = specific_find(current, pacman, gp)
            if gt >= distance:
                value = 200 * (1.0 / distance)
                max_scared = max(max_scared, value)
        elif pacman == gp: score = -1000
     
    return score + max_scared
Esempio n. 2
0
def betterEvaluationFunction(current):
    """
    * if there are any capsules left, lets really move towards
      the closest one.
    * If there is food left, try to move to the closest
    * For each ghost
      - if they are scared and nearby, chase them
      - otherwise never be in the same position as them
    """
    pacman    = current.getPacmanPosition()
    foods     = current.getFood()
    walls     = current.getWalls()
    ghosts    = current.getGhostStates()
    distance  = util.manhattanDistance
    capsules  = current.getCapsules()
    score     = current.getScore()

    if len(capsules) > 0:
        mcaps  = min(specific_find(current, pacman, c) for c in capsules)
        score += 20 if mcaps == 0 else 5 * math.ceil(1.0 / mcaps)
       
#    if foods.count() > 0:
#        dfood  = [distance(f, pacman) for f in foods.asList()]
#        mfood  = min(dfood)
#        cfood  = sum(1.0 for f in dfood if f == mfood)
#        score += 1.0 / mfood
    score += 1.0 / any_food_find(current)
        
    for ghost in ghosts:
        gp = ghost.getPosition()
        gd = distance(gp, pacman)
        gt = ghost.scaredTimer
        
        if gt != 0 and gd <= gt: score += 200
        elif pacman == gp: score -= 500
    
    return score