Exemplo n.º 1
0
 def _extra_supply_depots(self, observations: Observations) -> Order:
     counter = BuildingCounter()
     expectMore = 8 > counter.supply_depots_count(observations)
     supplyAlmostFull = observations.player().food_cap(
     ) - observations.player().food_used() <= 2
     if expectMore and supplyAlmostFull:
         return BuildSupplyDepot(self.location)
     else:
         return NoOrder()
Exemplo n.º 2
0
 def missing_supply_depot(self, observations: Observations,
                          counter: BuildingCounter) -> bool:
     expectMore = self.expected_supply_depot > counter.supply_depots_count(
         observations)
     supplyAlmostFull = observations.player().food_cap(
     ) - observations.player().food_used() <= 4
     buildingOne = isinstance(self.current_order, BuildSupplyDepot)
     # but still build several in a row, needs to detect if a supply building is in progress
     return expectMore and supplyAlmostFull and not buildingOne
Exemplo n.º 3
0
 def execute(self, observations: Observations) -> actions.FunctionCall:
     if not self.scv_selected:
         unit_type = observations.screen().unit_type()
         unit_y, unit_x = (
             unit_type == self.unit_type_ids.terran_scv()).nonzero()
         rand_unit_index = random.randint(0, len(unit_y) - 1)
         target = [unit_x[rand_unit_index], unit_y[rand_unit_index]]
         self.scv_selected = True
         return self.actions.select_point(target)
     elif not self.scv_moved and self.action_ids.move_minimap(
     ) in observations.available_actions():
         unit_y, unit_x = self.other_bases_minimap_locations.pop(0)
         target = [unit_x, unit_y]
         self.scv_moved = True
         return self.actions.move_minimap(target)
     elif self.scv_moved and observations.player().idle_worker_count(
     ) > 0 and len(self.other_bases_minimap_locations) > 0:
         self.scv_moved = False
         return self.actions.select_idle_worker()
     elif self.infinite_scouting and len(
             self.other_bases_minimap_locations) == 0:
         self.other_bases_minimap_locations = self.base_location.other_unknown_bases_locations_on_minimap(
         )
     elif not self.scv_back_to_base and len(
             self.other_bases_minimap_locations) == 0:
         unit_y, unit_x = self.base_location.base_location_on_minimap()
         target = [unit_x, unit_y]
         self.scv_back_to_base = True
         return self.actions.move_minimap(target)
     return self.actions.no_op()
Exemplo n.º 4
0
    def build_state(self, location: Location, observations: Observations) -> []:
        unit_type = observations.screen().unit_type()
        unit_type_ids = UnitTypeIds()
        cc_y, cc_x = (unit_type == unit_type_ids.terran_command_center()).nonzero()
        cc_count = 1 if cc_y.any() else 0
        depot_y, depot_x = (unit_type == unit_type_ids.terran_supply_depot()).nonzero()
        supply_depot_count = int(round(len(depot_y) / 69))
        barracks_y, barracks_x = (unit_type == unit_type_ids.terran_barracks()).nonzero()
        barracks_count = int(round(len(barracks_y) / 137))

        current_state = np.zeros(8)
        current_state[0] = cc_count
        current_state[1] = supply_depot_count
        current_state[2] = barracks_count
        current_state[3] = observations.player().food_army()

        hot_squares = np.zeros(4)
        enemy_y, enemy_x = (observations.minimap().player_relative() == _PLAYER_HOSTILE).nonzero()
        for i in range(0, len(enemy_y)):
            y = int(math.ceil((enemy_y[i] + 1) / 32))
            x = int(math.ceil((enemy_x[i] + 1) / 32))
            hot_squares[((y - 1) * 2) + (x - 1)] = 1

        if not location.command_center_is_top_left():
            hot_squares = hot_squares[::-1]

        for i in range(0, 4):
            current_state[i + 4] = hot_squares[i]

        return current_state
Exemplo n.º 5
0
 def execute(self, observations: Observations) -> actions.FunctionCall:
     if not self.scv_selected:
         if observations.player().idle_worker_count() > 0:
             self.scv_selected = True
             return self.actions.select_idle_worker()
         else:
             unit_type = observations.screen().unit_type()
             unit_y, unit_x = (
                 unit_type == self.unit_type_ids.terran_scv()).nonzero()
             rand_unit_index = random.randint(0, len(unit_y) - 1)
             target = [unit_x[rand_unit_index], unit_y[rand_unit_index]]
             self.scv_selected = True
             return self.actions.select_point(target)
     return self.actions.no_op()
Exemplo n.º 6
0
    def build_state(self, location: Location, observations: Observations,
                    enemy_detector: EnemyDetector) -> []:
        counter = BuildingCounter()

        base_state_items_length = 8
        hot_squares_length = 4
        current_state_length = base_state_items_length + hot_squares_length

        current_state = np.zeros(current_state_length)
        current_state[0] = counter.command_center_count(observations)
        current_state[1] = counter.supply_depots_count(observations)
        current_state[2] = counter.barracks_count(observations)
        current_state[3] = counter.factories_count(observations)
        current_state[4] = counter.techlab_barracks_count(observations)
        current_state[5] = counter.reactor_barracks_count(observations)
        current_state[6] = self._enemy_race_id(enemy_detector)
        current_state[7] = observations.player().food_army()

        hot_squares = MinimapEnemyHotSquaresBuilder().minimap_four_squares(
            observations, location)
        for i in range(0, hot_squares_length):
            current_state[i + base_state_items_length] = hot_squares[i]

        return current_state
Exemplo n.º 7
0
 def doable(self, observations: Observations) -> bool:
     return observations.player().minerals() >= 50 and observations.player(
     ).vespene() >= 50
Exemplo n.º 8
0
 def doable(self, observations: Observations) -> bool:
     return observations.player().food_used() < observations.player(
     ).food_cap()
Exemplo n.º 9
0
 def doable(self, observations: Observations) -> bool:
     return observations.player().idle_worker_count() > 0
Exemplo n.º 10
0
 def doable(self, observations: Observations) -> bool:
     return observations.player().minerals() >= 75
Exemplo n.º 11
0
 def done(self, observations: Observations) -> bool:
     return (self.already_trained >= self.amount_trainee)\
            or (observations.player().food_used() == observations.player().food_cap())