featureExtractors.py
def closestFood(pos, food, walls):
    """
    closestFood -- this is similar to the function that we have
    worked on in the search project; here its all in one place
    """
    fringe = [(pos[0], pos[1], 0)]
    expanded = set()
    while fringe:
        pos_x, pos_y, dist = fringe.pop(0)
        if (pos_x, pos_y) in expanded:
            continue
        expanded.add((pos_x, pos_y))
        # if we find a food at this location then exit
        if food[pos_x][pos_y]:
            return dist
        # otherwise spread out from the location to its neighbours
        nbrs = Actions.getLegalNeighbors((pos_x, pos_y), walls)
        for nbr_x, nbr_y in nbrs:
            fringe.append((nbr_x, nbr_y, dist + 1))
    # no food found
    return None

    closestFood -- this is similar to the function that we have
    worked on in the search project; here its all in one place
    
- this is similar to the function that we have
worked on in the search project; here its all in one place
- this is similar to the function that we have worked on in the search project ; here its all in one place
def closestFood(pos, food, walls):
    fringe = [(pos[0], pos[1], 0)]
    expanded = set()
    while fringe:
        pos_x, pos_y, dist = fringe.pop(0)
        if (pos_x, pos_y) in expanded:
            continue
        expanded.add((pos_x, pos_y))
        if food[pos_x][pos_y]:
            return dist
        nbrs = Actions.getLegalNeighbors((pos_x, pos_y), walls)
        for nbr_x, nbr_y in nbrs:
            fringe.append((nbr_x, nbr_y, dist + 1))
    return None
def closestFood ( pos , food , walls ) : fringe = [ ( pos [ 0 ] , pos [ 1 ] , 0 ) ] expanded = set ( ) while fringe : pos_x , pos_y , dist = fringe . pop ( 0 ) if ( pos_x , pos_y ) in expanded : continue expanded . add ( ( pos_x , pos_y ) ) if food [ pos_x ] [ pos_y ] : return dist nbrs = Actions . getLegalNeighbors ( ( pos_x , pos_y ) , walls ) for nbr_x , nbr_y in nbrs : fringe . append ( ( nbr_x , nbr_y , dist + 1 ) ) return None
closestFood -- this is similar to the function that we have
worked on in the search project; here its all in one place
closestFood -- this is similar to the function that we have worked on in the search project ; here its all in one place
"""
    closestFood -- this is similar to the function that we have
    worked on in the search project; here its all in one place
    """ # if we find a food at this location then exit # otherwise spread out from the location to its neighbours # no food found
pos
food
walls