def moveToEnemies(self): closestEnemies = self.game.cached_enemies.not_flying.exclude_type( [ADEPTPHASESHIFT]) if closestEnemies: closestEnemy = closestEnemies.closest_to(self.unit) #get the distance to the closest Enemy and if it's in attack range, then don't move. if closestEnemy.distance_to( self.unit.position ) > self.unit.ground_range + self.unit.radius + closestEnemy.radius - 0.05: self.last_target = Point3( (closestEnemy.position3d.x, closestEnemy.position3d.y, (closestEnemy.position3d.z + 1))) if self.checkNewAction('move', closestEnemy.position[0], closestEnemy.position[1]): self.game.combinedActions.append( self.unit.attack(closestEnemy.position)) return True elif _rushmode: startPos = random.choice(self.game.enemy_start_locations) if self.checkNewAction('move', startPos[0], startPos[1]): self.game.combinedActions.append(self.unit.move(startPos)) self.last_target = Point3( (startPos.position.x, startPos.position.y, self.game.getHeight(startPos.position))) self.label = 'Searching for Enemy Base'
def _draw_point_list(self, point_list: List = None, color=None, text=None, box_r=None) -> bool: if not color: color = GREEN h = self.get_terrain_z_height(self.townhalls[0]) for p in point_list: p = Point2(p) pos = Point3((p.x, p.y, h)) if box_r: p0 = Point3( (pos.x - box_r, pos.y - box_r, pos.z + box_r)) + Point2( (0.5, 0.5)) p1 = Point3( (pos.x + box_r, pos.y + box_r, pos.z - box_r)) + Point2( (0.5, 0.5)) self.client.debug_box_out(p0, p1, color=color) if text: self.client.debug_text_world( "\n".join([ f"{text}", ]), pos, color=color, size=30, )
def make_decision(self, game, unit): self.saved_position = unit.position #first line always. self.game = game self.unit = unit self.abilities = self.game.allAbilities.get(self.unit.tag) if self.is_hallucination is None: self.check_hallucination() if self.is_hallucination: self.runHallList() else: self.runList() #debugging info if self.game.debugAllowed: if _debug or self.unit.is_selected: if self.last_target: spos = Point3( (self.unit.position3d.x, self.unit.position3d.y, (self.unit.position3d.z + 1))) self.game._client.debug_line_out(spos, self.last_target, color=Point3( (155, 255, 25))) self.game._client.debug_text_3d(self.label, self.unit.position3d)
def __init__(self, bot_ai, tactics): self.bot = bot_ai self.strategy = None self.target = None self.unit_tags = None self.count = 0 self.count1 = 0 self.tactics = tactics self.state = '' self.shy = 0 self.state1 = 0 self.switch = 0 self.perimeter_radious = 13 self.region_radius = 10 self.searchpoint = None self.state = 0 self.strategic_points = [ Point3((28, 60, 12)), # A Point3((63, 65, 10)), # B Point3((44, 44, 10)), # C Point3((24, 22, 10)), # D Point3((59, 27, 12)), # E ] self.goal_point = [ Point3((37.16, 49.47, 9)), Point3((40.04, 47.29, 9)), Point3((44, 44, 10)), Point3((47.96, 40.71, 9)), Point3((50.83, 38.53, 9.99)), ] self.reaper = [] self.marine = [] self.siege = [] self.pet = 0
def moveToExpansion(self): #get the distance to expansion, if it's more than 1, move to it. #find a mineral patch close to the location and move to it. if not self.nexus_position: #self.nexus_position = self.game.vespene_geyser.closer_than(15.0, self.game.expPos).first self.nexus_position = self.game.expPos if not self.nexus_position: return False dist = self.unit.distance_to(self.nexus_position) if dist > 6.5: if self.checkNewAction('move', self.nexus_position.position.x, self.nexus_position.position.y): self.game.combinedActions.append(self.unit.move(self.nexus_position)) self.last_target = Point3((self.nexus_position.position.x, self.nexus_position.position.y, self.game.getHeight(self.nexus_position.position))) return True elif dist < 5.5: #move away. move_distance = dist - 6 targetpoint = self.unit.position.towards(self.nexus_position, distance=move_distance) if self.checkNewAction('move', targetpoint.position.x, targetpoint.position.y): self.game.combinedActions.append(self.unit.move(targetpoint)) self.last_target = Point3((targetpoint.position.x, targetpoint.position.y, self.game.getHeight(targetpoint.position))) return True return False
def make_decision(self, game, unit): self.game = game self.stalker = unit self.unit = unit self.saved_position = self.unit.position self.abilities = self.game.allAbilities.get(self.unit.tag) self.trackHealth() self.runList() #debugging info if self.game.debugAllowed: if _debug or self.unit.is_selected: if len(self.last_target) > 0: spos = Point3( (self.unit.position3d.x, self.unit.position3d.y, (self.unit.position3d.z + 1))) self.game._client.debug_line_out(spos, self.last_target, color=Point3( (155, 255, 25))) self.game._client.debug_text_3d(self.label, self.unit.position3d)
def __init__(self, bot_ai): self.bot = bot_ai self.our_tags = dict() self.enemy_tags = dict() self.our_total = 0 self.enemy_total = 0 self.our_units = [5, 0, 0, 0, 0] # 맨 처음 마린 5기씩 self.enemy_units = [5, 0, 0, 0, 0] self.unit_turn = (MARINE, MEDIVAC, MARINE, MARAUDER, MARINE, MARAUDER, MARINE, REAPER, MARINE, SIEGETANK) self.enemy_unit_turn = 0 self.our_unit_turn = 0 # A B # C # D E self.strategic_points = [ # x y z Point3((28, 60, 12)), # A Point3((63, 65, 10)), # B Point3((44, 44, 10)), # C Point3((24, 22, 10)), # D Point3((59, 27, 12)), # E ]
def make_decision(self, game, unit): self.saved_position = unit.position #first line always. self.game = game self.unit = unit self.abilities = self.game.allAbilities.get(self.unit.tag) self.bonus_range = 0 self.beam_move_target = None if self.game.buildingList.pulseCrystalsAvail: self.bonus_range = 2 if self.is_hallucination is None: if AbilityId.GRAVITONBEAM_GRAVITONBEAM in self.abilities: self.is_hallucination = False else: self.is_hallucination = True if self.is_hallucination: self.runScout() else: self.runList() if not 'gravitonbeam' in str(self.unit.orders).lower(): self.beam_unit = None #debugging info if _debug or self.unit.is_selected: if self.last_target: spos = Point3((self.unit.position3d.x, self.unit.position3d.y, (self.unit.position3d.z + 1))) self.game._client.debug_line_out(spos, self.last_target, color=Point3((155, 255, 25))) self.game._client.debug_text_3d(self.label, self.unit.position3d)
def _draw_point_list(self, point_list: List = None, color=None, text=None, box_r=None) -> bool: if not color: color = GREEN if not point_list or (not text and not box_r): return True # print("cant draw nothing !") for p in point_list: p = Point2(p) h = self.ai.get_terrain_z_height(p) pos = Point3((p.x, p.y, h)) if box_r: p0 = Point3( (pos.x - box_r, pos.y - box_r, pos.z + box_r)) + Point2( (0.5, 0.5)) p1 = Point3( (pos.x + box_r, pos.y + box_r, pos.z - box_r)) + Point2( (0.5, 0.5)) self.ai.client.debug_box_out(p0, p1, color=color) if text: self.ai.client.debug_text_world( "\n".join([ f"{text}", ]), pos, color=color, size=30, )
def draw_regions(self): labeled_array, num_features = label( self.ai.game_info.placement_grid.data_numpy) for i, row in enumerate(labeled_array): for j, col in enumerate(row): try: text = labeled_array[i][j] if self.ai.game_info.placement_grid.data_numpy[i][j] == 1: p = Point2((i, j)) h = self.ai.get_terrain_z_height(p) pos = Point3((p.x, p.y, h)) # edge_points = [(points[[i, j], 0][1], points[[i, j], 1][0]) for i, j in edges] box_r = 0.2 color = Point3((int(text) * 10, 0, 250)) p0 = Point3((pos.x - box_r, pos.y - box_r, pos.z + box_r)) + Point2((0.5, 0.5)) p1 = Point3((pos.x + box_r, pos.y + box_r, pos.z - box_r)) + Point2((0.5, 0.5)) self.ai.client.debug_box_out(p0, p1, color=color) self.ai.client.debug_text_world( "\n".join([ f"{text}", ]), p, color=color, size=12, ) except Exception as e: pass
def draw_ramps(self): for index, ramp in self.ai.map_manager.cached_ramps.items(): self.ai.map_manager.cached_ramps[index] = ramp p = ramp.coords c0 = None c1 = None line_color = Point3((255, 0, 0)) if p is not None: if len(ramp.expansions) > 1: c0 = ramp.expansions[0].coords.to3 c1 = ramp.expansions[1].coords.to3 color = Point3((0, 255, 0)) h2 = self.ai.get_terrain_z_height(p) pos = Point3((p.x, p.y, h2)) p0 = Point3((pos.x - 1.5, pos.y - 1.5, pos.z + 1.5)) + Point2( (0.5, 0.5)) p1 = Point3((pos.x + 1.5, pos.y + 1.5, pos.z - 1.5)) + Point2( (0.5, 0.5)) if isinstance(c0, Point3) and isinstance(c1, Point3): self.ai.client.debug_line_out(c0, c1, color=line_color) self.ai.client.debug_box_out(p0, p1, color=color) self.ai.client.debug_text_world( "\n".join([ f"{ramp.name}", f"Coords: ({p.position.x:.2f},{p.position.y:.2f})", ]), pos, color=(0, 255, 0), size=12, )
def draw_placement_grid(self, expansion: Expansion): map_area = self.ai.game_info.playable_area for (b, a), value in np.ndenumerate( self.ai.game_info.placement_grid.data_numpy): # skip non placements which are zero if value == 0: continue # Skip values outside of playable map area if not (map_area.x <= a < map_area.x + map_area.width): continue if not (map_area.y <= b < map_area.y + map_area.height): continue p = Point2((a, b)) if expansion.is_in(p): h2 = self.ai.get_terrain_z_height(p) pos = Point3((p.x, p.y, h2)) p0 = Point3( (pos.x - 0.25, pos.y - 0.25, pos.z + 0.25)) + Point2( (0.5, 0.5)) p1 = Point3( (pos.x + 0.25, pos.y + 0.25, pos.z - 0.25)) + Point2( (0.5, 0.5)) color = Point3((0, 255, 0)) self.ai.client.debug_box_out(p0, p1, color=color)
def draw_expansions(self): color = GREEN self.draw_expansion_borders(color) for i, expansion in enumerate(self.ai.map_manager.expansions.values()): # if i%2 == 0: # color = Point3((0, 255, 0)) # else: # color = Point3((255, 0, 0)) p = expansion.coords if isinstance(p, Point2): h2 = self.ai.get_terrain_z_height(p) pos = Point3((p.x, p.y, h2)) p0 = Point3((pos.x - 2, pos.y - 2, pos.z + 2)) + Point2( (0.5, 0.5)) p1 = Point3((pos.x + 2, pos.y + 2, pos.z - 2)) + Point2( (0.5, 0.5)) distance_to_main = p.distance_to( self.ai.start_location.rounded) # if distance_to_main < 18.0: # continue self.ai.client.debug_box_out(p0, p1, color=color) self.ai.client.debug_text_world( "\n".join([ f"{expansion}", f"distance_to_main: {distance_to_main:.2f}", f"Coords: ({p.position.x:.2f},{p.position.y:.2f})", f"Resources: ({len(expansion.resources)})", ]), pos, color=(0, 255, 255), size=8, )
def draw_expansion_borders(self, color: Union[Point3, Tuple]): height_map = self.ai.game_info.terrain_height for expansion in self.ai.map_manager.expansions.values(): height_here = height_map[expansion.coords] main_height = height_map[self.ai.start_location.rounded] natural_height = height_map[ self.ai.main_base_ramp.lower.pop()] # doesnt matter which c = GREEN if expansion.coords.rounded == self.ai.start_location.rounded: c = GREEN elif expansion.coords.rounded.distance_to( self.ai.start_location.rounded) < 33: c = BLUE else: c = RED for p in expansion.borders: p = Point2(p) h2 = self.ai.get_terrain_z_height(p) pos = Point3((p.x, p.y, h2)) p0 = Point3( (pos.x - 0.25, pos.y - 0.25, pos.z + 0.25)) + Point2( (0.5, 0.5)) p1 = Point3( (pos.x + 0.25, pos.y + 0.25, pos.z - 0.25)) + Point2( (0.5, 0.5)) self.ai.client.debug_box_out(p0, p1, color=c) self.ai.client.debug_text_world( f"h:{self.ai.game_info.terrain_height[p]:.2f}", pos, color=RED, size=30, )
async def post_update(self): if self.debug: client: "Client" = self.ai._client if self.zealot_position: x = self.zealot_position.x y = self.zealot_position.y z = self.knowledge.get_z(Point2((x, y))) c1 = Point3((x - 0.25, y - 0.25, z)) c2 = Point3((x + 0.25, y + 0.25, z + 2)) client.debug_box_out(c1, c2) correction = Point2((0, 1)) for x in range(0, self.grid.width - 1): for y in range(0, self.grid.height - 1): cell: GridArea = self.grid.get(x, y) color = None if cell.Area == BuildArea.Building: color = self.grid.building_color elif cell.Area == BuildArea.TownHall: color = self.grid.townhall_color elif cell.Area == BuildArea.Pylon: color = self.grid.pylon_color elif cell.Area == BuildArea.Mineral: color = self.grid.mineral_color elif cell.Area == BuildArea.Gas: color = self.grid.gas_color # elif cell.Area == BuildArea.Empty: # color = self.grid.gas_color if color: z = self.knowledge.get_z(Point2((x, y)) + correction) c1 = Point3((x, y, z)) c2 = Point3((x + 1, y + 1, z + 1)) client.debug_box_out(c1, c2, color)
def make_decision(self, game, unit): self.saved_position = unit.position #first line always. self.game = game self.unit = unit if not self.life_start: self.life_start = self.game.time self.owner = self.find_owner() self.life_left = 2.1 - (self.game.time - self.life_start) self.runList() #debugging info if self.game.debugAllowed: if _debug or self.unit.is_selected: if self.last_target: spos = Point3( (self.unit.position3d.x, self.unit.position3d.y, (self.unit.position3d.z + 1))) self.game._client.debug_line_out(spos, self.last_target, color=Point3( (155, 255, 25))) self.game._client.debug_sphere_out( self.game.turn3d(self.last_target), 1.5, Point3((155, 255, 25))) self.game._client.debug_text_3d( 'TARGET LOC', self.game.turn3d(self.last_target)) self.game._client.debug_text_3d(self.label, self.unit.position3d)
def KeepKiteRange(self): #kite if we can. targetEnemy = self.findKiteTarget() if targetEnemy: kitePoint = self.findKiteBackTarget(targetEnemy) if kitePoint: if AbilityId.MORPH_WARPPRISMTRANSPORTMODE in self.abilities and self.game.can_afford( MORPH_WARPPRISMTRANSPORTMODE): self.game.combinedActions.append( self.unit(AbilityId.MORPH_WARPPRISMTRANSPORTMODE)) return True if self.checkNewAction('move', kitePoint[0], kitePoint[1]): self.game.combinedActions.append(self.unit.move(kitePoint)) if self.unit.is_selected or _debug: self.last_target = kitePoint.position self.game._client.debug_line_out( self.game.unitDebugPos(self.unit), self.game.p3AddZ(targetEnemy.position3d), color=Point3((0, 206, 3))) self.game._client.debug_line_out( self.game.unitDebugPos(self.unit), self.game.p2AddZ(kitePoint), color=Point3((212, 66, 244))) return True return False
def make_decision(self, game, unit): self.saved_position = unit.position #first line always. self.game = game self.unit = unit self.abilities = self.game.allAbilities.get(self.unit.tag) self.label = 'Idle' if not self.shade_start: self.shade_start = self.game.time #find our owner adept. self.owner = self.find_owner() self.emptyTarget = self.findEmptyExpansion() self.getOwnerOrder() self.runList() #debugging info if self.game.debugAllowed: if _debug or self.unit.is_selected: if self.owner: opos = Point3( (self.owner.position3d.x, self.owner.position3d.y, (self.owner.position3d.z + 1))) spos = Point3( (self.unit.position3d.x, self.unit.position3d.y, (self.unit.position3d.z + 1))) self.game._client.debug_line_out(spos, opos, color=Point3( (155, 255, 25))) lb = "{} ||| {}".format(str(self.ownerOrder), self.label) self.game._client.debug_text_3d(lb, self.unit.position3d)
async def step(self): actions = list() # 이 전투그룹에 속한 아군 유닛들 units = self.units() if units.amount == 0 or self.target is None: return actions # 이 전투그룹 근처의 적군 유닛들 enemy = self.bot.known_enemy_units.closer_than(self.perimeter_radious, units.center) for unit in units: if self.tactics == Tactics.NORMAL: actions += await self.normal_step(unit, units, enemy) elif self.tactics == Tactics.FIRST: actions += await self.first_step(unit, units, enemy) if self.bot.debug: # 모든 유닛의 공격목표롤 시각화 if len(unit.orders) > 0: # if unit.type_id == UnitTypeId.MARINE: # embed(); exit() skill = unit.orders[0].ability.id.name target = unit.orders[0].target if type(target) is Point3: self.bot._client.debug_line_out( unit.position3d, target) self.bot._client.debug_text_world(skill, target, size=16) elif type(target) is int: all_units = self.bot.units | self.bot.known_enemy_units target_unit = all_units.find_by_tag(target) if target_unit is not None: target = target_unit.position3d self.bot._client.debug_line_out( unit.position3d, target) self.bot._client.debug_text_world(skill, target, size=16) if self.bot.debug: # 전투그룹의 중심점과 목표지점 시각화 p1 = units.center p2 = self.target.to3 self.bot._client.debug_sphere_out(Point3((p1.x, p1.y, 12)), 5, Point3((0, 255, 0))) self.bot._client.debug_line_out(Point3((p1.x, p1.y, 12)), p2, color=Point3((0, 255, 0))) self.bot._client.debug_sphere_out(self.target.to3, 5, Point3((0, 255, 0))) return actions
def draw_expansions(self): green = Point3((0, 255, 0)) for expansion_pos in self.expansion_locations_list: height = self.get_terrain_z_height(expansion_pos) expansion_pos3 = Point3((*expansion_pos, height)) self._client.debug_box2_out(expansion_pos3, half_vertex_length=2.5, color=green)
def debug(self): """ 지형정보를 게임에서 시각화 """ # 각 지역마다, 내가 점령하고 있는지 아닌지 구의 색상으로 시각화 for occ, point in zip(self.occupied_points(), self.strategic_points): color = Point3((255, 0, 0)) if occ > 0 else Point3((0, 0, 255)) self.bot._client.debug_sphere_out(point, self.region_radius, color)
def draw_vision_blockers(self): for p in self.game_info.vision_blockers: h = self.get_terrain_height(p) h2 = self.terrain_to_z_height(h) pos = Point3((p.x, p.y, h2)) p0 = Point3((pos.x - 0.25, pos.y - 0.25, pos.z)) p1 = Point3((pos.x + 0.25, pos.y + 0.25, pos.z - 0.5)) # print(f"Drawing {p0} to {p1}") self._client.debug_box_out(p0, p1, color=(255, 0, 0))
def _draw_path_box(self, p, color): h = self.get_terrain_z_height(p) pos = Point3((p.x, p.y, h)) box_r = 1 p0 = Point3((pos.x - box_r, pos.y - box_r, pos.z + box_r)) + Point2( (0.5, 0.5)) p1 = Point3((pos.x + box_r, pos.y + box_r, pos.z - box_r)) + Point2( (0.5, 0.5)) self.client.debug_box_out(p0, p1, color=color)
def draw_creep_pixelmap(self): for (y, x), value in np.ndenumerate(self.state.creep.data_numpy): p = Point2((x, y)) h2 = self.get_terrain_z_height(p) pos = Point3((p.x, p.y, h2)) # Red if there is no creep color = Point3((255, 0, 0)) if value == 1: # Green if there is creep color = Point3((0, 255, 0)) self._client.debug_box2_out(pos, half_vertex_length=0.25, color=color)
async def post_update(self): if self.debug: client: "Client" = self.ai._client i = 0 for zone in self.expansion_zones: z = self.knowledge.get_z(zone.center_location) position: Point3 = Point3( (zone.center_location.x, zone.center_location.y, z + 1)) is_gather = i in self.gather_points for unit in zone.our_units: self.debug_text_on_unit(unit, f"Z:{zone.zone_index}") for unit in zone.known_enemy_units: self.debug_text_on_unit(unit, f"Z:{zone.zone_index}") zone_msg = f"Zone {i}" if is_gather: zone_msg += " (Gather)" if zone.is_neutral: zone_msg += ", neutral" if zone.is_ours: zone_msg += ", ours" if zone.is_enemys: zone_msg += ", enemys" if zone.is_under_attack: zone_msg += ", under attack" our_power = round(zone.our_power.power, 1) enemy_power = round(zone.known_enemy_power.power, 1) zone_msg += f"\nPower {str(our_power)} Enemy {str(enemy_power)}" zone_msg += f"\nBalance {zone.power_balance}" client.debug_text_world(zone_msg, position, size=12) i += 1 if zone.is_ours: client.debug_sphere_out(position, zone.radius, Point3((0, 200, 0))) client.debug_sphere_out(position, Zone.ZONE_DANGER_RADIUS, Point3((200, 0, 0))) position = Point3( (zone.gather_point.x, zone.gather_point.y, z + 1)) client.debug_sphere_out(position, 1, Point3((200, 200, 0)))
def __init__(self, bot_ai): self.bot = bot_ai # 자원이 생산되는 주요 전략적 요충지 좌표 # A B # C # D E self.strategic_point = [ # x y Point3((28, 60)), # A Point3((63, 65)), # B Point3((44, 44)), # C Point3((24, 22)), # D Point3((59, 27)), # E ]
def findRecallArmyExp(self, scoreMin): #get the center of our fighting units. possibles = self.game.units.filter( lambda x: not x.is_structure and not x.name in ['Probe'] and (x.can_attack_ground or x.can_attack_air) and x.distance_to( self.unit) >= 30) if len(possibles) > 0: center = possibles.center self.game._client.debug_sphere_out( Point3((center.position.x, center.position.y, self.unit.position3d.z)), 2.5, Point3((66, 69, 244))) #blue #self.game._client.debug_text_3d('P1', Point3((self.p1.position.x, self.p1.position.y, self.unit.position3d.z))) print('center', center) print(len(possibles))
def draw_visibility_pixelmap(self): for (y, x), value in np.ndenumerate(self.state.visibility.data_numpy): p = Point2((x, y)) h2 = self.get_terrain_z_height(p) pos = Point3((p.x, p.y, h2)) p0 = Point3((pos.x - 0.25, pos.y - 0.25, pos.z + 0.25)) + Point2( (0.5, 0.5)) p1 = Point3((pos.x + 0.25, pos.y + 0.25, pos.z - 0.25)) + Point2( (0.5, 0.5)) # Red color = Point3((255, 0, 0)) # If value == 2: show green (= we have vision on that point) if value == 2: color = Point3((0, 255, 0)) self._client.debug_box_out(p0, p1, color=color)
def draw_ramp_points(self): for ramp in self.game_info.map_ramps: for p in ramp.points: h2 = self.get_terrain_z_height(p) pos = Point3((p.x, p.y, h2)) color = Point3((255, 0, 0)) if p in ramp.upper: color = Point3((0, 255, 0)) if p in ramp.upper2_for_ramp_wall: color = Point3((0, 255, 255)) if p in ramp.lower: color = Point3((0, 0, 255)) self._client.debug_box2_out(pos, half_vertex_length=0.25, color=color)
def reset(self, target): self.target = target if self.target == Point2((68.16, 69.35)) or self.target == Point2( (19.89, 18.56)): self.push_to_forecourt = True elif self.target == Point3((28, 60, 12)) or self.target == Point3( (59, 27, 12)): self.push_to_base = True else: self.push_to_forecourt = False self.push_to_base = False self.enemy = self.bot.known_enemy_units self.units = self.bot.units.owned