コード例 #1
0
    def blink_attack_earth(unit):
        if not gc.is_blink_ready(unit.id):
            return
        if bc.ResearchInfo().get_level(bc.UnitType.Mage) < 4:
            return

        location = unit.location

        possible_targets = sense_nearby_units_by_team(location.map_location(),
                                                      2, enemy_team)
        if len(possible_targets) > 2:
            return

        for guess in range(NUMBER_OF_GUESSES):
            i = random.randint(0, earthHeight - 1)
            j = random.randint(0, earthWidth - 1)

            try:
                temp_location = bc.MapLocation(bc.Planet.Earth, i, j)
                if gc.can_blink(unit.id, temp_location):
                    gc.blink(unit.id, temp_location)
                    return

            except Exception as e:
                print('Error:', e)
                # use this to show where the error was
                traceback.print_exc()
コード例 #2
0
    def javelin_attack(unit):
        if not gc.is_javelin_ready(unit.id):
            return
        if bc.ResearchInfo().get_level(bc.UnitType.Knight) < 3:
            return

        location = unit.location

        possible_targets = sense_nearby_units_by_team(location.map_location(),
                                                      unit.ability_range(),
                                                      enemy_team)
        for other in possible_targets:
            if gc.can_javelin(unit.id, other.id):
                gc.javelin(unit.id, other.id)
                return
コード例 #3
0
    def overcharge_attack(unit):
        if not gc.is_overcharge_ready(unit.id):
            return
        if bc.ResearchInfo().get_level(bc.UnitType.Healer) < 3:
            return

        location = unit.location

        possible_targets = sense_nearby_units_by_team(location.map_location(),
                                                      unit.ability_range(),
                                                      my_team)
        for other in possible_targets:
            if gc.can_heal(unit.id, other.id):
                gc.heal(unit.id, other.id)
                return
コード例 #4
0
def Healer_overcharge(unit):
    global my_team
    #if we can't overcharge, exit
    if not gc.is_overcharge_ready(unit.id):
        return

    #cannot overcharge if not at research level 3
    if bc.ResearchInfo().get_level(bc.UnitType.Healer) < 3:
        return

    #find our location
    location = unit.location

    #get all possible targets around, and choose one to heal
    possible_targets = sense_nearby_units_by_team(location.map_location(),
                                                  unit.ability_range(),
                                                  my_team)
    for other in possible_targets:
        if gc.can_heal(unit.id, other.id):
            gc.heal(unit.id, other.id)
            return
コード例 #5
0
    def snipe_attack_earth(unit):
        if unit.ranger_is_sniping():
            return
        if not gc.is_begin_snipe_ready(unit.id):
            return
        if bc.ResearchInfo().get_level(bc.UnitType.Ranger) < 3:
            return

        location = unit.location

        possible_targets = sense_nearby_units_by_type(location.map_location(),
                                                      unit.ability_range(),
                                                      bc.UnitType.Rocket)
        for other in possible_targets:
            if gc.can_begin_snipe(unit.id, other.location.map_location()):
                gc.begin_snipe(unit.id, other.location.map_location())
                return

        possible_targets = sense_nearby_units_by_type(location.map_location(),
                                                      unit.ability_range(),
                                                      bc.UnitType.Factory)
        for other in possible_targets:
            if gc.can_begin_snipe(unit.id, other.location.map_location()):
                gc.begin_snipe(unit.id, other.location.map_location())
                return

        for guess in range(NUMBER_OF_GUESSES):
            i = random.randint(0, earthHeight - 1)
            j = random.randint(0, earthWidth - 1)

            try:
                temp_location = bc.MapLocation(bc.Planet.Earth, i, j)
                if gc.can_begin_snipe(unit.id, temp_location):
                    gc.begin_snipe(unit.id, temp_location)
                    return

            except Exception as e:
                print('Error:', e)
                # use this to show where the error was
                traceback.print_exc()
コード例 #6
0
    def snipe_attack_mars(unit):
        if unit.ranger_is_sniping():
            return
        if not gc.is_begin_snipe_ready(unit.id):
            return
        if bc.ResearchInfo().get_level(bc.UnitType.Ranger) < 3:
            return

        for guess in range(NUMBER_OF_GUESSES):
            i = random.randint(0, marsHeight - 1)
            j = random.randint(0, marsWidth - 1)

            try:
                temp_location = bc.MapLocation(bc.Planet.Mars, i, j)
                if gc.can_begin_snipe(unit.id, temp_location):
                    gc.begin_snipe(unit.id, temp_location)
                    return

            except Exception as e:
                print('Error:', e)
                # use this to show where the error was
                traceback.print_exc()
