Пример #1
0
def traverseMapDown(loc, grid):
    smallestLocs = [loc]
    smallest = grid[loc]
    adjacents = dmap.adjacentInBounds(loc)
    for adj in adjacents:
        if grid[adj] <= smallest and (adj in factoryLocs or gc.is_occupiable(
                MapLocationFlat(THIS_PLANETMAP.planet, adj))):
            if grid[adj] == smallest:
                # if it is equally small just append this loc
                smallestLocs.append(adj)
            else:
                # it set a new bar for smallest, set the smallest value and reset smallestLocs
                smallest = grid[adj]
                smallestLocs = [adj]
    # of all the good choices, pick a random one
    randloc = random.choice(smallestLocs)
    return randloc
Пример #2
0
def walkUpMap(unit, grid):
    unit_maploc = unit.location.map_location()
    loc = dmap.flattenMapLoc(unit_maploc)
    largestLocs = [loc]
    largest = grid[loc]
    adjacents = dmap.adjacentInBounds(loc)
    for adj in adjacents:
        if grid[adj] >= largest and gc.is_occupiable(MapLocationFlat(unit_maploc.planet, adj)):
            if grid[adj] == largest:
                # if it is equally small just append this loc
                largestLocs.append(adj)
            else:
                # it set a new bar for largest, set the largest value and reset largestLocs
                largest = grid[adj]
                largestLocs = [adj]
    # of all the good choices, pick a random one
    randloc = random.choice(largestLocs)
    tryMove(unit, unit_maploc.direction_to(MapLocationFlat(unit_maploc.planet,randloc)))
Пример #3
0
def downMapDir(unit,grid):
    unit_maploc = unit.location.map_location()
    loc = dmap.flattenMapLoc(unit_maploc)
    smallestLocs = [loc]
    smallest = grid[loc]
    adjacents = dmap.adjacentInBounds(loc)
    for adj in adjacents:
        if grid[adj] <= smallest and gc.is_occupiable(MapLocationFlat(unit_maploc.planet, adj)):
            if grid[adj] == smallest:
                # if it is equally small just append this loc
                smallestLocs.append(adj)
            else:
                # it set a new bar for smallest, set the smallest value and reset smallestLocs
                smallest = grid[adj]
                smallestLocs = [adj]
    # of all the good choices, pick a random one
    randloc = random.choice(smallestLocs)
    return unit_maploc.direction_to(MapLocationFlat(unit_maploc.planet,randloc))