Beispiel #1
0
def rangerMap(planetMap, atkRange):
    enemies = senseAllEnemies(planetMap.planet)
    enemyLocs = []
    if enemies:
        for e in enemies:
            loc = e.location.map_location()
            enemyLocs.append([dmap.flattenXY(loc.x, loc.y), 0])
    # If we can't see any enemies head towards where we last saw them. currently only remembers factory locations
    elif ENEMY_LOCATION_MEMORY:
        for loc in ENEMY_LOCATION_MEMORY:
            enemyLocs.append([loc, 0])
    # find distances to enemy, ignoring walls, because rangers can shoot over
    distMap = dmap.dijkstraMap(enemyLocs, NO_WALL_GRAPH)

    goalLocs = []

    realAtkRange = int(math.sqrt(atkRange / 2))
    # now find where the distance is right for rangers
    for idx, value in enumerate(distMap):
        if value == realAtkRange:
            goalLocs.append([idx, 0])

    # now pathfind to those sweet spot
    rangerMap = dmap.dijkstraMap(goalLocs, WALL_GRAPH)

    return rangerMap
Beispiel #2
0
def enemyAttackMap(planetMap):
    eList  = []
    for e in senseAllEnemies(planetMap.planet):
        loc = e.location.map_location()
        if e.unit_type == bc.UnitType.Ranger or e.unit_type == bc.UnitType.Knight or e.unit_type == bc.UnitType.Mage:
            eList.append([dmap.flattenXY(loc.x,loc.y),-int(math.sqrt(e.attack_range()/2))])
    return dmap.dijkstraMap(eList,NO_WALL_GRAPH)
Beispiel #3
0
def updateKarbonite():
    global TOTAL_KARBONITE
    KARBONITE_LOCS[:] = [k for k in KARBONITE_LOCS if
                         not gc.can_sense_location(MapLocationFlat(THIS_PLANETMAP.planet,k[0]))
                         or gc.karbonite_at(MapLocationFlat(THIS_PLANETMAP.planet,k[0]))]
    for k in KARBONITE_LOCS:
        TOTAL_KARBONITE += k[1]
    return dmap.dijkstraMap(KARBONITE_LOCS, WATER_GRAPH)
Beispiel #4
0
def adjacentToMap(mapLocs):
    goals = []
    for loc in mapLocs:
        adjacent = gc.all_locations_within(loc, 2)
        for adjLoc in adjacent:
            flatxy = dmap.flattenXY(adjLoc.x, adjLoc.y)
            if not flatxy in THIS_PLANET_WALLS and gc.is_occupiable(adjLoc):
                goals.append([flatxy, 0])
    return dmap.dijkstraMap(goals, WALL_GRAPH)
Beispiel #5
0
def mapToEnemy(planetMap):
    s = time.time()
    enemies = senseAllEnemies(planetMap.planet)
    enemyLocs = []
    for e in enemies:
        loc = e.location.map_location()
        enemyLocs.append([dmap.flattenMapLoc(loc), 0])
    if not enemies:
        for loc in ENEMY_LOCATION_MEMORY:
            enemyLocs.append([loc, 0])
    m = dmap.dijkstraMap(enemyLocs, WALL_GRAPH)
    # print('\n'.join([''.join(['{:4}'.format(item) for item in row])for row in m]))
    # print("build enemy map took " + str(time.time()-s))
    return m
Beispiel #6
0
def fleeMap(enemyAttackMap):
    goalLocs = []
    for idx, cell in enumerate(enemyAttackMap):
        if cell < 0 and not (idx in THIS_PLANET_WALLS):
            goalLocs.append([idx, cell])
    return dmap.dijkstraMap(goalLocs, WALL_GRAPH)
Beispiel #7
0
            # Healer map. Directs healers to get near rangers to heal them
            HEALER_MAP = []
            if healers:
                healerMapBench.start()
                goals = []
                for seq in [mages, rangers, knights, workers, healers]:
                    for ally in seq:
                        if ally.health < ally.max_health and ally.location.is_on_map(
                        ):
                            loc = ally.location.map_location()
                            goals.append([
                                dmap.flattenXY(loc.x, loc.y),
                                int((ally.health - ally.max_health) / 10)
                            ])
                HEALER_MAP = dmap.dijkstraMap(goals, WALL_GRAPH)
                healerMapBench.end()

            # refresh blueprint map
            BLUEPRINT_MAP = []
            if allBlueprints:
                factoryMapBench.start()
                blueprintLocs = [
                    f.location.map_location() for f in allBlueprints
                ]
                BLUEPRINT_MAP = adjacentToMap(blueprintLocs)
                factoryMapBench.end()

            rocketMapBench.start()
            # refresh rocket map
            ROCKET_MAP = []
Beispiel #8
0
            RANGER_MAP = []
            if rangers:
                rangerMapBench.start()
                RANGER_MAP = rangerMap(THIS_PLANETMAP, rangerAtkRange)
                rangerMapBench.end()

            # Healer map. Directs healers to get near rangers to heal them
            HEALER_MAP = []
            if healers:
                healerMapBench.start()
                goals = []
                for ally in rangers:
                    if ally.health < ally.max_health and ally.location.is_on_map():
                        loc = ally.location.map_location()
                        goals.append([dmap.flattenXY(loc.x,loc.y), int((ally.health - ally.max_health)/10)])
                HEALER_MAP = dmap.dijkstraMap(goals, WALL_GRAPH)
                healerMapBench.end()

            # refresh blueprint map
            BLUEPRINT_MAP = []
            if allBlueprints:
                factoryMapBench.start()
                blueprintLocs = [f.location.map_location() for f in allBlueprints]
                BLUEPRINT_MAP = adjacentToMap(blueprintLocs)
                factoryMapBench.end()

            rocketMapBench.start()
            # refresh rocket map
            ROCKET_MAP = []
            if rockets:
                rocketlocs = [f.location.map_location() for f in rockets if len(f.structure_garrison())<f.structure_max_capacity()]