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
def __init__(self, first_observations: Observations): player_y, player_x = (first_observations.minimap().player_relative() == _PLAYER_SELF).nonzero() self.base_top_left = player_y.mean() <= 31 unit_type = first_observations.screen().unit_type() self.unit_type_ids = UnitTypeIds() self.cc_y, self.cc_x = ( unit_type == self.unit_type_ids.terran_command_center()).nonzero()
def minimap_four_squares(self, observations: Observations, location: Location) -> []: hot_squares = np.zeros(4) enemy_y, enemy_x = (observations.minimap().player_relative() == _PLAYER_ENEMY).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] return hot_squares
def _enemy_position_on_minimap(self, observations: Observations) -> []: return (observations.minimap().player_relative() == _PLAYER_ENEMY ).nonzero()