コード例 #7
0
    def __init__(self, gc):
        self.myTeam = gc.team()
        if gc.team() == bc.Team.Red:
            self.enemyTeam = bc.Team.Blue
        else: 
            self.enemyTeam = bc.Team.Red 
        
        self.factoryCount = self.workerCount = self.knightCount = self.rangerCount = 0
        self.mageCount = self.healerCount = self.rocketCount = 0
        self.earthFactoryCount = self.earthWorkerCount = self.earthKnightCount = self.earthRangerCount = 0
        self.earthMageCount = self.earthHealerCount = self.earthRocketCount = 0
        self.marsFactoryCount = self.marsWorkerCount = self.marsKnightCount = self.marsRangerCount = 0
        self.marsMageCount = self.marsHealerCount = self.marsRocketCount = 0

        self.earthVisibleEnemyUnitsLocation = []
        self.marsVisibleEnemyUnitsLocation = []

        self.earthFriendlyUnitsLocation = []
        self.marsFriendlyUnitsLocation = []

        self.earthFriendlyWoundedUnitsLocation = []
        self.marsFriendlyWoundedUnitsLocation = []

        self.Research = bc.ResearchInfo()

        for unit in gc.my_units():
            loc = unit.location
            if loc.is_on_map():
                if unit.location.is_on_planet(bc.Planet.Earth):
                    self.earthFriendlyUnitsLocation.append(loc.map_location())
                    if unit.health < unit.max_health:
                        self.earthFriendlyWoundedUnitsLocation.append(loc.map_location())
                elif unit.location.is_on_planet(bc.Planet.Mars):
                    self.marsFriendlyUnitsLocation.append(unit.location.map_location())
                    if unit.health < unit.max_health:
                        self.marsFriendlyWoundedUnitsLocation.append(unit.location.map_location())

            if (unit.unit_type == bc.UnitType.Factory):
                self.factoryCount += 1
                if unit.location.is_on_planet(bc.Planet.Earth):
                    self.earthFactoryCount += 1
                elif unit.location.is_on_planet(bc.Planet.Mars):
                    self.marsFactoryCount += 1
            elif (unit.unit_type == bc.UnitType.Worker):
                self.workerCount += 1
                if unit.location.is_on_planet(bc.Planet.Earth):
                    self.earthWorkerCount += 1
                elif unit.location.is_on_planet(bc.Planet.Mars):
                    self.marsWorkerCount += 1
            elif (unit.unit_type == bc.UnitType.Knight):
                self.knightCount += 1
                if unit.location.is_on_planet(bc.Planet.Earth):
                    self.earthKnightCount += 1
                elif unit.location.is_on_planet(bc.Planet.Mars):
                    self.marsKnightCount += 1
            elif (unit.unit_type == bc.UnitType.Ranger):
                self.rangerCount += 1
                if unit.location.is_on_planet(bc.Planet.Earth):
                    self.earthKnightCount += 1
                elif unit.location.is_on_planet(bc.Planet.Mars):
                    self.marsKnightCount += 1
            elif (unit.unit_type == bc.UnitType.Mage):
                self.mageCount += 1
                if unit.location.is_on_planet(bc.Planet.Earth):
                    self.earthMageCount += 1
                elif unit.location.is_on_planet(bc.Planet.Mars):
                    self.marsMageCount += 1
            elif (unit.unit_type == bc.UnitType.Healer):
                self.healerCount += 1
                if unit.location.is_on_planet(bc.Planet.Earth):
                    self.earthHealerCount += 1
                elif unit.location.is_on_planet(bc.Planet.Mars):
                    self.marsHealerCount += 1
            elif (unit.unit_type == bc.UnitType.Rocket):
                self.rocketCount += 1
                if unit.location.is_on_planet(bc.Planet.Earth):
                    self.earthRocketCount += 1
                elif unit.location.is_on_planet(bc.Planet.Mars):
                    self.marsRocketCount += 1

            
            if(unit.location.is_on_map() and unit.location.is_on_planet(bc.Planet.Earth)):
                for enemyUnit in gc.sense_nearby_units_by_team(unit.location.map_location(), unit.vision_range, self.enemyTeam):
                    loc = enemyUnit.location                    
                    if loc.is_on_map():
                        self.earthVisibleEnemyUnitsLocation.append(loc.map_location())
            if(unit.location.is_on_map() and unit.location.is_on_planet(bc.Planet.Mars)):
                for enemyUnit in gc.sense_nearby_units_by_team(unit.location.map_location(), unit.vision_range, self.enemyTeam):
                    loc = enemyUnit.location                    
                    if loc.is_on_map():
                        self.marsVisibleEnemyUnitsLocation.append(loc.map_location())


        self.totalCount = len(gc.my_units())
        self.totalArmyCount = self.totalCount - self.workerCount

        self.totalEarthCount = self.earthFactoryCount + self.earthWorkerCount + self.earthKnightCount + self.earthRangerCount + self.earthMageCount + self.earthHealerCount + self.earthRocketCount
        self.totalEarthArmyCount = self.totalEarthCount - self.earthWorkerCount
        self.totalMarsCount = self.marsFactoryCount + self.marsWorkerCount + self.marsKnightCount + self.marsRangerCount + self.marsMageCount + self.marsHealerCount + self.marsRocketCount
        self.totalmMrsArmyCount = self.totalMarsCount - self.marsWorkerCount