Exemplo n.º 1
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
Exemplo n.º 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)))
Exemplo n.º 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))
Exemplo n.º 4
0
def upMapDir(unit_maploc, grid):
    loc = traverseMapUp(dmap.flattenMapLoc(unit_maploc), grid)
    return unit_maploc.direction_to(MapLocationFlat(unit_maploc.planet, loc))
Exemplo n.º 5
0
factoryLocs = set()


class Strategy(Enum):
    KNIGHT_RUSH = 1
    RANGER_HEALER = 2
    MAGES = 3


# ranger healer by default
STRAT = Strategy.RANGER_HEALER

# DECIDE WHETHER OR NOT TO KNIGHT_RUSH
if (gc.planet() == bc.Planet.Earth):
    for unit in EARTHMAP.initial_units:
        if unit.team == MY_TEAM and ENEMY_MAP[dmap.flattenMapLoc(
                unit.location.map_location())] < 20:
            STRAT = Strategy.KNIGHT_RUSH
            break

# Research according to the strat
manageResearch()

while True:
    ROUND = gc.round()
    # We only support Python 3, which means brackets around print()
    if not TIMING_DISABLED:
        print('pyround:', gc.round(), 'time left:', gc.get_time_left_ms(),
              'ms')
    turnBench.start()

    # frequent try/catches are a good idea
Exemplo n.º 6
0
ROCKET_MAP = []
ID_GO_TO_ROCKET = set()


class Strategy(Enum):
    KNIGHT_RUSH = 1
    RANGER_HEALER = 2
    MAGES = 3

# ranger healer by default
STRAT = Strategy.RANGER_HEALER

# DECIDE WHETHER OR NOT TO KNIGHT_RUSH
if(gc.planet() == bc.Planet.Earth):
    for unit in EARTHMAP.initial_units:
        if unit.team == MY_TEAM and ENEMY_MAP[dmap.flattenMapLoc(unit.location.map_location())] < 15:
            STRAT = Strategy.KNIGHT_RUSH
            break

# Research according to the strat
manageResearch()

while True:
    ROUND = gc.round()
    # We only support Python 3, which means brackets around print()
    if TIMING_DISABLED:
        print('pyround:', gc.round(), 'time left:', gc.get_time_left_ms(), 'ms')
    turnBench.start()

    # frequent try/catches are a good idea
    try:
Exemplo n.º 7
0
                    if enemies:
                        target = enemies[0]
                        targetPriority = UNIT_PRIORITY.index(
                            enemies[0].unit_type)
                        for e in enemies:
                            priorityLevel = UNIT_PRIORITY.index(e.unit_type)
                            if priorityLevel < targetPriority:
                                target = e
                                targetPriority = priorityLevel
                            elif priorityLevel == targetPriority and e.health < target.health:
                                target = e
                        if gc.can_attack(unit.id, target.id):
                            gc.attack(unit.id, target.id)
                if unit.id in ID_GO_TO_ROCKET:
                    walkDownMap(unit, ROCKET_MAP)
                elif unit.health < 170 and ENEMY_RANGE_MAP[dmap.flattenMapLoc(
                        unit.location.map_location())] < 3:
                    walkUpMap(unit, FLEE_MAP)
                else:
                    walkDownMap(unit, RANGER_MAP)
        rangerBench.end()

        healerBench.start()
        for unit in healers:
            # Ranger logic
            if unit.location.is_on_map():
                if gc.is_heal_ready(unit.id):
                    for ally_id in HURT_ALLIES:
                        if gc.can_heal(unit.id, ally_id):
                            gc.heal(unit.id, ally_id)
                            break
                if unit.id in ID_GO_TO_ROCKET: