Пример #1
0
def spy_raports_to_attack(spy_reports,
                          max_attacks,
                          useHeavyTransporters=False):
    threats = [
        'LightFighter', 'HeavyFighter', 'Cruiser', 'Battleship',
        'LightTransport', 'HeavyTransport', 'ColonizationShip', 'Dreadnought',
        'Bomber', 'Destroyer', 'DeathStar', 'Recycler', 'SpyProbe',
        'RocketLauncher', 'LightLaserCannon', 'HeavyLaserCannon',
        'GaussCannon', 'IonCannon', 'PlasmaLauncher', 'SmallPlanetaryShield',
        'LargePlanetaryShield', 'AntiMissile', 'InterplanetaryMissile'
    ]

    number_of_reports = len(spy_reports)
    potential_targets = list()

    # search for defensless targets
    for i in range(0, len(spy_reports)):
        defensless = True
        for j in threats:
            if spy_reports[i].get(j) > 0:
                defensless = False
                break
        if defensless:
            potential_targets.append(spy_reports[i])

    # search for best profit targets
    profit_list = list()
    for i in range(0, len(potential_targets)):
        profit = potential_targets[i].get("metal")
        profit += potential_targets[i].get("crystal")
        profit += potential_targets[i].get("deuter")
        profit_list.append((profit, i))

    profit_list.sort(key=lambda profit: profit[0], reverse=True)

    result = list()

    for i in range(0, len(profit_list)):
        if i + 1 > max_attacks:
            break
        attack_fleet = Fleet()
        if useHeavyTransporters:
            attack_fleet.set("HeavyTransport", int(profit_list[i][0] / 50000))
        else:
            attack_fleet.set("LightTransport", int(profit_list[i][0] / 10000))
        target_planet = potential_targets[profit_list[i][1]]
        result.append(Order("attack", attack_fleet, target_planet))

    return result
    def Colonize(self,radius,startingPlanet):
        """

        :param radius: Int
        :param startingPlanet: object PlanetState with coordinates
        :return: Bool if colonized True if failed to colonize: False
        """

        self.bot.setScope('galaxy')
        WebDriverWait(self.browser, 10).until(
            EC.presence_of_all_elements_located((By.XPATH, "//*[@id='colonized']")))
        if radius+startingPlanet.get('Star')>499:
            radius=499-startingPlanet.get('Star')
        if -radius+startingPlanet.get('Star')<1:
            radius=startingPlanet.get('Star')-1

        counter = 0
        for j in range (-radius,radius):
            self.GoToSystem(startingPlanet.get('Galaxy'), startingPlanet.get('Star')-radius+counter)
            for i in range(1, 15):

                name = self.browser.find_element(By.XPATH, '//*[@id="galaxytable"]/tbody/tr[' + str(i) + ']/td[3]').text
                print(name)
                if name=='' and i>5 and i<10:
                    colonizationFleet = Fleet()
                    planet = PlanetState()
                    colonizationFleet.set('ColonizationShip',1)
                    colonizationFleet.set('Mission','Colonize')
                    planet.set('Galaxy', startingPlanet.get('Galaxy'))
                    planet.set('Star', startingPlanet.get('Star') + counter)
                    planet.set('Planet', i)
                    print('found planet')

                    print('sending fleet')
                    self.bot.sendFleet(colonizationFleet,planet)
                    return True
                else:
                    i = i+1



            self.GoToSystem(startingPlanet.get('Galaxy'), startingPlanet.get('Star')+radius  - counter)
            for i in range(1, 15):

                name = self.browser.find_element(By.XPATH, '//*[@id="galaxytable"]/tbody/tr[' + str(i) + ']/td[3]').text
                print(name)
                if i>5 and i<10 and name=='':
                    colonizationFleet = Fleet()
                    planet = PlanetState()
                    colonizationFleet.set('ColonizationShip',1)
                    colonizationFleet.set('Mission','Colonize')
                    planet.set('Galaxy', startingPlanet.get('Galaxy'))
                    planet.set('Star', startingPlanet.get('Star') +radius-counter)
                    planet.set('Planet', i)
                    print('found planet')

                    print('sending fleet')
                    self.bot.sendFleet(colonizationFleet,planet)
                    return True
                else:
                    i = i+1



            counter += 1
        print('failed')
        return False