partition stringclasses 3
values | func_name stringlengths 1 134 | docstring stringlengths 1 46.9k | path stringlengths 4 223 | original_string stringlengths 75 104k | code stringlengths 75 104k | docstring_tokens listlengths 1 1.97k | repo stringlengths 7 55 | language stringclasses 1
value | url stringlengths 87 315 | code_tokens listlengths 19 28.4k | sha stringlengths 40 40 |
|---|---|---|---|---|---|---|---|---|---|---|---|
train | PassengerUnit.type_id | UnitTypeId found in sc2/ids/unit_typeid
Caches all type_ids of the same unit type | sc2/unit.py | def type_id(self) -> UnitTypeId:
""" UnitTypeId found in sc2/ids/unit_typeid
Caches all type_ids of the same unit type"""
unit_type = self._proto.unit_type
if unit_type not in self._game_data.unit_types:
self._game_data.unit_types[unit_type] = UnitTypeId(unit_type)
re... | def type_id(self) -> UnitTypeId:
""" UnitTypeId found in sc2/ids/unit_typeid
Caches all type_ids of the same unit type"""
unit_type = self._proto.unit_type
if unit_type not in self._game_data.unit_types:
self._game_data.unit_types[unit_type] = UnitTypeId(unit_type)
re... | [
"UnitTypeId",
"found",
"in",
"sc2",
"/",
"ids",
"/",
"unit_typeid",
"Caches",
"all",
"type_ids",
"of",
"the",
"same",
"unit",
"type"
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/unit.py#L26-L32 | [
"def",
"type_id",
"(",
"self",
")",
"->",
"UnitTypeId",
":",
"unit_type",
"=",
"self",
".",
"_proto",
".",
"unit_type",
"if",
"unit_type",
"not",
"in",
"self",
".",
"_game_data",
".",
"unit_types",
":",
"self",
".",
"_game_data",
".",
"unit_types",
"[",
... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | PassengerUnit.ground_dps | Does not include upgrades | sc2/unit.py | def ground_dps(self) -> Union[int, float]:
""" Does not include upgrades """
if self._weapons:
weapon = next(
(weapon for weapon in self._weapons if weapon.type in {TargetType.Ground.value, TargetType.Any.value}),
None,
)
if weapon:
... | def ground_dps(self) -> Union[int, float]:
""" Does not include upgrades """
if self._weapons:
weapon = next(
(weapon for weapon in self._weapons if weapon.type in {TargetType.Ground.value, TargetType.Any.value}),
None,
)
if weapon:
... | [
"Does",
"not",
"include",
"upgrades"
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/unit.py#L109-L118 | [
"def",
"ground_dps",
"(",
"self",
")",
"->",
"Union",
"[",
"int",
",",
"float",
"]",
":",
"if",
"self",
".",
"_weapons",
":",
"weapon",
"=",
"next",
"(",
"(",
"weapon",
"for",
"weapon",
"in",
"self",
".",
"_weapons",
"if",
"weapon",
".",
"type",
"i... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | PassengerUnit.ground_range | Does not include upgrades | sc2/unit.py | def ground_range(self) -> Union[int, float]:
""" Does not include upgrades """
if self._weapons:
weapon = next(
(weapon for weapon in self._weapons if weapon.type in {TargetType.Ground.value, TargetType.Any.value}),
None,
)
if weapon:
... | def ground_range(self) -> Union[int, float]:
""" Does not include upgrades """
if self._weapons:
weapon = next(
(weapon for weapon in self._weapons if weapon.type in {TargetType.Ground.value, TargetType.Any.value}),
None,
)
if weapon:
... | [
"Does",
"not",
"include",
"upgrades"
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/unit.py#L121-L130 | [
"def",
"ground_range",
"(",
"self",
")",
"->",
"Union",
"[",
"int",
",",
"float",
"]",
":",
"if",
"self",
".",
"_weapons",
":",
"weapon",
"=",
"next",
"(",
"(",
"weapon",
"for",
"weapon",
"in",
"self",
".",
"_weapons",
"if",
"weapon",
".",
"type",
... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | PassengerUnit.can_attack_air | Does not include upgrades | sc2/unit.py | def can_attack_air(self) -> bool:
""" Does not include upgrades """
if self._weapons:
weapon = next(
(weapon for weapon in self._weapons if weapon.type in {TargetType.Air.value, TargetType.Any.value}),
None,
)
return weapon is not None
... | def can_attack_air(self) -> bool:
""" Does not include upgrades """
if self._weapons:
weapon = next(
(weapon for weapon in self._weapons if weapon.type in {TargetType.Air.value, TargetType.Any.value}),
None,
)
return weapon is not None
... | [
"Does",
"not",
"include",
"upgrades"
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/unit.py#L133-L141 | [
"def",
"can_attack_air",
"(",
"self",
")",
"->",
"bool",
":",
"if",
"self",
".",
"_weapons",
":",
"weapon",
"=",
"next",
"(",
"(",
"weapon",
"for",
"weapon",
"in",
"self",
".",
"_weapons",
"if",
"weapon",
".",
"type",
"in",
"{",
"TargetType",
".",
"A... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | PassengerUnit.air_dps | Does not include upgrades | sc2/unit.py | def air_dps(self) -> Union[int, float]:
""" Does not include upgrades """
if self._weapons:
weapon = next(
(weapon for weapon in self._weapons if weapon.type in {TargetType.Air.value, TargetType.Any.value}),
None,
)
if weapon:
... | def air_dps(self) -> Union[int, float]:
""" Does not include upgrades """
if self._weapons:
weapon = next(
(weapon for weapon in self._weapons if weapon.type in {TargetType.Air.value, TargetType.Any.value}),
None,
)
if weapon:
... | [
"Does",
"not",
"include",
"upgrades"
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/unit.py#L144-L153 | [
"def",
"air_dps",
"(",
"self",
")",
"->",
"Union",
"[",
"int",
",",
"float",
"]",
":",
"if",
"self",
".",
"_weapons",
":",
"weapon",
"=",
"next",
"(",
"(",
"weapon",
"for",
"weapon",
"in",
"self",
".",
"_weapons",
"if",
"weapon",
".",
"type",
"in",... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | PassengerUnit.air_range | Does not include upgrades | sc2/unit.py | def air_range(self) -> Union[int, float]:
""" Does not include upgrades """
if self._weapons:
weapon = next(
(weapon for weapon in self._weapons if weapon.type in {TargetType.Air.value, TargetType.Any.value}),
None,
)
if weapon:
... | def air_range(self) -> Union[int, float]:
""" Does not include upgrades """
if self._weapons:
weapon = next(
(weapon for weapon in self._weapons if weapon.type in {TargetType.Air.value, TargetType.Any.value}),
None,
)
if weapon:
... | [
"Does",
"not",
"include",
"upgrades"
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/unit.py#L156-L165 | [
"def",
"air_range",
"(",
"self",
")",
"->",
"Union",
"[",
"int",
",",
"float",
"]",
":",
"if",
"self",
".",
"_weapons",
":",
"weapon",
"=",
"next",
"(",
"(",
"weapon",
"for",
"weapon",
"in",
"self",
".",
"_weapons",
"if",
"weapon",
".",
"type",
"in... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | PassengerUnit.bonus_damage | Returns a tuple of form 'bonus damage, armor type' if unit does bonus damage against armor type
Light = 1; Armored = 2; Biological = 3; Mechanical = 4; Robotic = 5; Psionic = 6; Massive = 7;
Structure = 8; Hover = 9; Heroic = 10; Summoned = 11 | sc2/unit.py | def bonus_damage(self):
""" Returns a tuple of form 'bonus damage, armor type' if unit does bonus damage against armor type
Light = 1; Armored = 2; Biological = 3; Mechanical = 4; Robotic = 5; Psionic = 6; Massive = 7;
Structure = 8; Hover = 9; Heroic = 10; Summoned = 11 """
# TODO Consi... | def bonus_damage(self):
""" Returns a tuple of form 'bonus damage, armor type' if unit does bonus damage against armor type
Light = 1; Armored = 2; Biological = 3; Mechanical = 4; Robotic = 5; Psionic = 6; Massive = 7;
Structure = 8; Hover = 9; Heroic = 10; Summoned = 11 """
# TODO Consi... | [
"Returns",
"a",
"tuple",
"of",
"form",
"bonus",
"damage",
"armor",
"type",
"if",
"unit",
"does",
"bonus",
"damage",
"against",
"armor",
"type",
"Light",
"=",
"1",
";",
"Armored",
"=",
"2",
";",
"Biological",
"=",
"3",
";",
"Mechanical",
"=",
"4",
";",
... | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/unit.py#L168-L177 | [
"def",
"bonus_damage",
"(",
"self",
")",
":",
"# TODO Consider unit with ability attacks like Oracle, Thor, Baneling",
"if",
"self",
".",
"_weapons",
":",
"for",
"weapon",
"in",
"self",
".",
"_weapons",
":",
"if",
"weapon",
".",
"damage_bonus",
":",
"b",
"=",
"wea... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | PassengerUnit.health_percentage | Does not include shields | sc2/unit.py | def health_percentage(self) -> Union[int, float]:
""" Does not include shields """
if self._proto.health_max == 0:
return 0
return self._proto.health / self._proto.health_max | def health_percentage(self) -> Union[int, float]:
""" Does not include shields """
if self._proto.health_max == 0:
return 0
return self._proto.health / self._proto.health_max | [
"Does",
"not",
"include",
"shields"
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/unit.py#L204-L208 | [
"def",
"health_percentage",
"(",
"self",
")",
"->",
"Union",
"[",
"int",
",",
"float",
"]",
":",
"if",
"self",
".",
"_proto",
".",
"health_max",
"==",
"0",
":",
"return",
"0",
"return",
"self",
".",
"_proto",
".",
"health",
"/",
"self",
".",
"_proto"... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | Unit.distance_to | Using the 2d distance between self and p. To calculate the 3d distance,
use unit.position3d.distance_to(p) | sc2/unit.py | def distance_to(self, p: Union["Unit", Point2, Point3], bot: "BotAI" = None) -> Union[int, float]:
""" Using the 2d distance between self and p. To calculate the 3d distance,
use unit.position3d.distance_to(p) """
if bot and isinstance(p, Unit):
index = bot.distances_tag_dict
... | def distance_to(self, p: Union["Unit", Point2, Point3], bot: "BotAI" = None) -> Union[int, float]:
""" Using the 2d distance between self and p. To calculate the 3d distance,
use unit.position3d.distance_to(p) """
if bot and isinstance(p, Unit):
index = bot.distances_tag_dict
... | [
"Using",
"the",
"2d",
"distance",
"between",
"self",
"and",
"p",
".",
"To",
"calculate",
"the",
"3d",
"distance",
"use",
"unit",
".",
"position3d",
".",
"distance_to",
"(",
"p",
")"
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/unit.py#L273-L279 | [
"def",
"distance_to",
"(",
"self",
",",
"p",
":",
"Union",
"[",
"\"Unit\"",
",",
"Point2",
",",
"Point3",
"]",
",",
"bot",
":",
"\"BotAI\"",
"=",
"None",
")",
"->",
"Union",
"[",
"int",
",",
"float",
"]",
":",
"if",
"bot",
"and",
"isinstance",
"(",... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | Unit.weapon_cooldown | Returns some time (more than game loops) until the unit can fire again,
returns -1 for units that can't attack.
Usage:
if unit.weapon_cooldown == 0:
await self.do(unit.attack(target))
elif unit.weapon_cooldown < 0:
await self.do(unit.move(closest_allied_unit_becau... | sc2/unit.py | def weapon_cooldown(self) -> Union[int, float]:
""" Returns some time (more than game loops) until the unit can fire again,
returns -1 for units that can't attack.
Usage:
if unit.weapon_cooldown == 0:
await self.do(unit.attack(target))
elif unit.weapon_cooldown < 0:
... | def weapon_cooldown(self) -> Union[int, float]:
""" Returns some time (more than game loops) until the unit can fire again,
returns -1 for units that can't attack.
Usage:
if unit.weapon_cooldown == 0:
await self.do(unit.attack(target))
elif unit.weapon_cooldown < 0:
... | [
"Returns",
"some",
"time",
"(",
"more",
"than",
"game",
"loops",
")",
"until",
"the",
"unit",
"can",
"fire",
"again",
"returns",
"-",
"1",
"for",
"units",
"that",
"can",
"t",
"attack",
".",
"Usage",
":",
"if",
"unit",
".",
"weapon_cooldown",
"==",
"0",... | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/unit.py#L378-L391 | [
"def",
"weapon_cooldown",
"(",
"self",
")",
"->",
"Union",
"[",
"int",
",",
"float",
"]",
":",
"if",
"self",
".",
"can_attack",
":",
"return",
"self",
".",
"_proto",
".",
"weapon_cooldown",
"return",
"-",
"1"
] | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | Unit.passengers | Units inside a Bunker, CommandCenter, Nydus, Medivac, WarpPrism, Overlord | sc2/unit.py | def passengers(self) -> Set["PassengerUnit"]:
""" Units inside a Bunker, CommandCenter, Nydus, Medivac, WarpPrism, Overlord """
return {PassengerUnit(unit, self._game_data) for unit in self._proto.passengers} | def passengers(self) -> Set["PassengerUnit"]:
""" Units inside a Bunker, CommandCenter, Nydus, Medivac, WarpPrism, Overlord """
return {PassengerUnit(unit, self._game_data) for unit in self._proto.passengers} | [
"Units",
"inside",
"a",
"Bunker",
"CommandCenter",
"Nydus",
"Medivac",
"WarpPrism",
"Overlord"
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/unit.py#L410-L412 | [
"def",
"passengers",
"(",
"self",
")",
"->",
"Set",
"[",
"\"PassengerUnit\"",
"]",
":",
"return",
"{",
"PassengerUnit",
"(",
"unit",
",",
"self",
".",
"_game_data",
")",
"for",
"unit",
"in",
"self",
".",
"_proto",
".",
"passengers",
"}"
] | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | Unit.target_in_range | Includes the target's radius when calculating distance to target | sc2/unit.py | def target_in_range(self, target: "Unit", bonus_distance: Union[int, float] = 0) -> bool:
""" Includes the target's radius when calculating distance to target """
if self.can_attack_ground and not target.is_flying:
unit_attack_range = self.ground_range
elif self.can_attack_air and (t... | def target_in_range(self, target: "Unit", bonus_distance: Union[int, float] = 0) -> bool:
""" Includes the target's radius when calculating distance to target """
if self.can_attack_ground and not target.is_flying:
unit_attack_range = self.ground_range
elif self.can_attack_air and (t... | [
"Includes",
"the",
"target",
"s",
"radius",
"when",
"calculating",
"distance",
"to",
"target"
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/unit.py#L418-L429 | [
"def",
"target_in_range",
"(",
"self",
",",
"target",
":",
"\"Unit\"",
",",
"bonus_distance",
":",
"Union",
"[",
"int",
",",
"float",
"]",
"=",
"0",
")",
"->",
"bool",
":",
"if",
"self",
".",
"can_attack_ground",
"and",
"not",
"target",
".",
"is_flying",... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | Unit.is_carrying_minerals | Checks if a worker or MULE is carrying (gold-)minerals. | sc2/unit.py | def is_carrying_minerals(self) -> bool:
""" Checks if a worker or MULE is carrying (gold-)minerals. """
return any(
buff.value in self._proto.buff_ids
for buff in {BuffId.CARRYMINERALFIELDMINERALS, BuffId.CARRYHIGHYIELDMINERALFIELDMINERALS}
) | def is_carrying_minerals(self) -> bool:
""" Checks if a worker or MULE is carrying (gold-)minerals. """
return any(
buff.value in self._proto.buff_ids
for buff in {BuffId.CARRYMINERALFIELDMINERALS, BuffId.CARRYHIGHYIELDMINERALFIELDMINERALS}
) | [
"Checks",
"if",
"a",
"worker",
"or",
"MULE",
"is",
"carrying",
"(",
"gold",
"-",
")",
"minerals",
"."
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/unit.py#L432-L437 | [
"def",
"is_carrying_minerals",
"(",
"self",
")",
"->",
"bool",
":",
"return",
"any",
"(",
"buff",
".",
"value",
"in",
"self",
".",
"_proto",
".",
"buff_ids",
"for",
"buff",
"in",
"{",
"BuffId",
".",
"CARRYMINERALFIELDMINERALS",
",",
"BuffId",
".",
"CARRYHI... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | Unit.is_carrying_vespene | Checks if a worker is carrying vespene. | sc2/unit.py | def is_carrying_vespene(self) -> bool:
""" Checks if a worker is carrying vespene. """
return any(
buff.value in self._proto.buff_ids
for buff in {
BuffId.CARRYHARVESTABLEVESPENEGEYSERGAS,
BuffId.CARRYHARVESTABLEVESPENEGEYSERGASPROTOSS,
... | def is_carrying_vespene(self) -> bool:
""" Checks if a worker is carrying vespene. """
return any(
buff.value in self._proto.buff_ids
for buff in {
BuffId.CARRYHARVESTABLEVESPENEGEYSERGAS,
BuffId.CARRYHARVESTABLEVESPENEGEYSERGASPROTOSS,
... | [
"Checks",
"if",
"a",
"worker",
"is",
"carrying",
"vespene",
"."
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/unit.py#L440-L449 | [
"def",
"is_carrying_vespene",
"(",
"self",
")",
"->",
"bool",
":",
"return",
"any",
"(",
"buff",
".",
"value",
"in",
"self",
".",
"_proto",
".",
"buff_ids",
"for",
"buff",
"in",
"{",
"BuffId",
".",
"CARRYHARVESTABLEVESPENEGEYSERGAS",
",",
"BuffId",
".",
"C... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | Unit.is_patrolling | Checks if a unit is patrolling. | sc2/unit.py | def is_patrolling(self) -> bool:
""" Checks if a unit is patrolling. """
return self.orders and self.orders[0].ability.id is AbilityId.PATROL | def is_patrolling(self) -> bool:
""" Checks if a unit is patrolling. """
return self.orders and self.orders[0].ability.id is AbilityId.PATROL | [
"Checks",
"if",
"a",
"unit",
"is",
"patrolling",
"."
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/unit.py#L478-L480 | [
"def",
"is_patrolling",
"(",
"self",
")",
"->",
"bool",
":",
"return",
"self",
".",
"orders",
"and",
"self",
".",
"orders",
"[",
"0",
"]",
".",
"ability",
".",
"id",
"is",
"AbilityId",
".",
"PATROL"
] | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | Unit.is_gathering | Checks if a unit is on its way to a mineral field / vespene geyser to mine. | sc2/unit.py | def is_gathering(self) -> bool:
""" Checks if a unit is on its way to a mineral field / vespene geyser to mine. """
return self.orders and self.orders[0].ability.id is AbilityId.HARVEST_GATHER | def is_gathering(self) -> bool:
""" Checks if a unit is on its way to a mineral field / vespene geyser to mine. """
return self.orders and self.orders[0].ability.id is AbilityId.HARVEST_GATHER | [
"Checks",
"if",
"a",
"unit",
"is",
"on",
"its",
"way",
"to",
"a",
"mineral",
"field",
"/",
"vespene",
"geyser",
"to",
"mine",
"."
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/unit.py#L483-L485 | [
"def",
"is_gathering",
"(",
"self",
")",
"->",
"bool",
":",
"return",
"self",
".",
"orders",
"and",
"self",
".",
"orders",
"[",
"0",
"]",
".",
"ability",
".",
"id",
"is",
"AbilityId",
".",
"HARVEST_GATHER"
] | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | Unit.is_returning | Checks if a unit is returning from mineral field / vespene geyser to deliver resources to townhall. | sc2/unit.py | def is_returning(self) -> bool:
""" Checks if a unit is returning from mineral field / vespene geyser to deliver resources to townhall. """
return self.orders and self.orders[0].ability.id is AbilityId.HARVEST_RETURN | def is_returning(self) -> bool:
""" Checks if a unit is returning from mineral field / vespene geyser to deliver resources to townhall. """
return self.orders and self.orders[0].ability.id is AbilityId.HARVEST_RETURN | [
"Checks",
"if",
"a",
"unit",
"is",
"returning",
"from",
"mineral",
"field",
"/",
"vespene",
"geyser",
"to",
"deliver",
"resources",
"to",
"townhall",
"."
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/unit.py#L488-L490 | [
"def",
"is_returning",
"(",
"self",
")",
"->",
"bool",
":",
"return",
"self",
".",
"orders",
"and",
"self",
".",
"orders",
"[",
"0",
"]",
".",
"ability",
".",
"id",
"is",
"AbilityId",
".",
"HARVEST_RETURN"
] | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | Unit.is_collecting | Combines the two properties above. | sc2/unit.py | def is_collecting(self) -> bool:
""" Combines the two properties above. """
return self.orders and self.orders[0].ability.id in {AbilityId.HARVEST_GATHER, AbilityId.HARVEST_RETURN} | def is_collecting(self) -> bool:
""" Combines the two properties above. """
return self.orders and self.orders[0].ability.id in {AbilityId.HARVEST_GATHER, AbilityId.HARVEST_RETURN} | [
"Combines",
"the",
"two",
"properties",
"above",
"."
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/unit.py#L493-L495 | [
"def",
"is_collecting",
"(",
"self",
")",
"->",
"bool",
":",
"return",
"self",
".",
"orders",
"and",
"self",
".",
"orders",
"[",
"0",
"]",
".",
"ability",
".",
"id",
"in",
"{",
"AbilityId",
".",
"HARVEST_GATHER",
",",
"AbilityId",
".",
"HARVEST_RETURN",
... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | Unit.is_constructing_scv | Checks if the unit is an SCV that is currently building. | sc2/unit.py | def is_constructing_scv(self) -> bool:
""" Checks if the unit is an SCV that is currently building. """
return self.orders and self.orders[0].ability.id in {
AbilityId.TERRANBUILD_ARMORY,
AbilityId.TERRANBUILD_BARRACKS,
AbilityId.TERRANBUILD_BUNKER,
Abilit... | def is_constructing_scv(self) -> bool:
""" Checks if the unit is an SCV that is currently building. """
return self.orders and self.orders[0].ability.id in {
AbilityId.TERRANBUILD_ARMORY,
AbilityId.TERRANBUILD_BARRACKS,
AbilityId.TERRANBUILD_BUNKER,
Abilit... | [
"Checks",
"if",
"the",
"unit",
"is",
"an",
"SCV",
"that",
"is",
"currently",
"building",
"."
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/unit.py#L498-L514 | [
"def",
"is_constructing_scv",
"(",
"self",
")",
"->",
"bool",
":",
"return",
"self",
".",
"orders",
"and",
"self",
".",
"orders",
"[",
"0",
"]",
".",
"ability",
".",
"id",
"in",
"{",
"AbilityId",
".",
"TERRANBUILD_ARMORY",
",",
"AbilityId",
".",
"TERRANB... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | Unit.order_target | Returns the target tag (if it is a Unit) or Point2 (if it is a Position)
from the first order, returns None if the unit is idle | sc2/unit.py | def order_target(self) -> Optional[Union[int, Point2]]:
""" Returns the target tag (if it is a Unit) or Point2 (if it is a Position)
from the first order, returns None if the unit is idle """
if self.orders:
if isinstance(self.orders[0].target, int):
return self.order... | def order_target(self) -> Optional[Union[int, Point2]]:
""" Returns the target tag (if it is a Unit) or Point2 (if it is a Position)
from the first order, returns None if the unit is idle """
if self.orders:
if isinstance(self.orders[0].target, int):
return self.order... | [
"Returns",
"the",
"target",
"tag",
"(",
"if",
"it",
"is",
"a",
"Unit",
")",
"or",
"Point2",
"(",
"if",
"it",
"is",
"a",
"Position",
")",
"from",
"the",
"first",
"order",
"returns",
"None",
"if",
"the",
"unit",
"is",
"idle"
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/unit.py#L525-L533 | [
"def",
"order_target",
"(",
"self",
")",
"->",
"Optional",
"[",
"Union",
"[",
"int",
",",
"Point2",
"]",
"]",
":",
"if",
"self",
".",
"orders",
":",
"if",
"isinstance",
"(",
"self",
".",
"orders",
"[",
"0",
"]",
".",
"target",
",",
"int",
")",
":... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | Unit.research | Requires UpgradeId to be passed instead of AbilityId | sc2/unit.py | def research(self, upgrade, *args, **kwargs):
""" Requires UpgradeId to be passed instead of AbilityId """
return self(self._game_data.upgrades[upgrade.value].research_ability.id, *args, **kwargs) | def research(self, upgrade, *args, **kwargs):
""" Requires UpgradeId to be passed instead of AbilityId """
return self(self._game_data.upgrades[upgrade.value].research_ability.id, *args, **kwargs) | [
"Requires",
"UpgradeId",
"to",
"be",
"passed",
"instead",
"of",
"AbilityId"
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/unit.py#L575-L577 | [
"def",
"research",
"(",
"self",
",",
"upgrade",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"self",
"(",
"self",
".",
"_game_data",
".",
"upgrades",
"[",
"upgrade",
".",
"value",
"]",
".",
"research_ability",
".",
"id",
",",
"*",
... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | Units.in_attack_range_of | Filters units that are in attack range of the unit in parameter | sc2/units.py | def in_attack_range_of(self, unit: Unit, bonus_distance: Union[int, float] = 0) -> "Units":
""" Filters units that are in attack range of the unit in parameter """
return self.filter(lambda x: unit.target_in_range(x, bonus_distance=bonus_distance)) | def in_attack_range_of(self, unit: Unit, bonus_distance: Union[int, float] = 0) -> "Units":
""" Filters units that are in attack range of the unit in parameter """
return self.filter(lambda x: unit.target_in_range(x, bonus_distance=bonus_distance)) | [
"Filters",
"units",
"that",
"are",
"in",
"attack",
"range",
"of",
"the",
"unit",
"in",
"parameter"
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/units.py#L113-L115 | [
"def",
"in_attack_range_of",
"(",
"self",
",",
"unit",
":",
"Unit",
",",
"bonus_distance",
":",
"Union",
"[",
"int",
",",
"float",
"]",
"=",
"0",
")",
"->",
"\"Units\"",
":",
"return",
"self",
".",
"filter",
"(",
"lambda",
"x",
":",
"unit",
".",
"tar... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | Units.closest_distance_to | Returns the distance between the closest unit from this group to the target unit | sc2/units.py | def closest_distance_to(self, position: Union[Unit, Point2, Point3]) -> Union[int, float]:
""" Returns the distance between the closest unit from this group to the target unit """
assert self.exists
if isinstance(position, Unit):
position = position.position
return position.d... | def closest_distance_to(self, position: Union[Unit, Point2, Point3]) -> Union[int, float]:
""" Returns the distance between the closest unit from this group to the target unit """
assert self.exists
if isinstance(position, Unit):
position = position.position
return position.d... | [
"Returns",
"the",
"distance",
"between",
"the",
"closest",
"unit",
"from",
"this",
"group",
"to",
"the",
"target",
"unit"
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/units.py#L117-L124 | [
"def",
"closest_distance_to",
"(",
"self",
",",
"position",
":",
"Union",
"[",
"Unit",
",",
"Point2",
",",
"Point3",
"]",
")",
"->",
"Union",
"[",
"int",
",",
"float",
"]",
":",
"assert",
"self",
".",
"exists",
"if",
"isinstance",
"(",
"position",
",",... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | Units.furthest_distance_to | Returns the distance between the furthest unit from this group to the target unit | sc2/units.py | def furthest_distance_to(self, position: Union[Unit, Point2, Point3]) -> Union[int, float]:
""" Returns the distance between the furthest unit from this group to the target unit """
assert self.exists
if isinstance(position, Unit):
position = position.position
return position... | def furthest_distance_to(self, position: Union[Unit, Point2, Point3]) -> Union[int, float]:
""" Returns the distance between the furthest unit from this group to the target unit """
assert self.exists
if isinstance(position, Unit):
position = position.position
return position... | [
"Returns",
"the",
"distance",
"between",
"the",
"furthest",
"unit",
"from",
"this",
"group",
"to",
"the",
"target",
"unit"
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/units.py#L126-L131 | [
"def",
"furthest_distance_to",
"(",
"self",
",",
"position",
":",
"Union",
"[",
"Unit",
",",
"Point2",
",",
"Point3",
"]",
")",
"->",
"Union",
"[",
"int",
",",
"float",
"]",
":",
"assert",
"self",
".",
"exists",
"if",
"isinstance",
"(",
"position",
","... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | Units.sorted_by_distance_to | This function should be a bit faster than using units.sorted(keyfn=lambda u: u.distance_to(position)) | sc2/units.py | def sorted_by_distance_to(self, position: Union[Unit, Point2], reverse: bool = False) -> "Units":
""" This function should be a bit faster than using units.sorted(keyfn=lambda u: u.distance_to(position)) """
if len(self) in [0, 1]:
return self
position = position.position
ret... | def sorted_by_distance_to(self, position: Union[Unit, Point2], reverse: bool = False) -> "Units":
""" This function should be a bit faster than using units.sorted(keyfn=lambda u: u.distance_to(position)) """
if len(self) in [0, 1]:
return self
position = position.position
ret... | [
"This",
"function",
"should",
"be",
"a",
"bit",
"faster",
"than",
"using",
"units",
".",
"sorted",
"(",
"keyfn",
"=",
"lambda",
"u",
":",
"u",
".",
"distance_to",
"(",
"position",
"))"
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/units.py#L168-L173 | [
"def",
"sorted_by_distance_to",
"(",
"self",
",",
"position",
":",
"Union",
"[",
"Unit",
",",
"Point2",
"]",
",",
"reverse",
":",
"bool",
"=",
"False",
")",
"->",
"\"Units\"",
":",
"if",
"len",
"(",
"self",
")",
"in",
"[",
"0",
",",
"1",
"]",
":",
... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | Units.tags_not_in | Filters all units that have their tags not in the 'other' set/list/dict | sc2/units.py | def tags_not_in(self, other: Union[Set[int], List[int], Dict[int, Any]]) -> "Units":
""" Filters all units that have their tags not in the 'other' set/list/dict """
# example: self.units(QUEEN).tags_not_in(self.queen_tags_assigned_to_do_injects)
if isinstance(other, list):
other = se... | def tags_not_in(self, other: Union[Set[int], List[int], Dict[int, Any]]) -> "Units":
""" Filters all units that have their tags not in the 'other' set/list/dict """
# example: self.units(QUEEN).tags_not_in(self.queen_tags_assigned_to_do_injects)
if isinstance(other, list):
other = se... | [
"Filters",
"all",
"units",
"that",
"have",
"their",
"tags",
"not",
"in",
"the",
"other",
"set",
"/",
"list",
"/",
"dict"
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/units.py#L182-L187 | [
"def",
"tags_not_in",
"(",
"self",
",",
"other",
":",
"Union",
"[",
"Set",
"[",
"int",
"]",
",",
"List",
"[",
"int",
"]",
",",
"Dict",
"[",
"int",
",",
"Any",
"]",
"]",
")",
"->",
"\"Units\"",
":",
"# example: self.units(QUEEN).tags_not_in(self.queen_tags_... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | Units.of_type | Filters all units that are of a specific type | sc2/units.py | def of_type(self, other: Union[UnitTypeId, Set[UnitTypeId], List[UnitTypeId], Dict[UnitTypeId, Any]]) -> "Units":
""" Filters all units that are of a specific type """
# example: self.units.of_type([ZERGLING, ROACH, HYDRALISK, BROODLORD])
if isinstance(other, UnitTypeId):
other = {ot... | def of_type(self, other: Union[UnitTypeId, Set[UnitTypeId], List[UnitTypeId], Dict[UnitTypeId, Any]]) -> "Units":
""" Filters all units that are of a specific type """
# example: self.units.of_type([ZERGLING, ROACH, HYDRALISK, BROODLORD])
if isinstance(other, UnitTypeId):
other = {ot... | [
"Filters",
"all",
"units",
"that",
"are",
"of",
"a",
"specific",
"type"
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/units.py#L189-L196 | [
"def",
"of_type",
"(",
"self",
",",
"other",
":",
"Union",
"[",
"UnitTypeId",
",",
"Set",
"[",
"UnitTypeId",
"]",
",",
"List",
"[",
"UnitTypeId",
"]",
",",
"Dict",
"[",
"UnitTypeId",
",",
"Any",
"]",
"]",
")",
"->",
"\"Units\"",
":",
"# example: self.u... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | Units.same_tech | Usage:
'self.units.same_tech(UnitTypeId.COMMANDCENTER)' or 'self.units.same_tech(UnitTypeId.ORBITALCOMMAND)'
returns all CommandCenter, CommandCenterFlying, OrbitalCommand, OrbitalCommandFlying, PlanetaryFortress
This also works with a set/list/dict parameter, e.g. 'self.units.same_tech({UnitTyp... | sc2/units.py | def same_tech(self, other: Union[UnitTypeId, Set[UnitTypeId], List[UnitTypeId], Dict[UnitTypeId, Any]]) -> "Units":
""" Usage:
'self.units.same_tech(UnitTypeId.COMMANDCENTER)' or 'self.units.same_tech(UnitTypeId.ORBITALCOMMAND)'
returns all CommandCenter, CommandCenterFlying, OrbitalCommand, Orb... | def same_tech(self, other: Union[UnitTypeId, Set[UnitTypeId], List[UnitTypeId], Dict[UnitTypeId, Any]]) -> "Units":
""" Usage:
'self.units.same_tech(UnitTypeId.COMMANDCENTER)' or 'self.units.same_tech(UnitTypeId.ORBITALCOMMAND)'
returns all CommandCenter, CommandCenterFlying, OrbitalCommand, Orb... | [
"Usage",
":",
"self",
".",
"units",
".",
"same_tech",
"(",
"UnitTypeId",
".",
"COMMANDCENTER",
")",
"or",
"self",
".",
"units",
".",
"same_tech",
"(",
"UnitTypeId",
".",
"ORBITALCOMMAND",
")",
"returns",
"all",
"CommandCenter",
"CommandCenterFlying",
"OrbitalCom... | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/units.py#L209-L228 | [
"def",
"same_tech",
"(",
"self",
",",
"other",
":",
"Union",
"[",
"UnitTypeId",
",",
"Set",
"[",
"UnitTypeId",
"]",
",",
"List",
"[",
"UnitTypeId",
"]",
",",
"Dict",
"[",
"UnitTypeId",
",",
"Any",
"]",
"]",
")",
"->",
"\"Units\"",
":",
"if",
"isinsta... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | Units.same_unit | Usage:
'self.units.same_tech(UnitTypeId.COMMANDCENTER)'
returns CommandCenter and CommandCenterFlying,
'self.units.same_tech(UnitTypeId.ORBITALCOMMAND)'
returns OrbitalCommand and OrbitalCommandFlying
This also works with a set/list/dict parameter, e.g. 'self.units.same_tech({Uni... | sc2/units.py | def same_unit(self, other: Union[UnitTypeId, Set[UnitTypeId], List[UnitTypeId], Dict[UnitTypeId, Any]]) -> "Units":
""" Usage:
'self.units.same_tech(UnitTypeId.COMMANDCENTER)'
returns CommandCenter and CommandCenterFlying,
'self.units.same_tech(UnitTypeId.ORBITALCOMMAND)'
returns... | def same_unit(self, other: Union[UnitTypeId, Set[UnitTypeId], List[UnitTypeId], Dict[UnitTypeId, Any]]) -> "Units":
""" Usage:
'self.units.same_tech(UnitTypeId.COMMANDCENTER)'
returns CommandCenter and CommandCenterFlying,
'self.units.same_tech(UnitTypeId.ORBITALCOMMAND)'
returns... | [
"Usage",
":",
"self",
".",
"units",
".",
"same_tech",
"(",
"UnitTypeId",
".",
"COMMANDCENTER",
")",
"returns",
"CommandCenter",
"and",
"CommandCenterFlying",
"self",
".",
"units",
".",
"same_tech",
"(",
"UnitTypeId",
".",
"ORBITALCOMMAND",
")",
"returns",
"Orbit... | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/units.py#L230-L250 | [
"def",
"same_unit",
"(",
"self",
",",
"other",
":",
"Union",
"[",
"UnitTypeId",
",",
"Set",
"[",
"UnitTypeId",
"]",
",",
"List",
"[",
"UnitTypeId",
"]",
",",
"Dict",
"[",
"UnitTypeId",
",",
"Any",
"]",
"]",
")",
"->",
"\"Units\"",
":",
"if",
"isinsta... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | Units.center | Returns the central point of all units in this list | sc2/units.py | def center(self) -> Point2:
""" Returns the central point of all units in this list """
assert self
pos = Point2(
(
sum([unit.position.x for unit in self]) / self.amount,
sum([unit.position.y for unit in self]) / self.amount,
)
)
... | def center(self) -> Point2:
""" Returns the central point of all units in this list """
assert self
pos = Point2(
(
sum([unit.position.x for unit in self]) / self.amount,
sum([unit.position.y for unit in self]) / self.amount,
)
)
... | [
"Returns",
"the",
"central",
"point",
"of",
"all",
"units",
"in",
"this",
"list"
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/units.py#L253-L262 | [
"def",
"center",
"(",
"self",
")",
"->",
"Point2",
":",
"assert",
"self",
"pos",
"=",
"Point2",
"(",
"(",
"sum",
"(",
"[",
"unit",
".",
"position",
".",
"x",
"for",
"unit",
"in",
"self",
"]",
")",
"/",
"self",
".",
"amount",
",",
"sum",
"(",
"[... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | MassReaperBot.on_step | - depots when low on remaining supply
- townhalls contains commandcenter and orbitalcommand
- self.units(TYPE).not_ready.amount selects all units of that type, filters incomplete units, and then counts the amount
- self.already_pending(TYPE) counts how many units are queued - but in this bot be... | examples/terran/mass_reaper.py | async def on_step(self, iteration):
self.combinedActions = []
"""
- depots when low on remaining supply
- townhalls contains commandcenter and orbitalcommand
- self.units(TYPE).not_ready.amount selects all units of that type, filters incomplete units, and then counts the amount... | async def on_step(self, iteration):
self.combinedActions = []
"""
- depots when low on remaining supply
- townhalls contains commandcenter and orbitalcommand
- self.units(TYPE).not_ready.amount selects all units of that type, filters incomplete units, and then counts the amount... | [
"-",
"depots",
"when",
"low",
"on",
"remaining",
"supply",
"-",
"townhalls",
"contains",
"commandcenter",
"and",
"orbitalcommand",
"-",
"self",
".",
"units",
"(",
"TYPE",
")",
".",
"not_ready",
".",
"amount",
"selects",
"all",
"units",
"of",
"that",
"type",
... | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/examples/terran/mass_reaper.py#L25-L189 | [
"async",
"def",
"on_step",
"(",
"self",
",",
"iteration",
")",
":",
"self",
".",
"combinedActions",
"=",
"[",
"]",
"if",
"self",
".",
"supply_left",
"<",
"5",
"and",
"self",
".",
"townhalls",
".",
"exists",
"and",
"self",
".",
"supply_used",
">=",
"14"... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | Client.leave | You can use 'await self._client.leave()' to surrender midst game. | sc2/client.py | async def leave(self):
""" You can use 'await self._client.leave()' to surrender midst game. """
is_resign = self._game_result is None
if is_resign:
# For all clients that can leave, result of leaving the game either
# loss, or the client will ignore the result
... | async def leave(self):
""" You can use 'await self._client.leave()' to surrender midst game. """
is_resign = self._game_result is None
if is_resign:
# For all clients that can leave, result of leaving the game either
# loss, or the client will ignore the result
... | [
"You",
"can",
"use",
"await",
"self",
".",
"_client",
".",
"leave",
"()",
"to",
"surrender",
"midst",
"game",
"."
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/client.py#L90-L103 | [
"async",
"def",
"leave",
"(",
"self",
")",
":",
"is_resign",
"=",
"self",
".",
"_game_result",
"is",
"None",
"if",
"is_resign",
":",
"# For all clients that can leave, result of leaving the game either",
"# loss, or the client will ignore the result",
"self",
".",
"_game_re... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | Client.step | EXPERIMENTAL: Change self._client.game_step during the step function to increase or decrease steps per second | sc2/client.py | async def step(self):
""" EXPERIMENTAL: Change self._client.game_step during the step function to increase or decrease steps per second """
result = await self._execute(step=sc_pb.RequestStep(count=self.game_step))
return result | async def step(self):
""" EXPERIMENTAL: Change self._client.game_step during the step function to increase or decrease steps per second """
result = await self._execute(step=sc_pb.RequestStep(count=self.game_step))
return result | [
"EXPERIMENTAL",
":",
"Change",
"self",
".",
"_client",
".",
"game_step",
"during",
"the",
"step",
"function",
"to",
"increase",
"or",
"decrease",
"steps",
"per",
"second"
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/client.py#L136-L139 | [
"async",
"def",
"step",
"(",
"self",
")",
":",
"result",
"=",
"await",
"self",
".",
"_execute",
"(",
"step",
"=",
"sc_pb",
".",
"RequestStep",
"(",
"count",
"=",
"self",
".",
"game_step",
")",
")",
"return",
"result"
] | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | Client.query_pathing | Caution: returns 0 when path not found | sc2/client.py | async def query_pathing(
self, start: Union[Unit, Point2, Point3], end: Union[Point2, Point3]
) -> Optional[Union[int, float]]:
""" Caution: returns 0 when path not found """
assert isinstance(start, (Point2, Unit))
assert isinstance(end, Point2)
if isinstance(start, Point2):... | async def query_pathing(
self, start: Union[Unit, Point2, Point3], end: Union[Point2, Point3]
) -> Optional[Union[int, float]]:
""" Caution: returns 0 when path not found """
assert isinstance(start, (Point2, Unit))
assert isinstance(end, Point2)
if isinstance(start, Point2):... | [
"Caution",
":",
"returns",
"0",
"when",
"path",
"not",
"found"
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/client.py#L167-L195 | [
"async",
"def",
"query_pathing",
"(",
"self",
",",
"start",
":",
"Union",
"[",
"Unit",
",",
"Point2",
",",
"Point3",
"]",
",",
"end",
":",
"Union",
"[",
"Point2",
",",
"Point3",
"]",
")",
"->",
"Optional",
"[",
"Union",
"[",
"int",
",",
"float",
"]... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | Client.query_pathings | Usage: await self.query_pathings([[unit1, target2], [unit2, target2]])
-> returns [distance1, distance2]
Caution: returns 0 when path not found
Might merge this function with the function above | sc2/client.py | async def query_pathings(self, zipped_list: List[List[Union[Unit, Point2, Point3]]]) -> List[Union[float, int]]:
""" Usage: await self.query_pathings([[unit1, target2], [unit2, target2]])
-> returns [distance1, distance2]
Caution: returns 0 when path not found
Might merge this function w... | async def query_pathings(self, zipped_list: List[List[Union[Unit, Point2, Point3]]]) -> List[Union[float, int]]:
""" Usage: await self.query_pathings([[unit1, target2], [unit2, target2]])
-> returns [distance1, distance2]
Caution: returns 0 when path not found
Might merge this function w... | [
"Usage",
":",
"await",
"self",
".",
"query_pathings",
"(",
"[[",
"unit1",
"target2",
"]",
"[",
"unit2",
"target2",
"]]",
")",
"-",
">",
"returns",
"[",
"distance1",
"distance2",
"]",
"Caution",
":",
"returns",
"0",
"when",
"path",
"not",
"found",
"Might"... | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/client.py#L197-L230 | [
"async",
"def",
"query_pathings",
"(",
"self",
",",
"zipped_list",
":",
"List",
"[",
"List",
"[",
"Union",
"[",
"Unit",
",",
"Point2",
",",
"Point3",
"]",
"]",
"]",
")",
"->",
"List",
"[",
"Union",
"[",
"float",
",",
"int",
"]",
"]",
":",
"assert",... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | Client.query_available_abilities | Query abilities of multiple units | sc2/client.py | async def query_available_abilities(
self, units: Union[List[Unit], "Units"], ignore_resource_requirements: bool = False
) -> List[List[AbilityId]]:
""" Query abilities of multiple units """
if not isinstance(units, list):
""" Deprecated, accepting a single unit may be removed in... | async def query_available_abilities(
self, units: Union[List[Unit], "Units"], ignore_resource_requirements: bool = False
) -> List[List[AbilityId]]:
""" Query abilities of multiple units """
if not isinstance(units, list):
""" Deprecated, accepting a single unit may be removed in... | [
"Query",
"abilities",
"of",
"multiple",
"units"
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/client.py#L249-L270 | [
"async",
"def",
"query_available_abilities",
"(",
"self",
",",
"units",
":",
"Union",
"[",
"List",
"[",
"Unit",
"]",
",",
"\"Units\"",
"]",
",",
"ignore_resource_requirements",
":",
"bool",
"=",
"False",
")",
"->",
"List",
"[",
"List",
"[",
"AbilityId",
"]... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | Client.chat_send | Writes a message to the chat | sc2/client.py | async def chat_send(self, message: str, team_only: bool):
""" Writes a message to the chat """
ch = ChatChannel.Team if team_only else ChatChannel.Broadcast
await self._execute(
action=sc_pb.RequestAction(
actions=[sc_pb.Action(action_chat=sc_pb.ActionChat(channel=ch.... | async def chat_send(self, message: str, team_only: bool):
""" Writes a message to the chat """
ch = ChatChannel.Team if team_only else ChatChannel.Broadcast
await self._execute(
action=sc_pb.RequestAction(
actions=[sc_pb.Action(action_chat=sc_pb.ActionChat(channel=ch.... | [
"Writes",
"a",
"message",
"to",
"the",
"chat"
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/client.py#L272-L279 | [
"async",
"def",
"chat_send",
"(",
"self",
",",
"message",
":",
"str",
",",
"team_only",
":",
"bool",
")",
":",
"ch",
"=",
"ChatChannel",
".",
"Team",
"if",
"team_only",
"else",
"ChatChannel",
".",
"Broadcast",
"await",
"self",
".",
"_execute",
"(",
"acti... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | Client.debug_create_unit | Usage example (will spawn 1 marine in the center of the map for player ID 1):
await self._client.debug_create_unit([[UnitTypeId.MARINE, 1, self._game_info.map_center, 1]]) | sc2/client.py | async def debug_create_unit(self, unit_spawn_commands: List[List[Union[UnitTypeId, int, Point2, Point3]]]):
""" Usage example (will spawn 1 marine in the center of the map for player ID 1):
await self._client.debug_create_unit([[UnitTypeId.MARINE, 1, self._game_info.map_center, 1]]) """
assert i... | async def debug_create_unit(self, unit_spawn_commands: List[List[Union[UnitTypeId, int, Point2, Point3]]]):
""" Usage example (will spawn 1 marine in the center of the map for player ID 1):
await self._client.debug_create_unit([[UnitTypeId.MARINE, 1, self._game_info.map_center, 1]]) """
assert i... | [
"Usage",
"example",
"(",
"will",
"spawn",
"1",
"marine",
"in",
"the",
"center",
"of",
"the",
"map",
"for",
"player",
"ID",
"1",
")",
":",
"await",
"self",
".",
"_client",
".",
"debug_create_unit",
"(",
"[[",
"UnitTypeId",
".",
"MARINE",
"1",
"self",
".... | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/client.py#L281-L307 | [
"async",
"def",
"debug_create_unit",
"(",
"self",
",",
"unit_spawn_commands",
":",
"List",
"[",
"List",
"[",
"Union",
"[",
"UnitTypeId",
",",
"int",
",",
"Point2",
",",
"Point3",
"]",
"]",
"]",
")",
":",
"assert",
"isinstance",
"(",
"unit_spawn_commands",
... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | Client.move_camera | Moves camera to the target position | sc2/client.py | async def move_camera(self, position: Union[Unit, Point2, Point3]):
""" Moves camera to the target position """
assert isinstance(position, (Unit, Point2, Point3))
if isinstance(position, Unit):
position = position.position
await self._execute(
action=sc_pb.Reques... | async def move_camera(self, position: Union[Unit, Point2, Point3]):
""" Moves camera to the target position """
assert isinstance(position, (Unit, Point2, Point3))
if isinstance(position, Unit):
position = position.position
await self._execute(
action=sc_pb.Reques... | [
"Moves",
"camera",
"to",
"the",
"target",
"position"
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/client.py#L318-L335 | [
"async",
"def",
"move_camera",
"(",
"self",
",",
"position",
":",
"Union",
"[",
"Unit",
",",
"Point2",
",",
"Point3",
"]",
")",
":",
"assert",
"isinstance",
"(",
"position",
",",
"(",
"Unit",
",",
"Point2",
",",
"Point3",
")",
")",
"if",
"isinstance",
... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | Client.move_camera_spatial | Moves camera to the target position using the spatial aciton interface | sc2/client.py | async def move_camera_spatial(self, position: Union[Point2, Point3]):
""" Moves camera to the target position using the spatial aciton interface """
from s2clientprotocol import spatial_pb2 as spatial_pb
assert isinstance(position, (Point2, Point3))
action = sc_pb.Action(
act... | async def move_camera_spatial(self, position: Union[Point2, Point3]):
""" Moves camera to the target position using the spatial aciton interface """
from s2clientprotocol import spatial_pb2 as spatial_pb
assert isinstance(position, (Point2, Point3))
action = sc_pb.Action(
act... | [
"Moves",
"camera",
"to",
"the",
"target",
"position",
"using",
"the",
"spatial",
"aciton",
"interface"
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/client.py#L337-L348 | [
"async",
"def",
"move_camera_spatial",
"(",
"self",
",",
"position",
":",
"Union",
"[",
"Point2",
",",
"Point3",
"]",
")",
":",
"from",
"s2clientprotocol",
"import",
"spatial_pb2",
"as",
"spatial_pb",
"assert",
"isinstance",
"(",
"position",
",",
"(",
"Point2"... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | Client.debug_text | Deprecated, may be removed soon | sc2/client.py | async def debug_text(self, texts: Union[str, list], positions: Union[list, set], color=(0, 255, 0), size_px=16):
""" Deprecated, may be removed soon """
if isinstance(positions, (set, list)):
if not positions:
return
if isinstance(texts, str):
tex... | async def debug_text(self, texts: Union[str, list], positions: Union[list, set], color=(0, 255, 0), size_px=16):
""" Deprecated, may be removed soon """
if isinstance(positions, (set, list)):
if not positions:
return
if isinstance(texts, str):
tex... | [
"Deprecated",
"may",
"be",
"removed",
"soon"
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/client.py#L350-L380 | [
"async",
"def",
"debug_text",
"(",
"self",
",",
"texts",
":",
"Union",
"[",
"str",
",",
"list",
"]",
",",
"positions",
":",
"Union",
"[",
"list",
",",
"set",
"]",
",",
"color",
"=",
"(",
"0",
",",
"255",
",",
"0",
")",
",",
"size_px",
"=",
"16"... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | Client.debug_text_simple | Draws a text in the top left corner of the screen (up to a max of 6 messages it seems). Don't forget to add 'await self._client.send_debug'. | sc2/client.py | def debug_text_simple(self, text: str):
""" Draws a text in the top left corner of the screen (up to a max of 6 messages it seems). Don't forget to add 'await self._client.send_debug'. """
self._debug_texts.append(self.to_debug_message(text)) | def debug_text_simple(self, text: str):
""" Draws a text in the top left corner of the screen (up to a max of 6 messages it seems). Don't forget to add 'await self._client.send_debug'. """
self._debug_texts.append(self.to_debug_message(text)) | [
"Draws",
"a",
"text",
"in",
"the",
"top",
"left",
"corner",
"of",
"the",
"screen",
"(",
"up",
"to",
"a",
"max",
"of",
"6",
"messages",
"it",
"seems",
")",
".",
"Don",
"t",
"forget",
"to",
"add",
"await",
"self",
".",
"_client",
".",
"send_debug",
"... | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/client.py#L382-L384 | [
"def",
"debug_text_simple",
"(",
"self",
",",
"text",
":",
"str",
")",
":",
"self",
".",
"_debug_texts",
".",
"append",
"(",
"self",
".",
"to_debug_message",
"(",
"text",
")",
")"
] | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | Client.debug_text_screen | Draws a text on the screen with coordinates 0 <= x, y <= 1. Don't forget to add 'await self._client.send_debug'. | sc2/client.py | def debug_text_screen(self, text: str, pos: Union[Point2, Point3, tuple, list], color=None, size: int = 8):
""" Draws a text on the screen with coordinates 0 <= x, y <= 1. Don't forget to add 'await self._client.send_debug'. """
assert len(pos) >= 2
assert 0 <= pos[0] <= 1
assert 0 <= po... | def debug_text_screen(self, text: str, pos: Union[Point2, Point3, tuple, list], color=None, size: int = 8):
""" Draws a text on the screen with coordinates 0 <= x, y <= 1. Don't forget to add 'await self._client.send_debug'. """
assert len(pos) >= 2
assert 0 <= pos[0] <= 1
assert 0 <= po... | [
"Draws",
"a",
"text",
"on",
"the",
"screen",
"with",
"coordinates",
"0",
"<",
"=",
"x",
"y",
"<",
"=",
"1",
".",
"Don",
"t",
"forget",
"to",
"add",
"await",
"self",
".",
"_client",
".",
"send_debug",
"."
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/client.py#L386-L392 | [
"def",
"debug_text_screen",
"(",
"self",
",",
"text",
":",
"str",
",",
"pos",
":",
"Union",
"[",
"Point2",
",",
"Point3",
",",
"tuple",
",",
"list",
"]",
",",
"color",
"=",
"None",
",",
"size",
":",
"int",
"=",
"8",
")",
":",
"assert",
"len",
"("... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | Client.debug_text_world | Draws a text at Point3 position. Don't forget to add 'await self._client.send_debug'.
To grab a unit's 3d position, use unit.position3d
Usually the Z value of a Point3 is between 8 and 14 (except for flying units) | sc2/client.py | def debug_text_world(self, text: str, pos: Union[Unit, Point2, Point3], color=None, size: int = 8):
""" Draws a text at Point3 position. Don't forget to add 'await self._client.send_debug'.
To grab a unit's 3d position, use unit.position3d
Usually the Z value of a Point3 is between 8 and 14 (exc... | def debug_text_world(self, text: str, pos: Union[Unit, Point2, Point3], color=None, size: int = 8):
""" Draws a text at Point3 position. Don't forget to add 'await self._client.send_debug'.
To grab a unit's 3d position, use unit.position3d
Usually the Z value of a Point3 is between 8 and 14 (exc... | [
"Draws",
"a",
"text",
"at",
"Point3",
"position",
".",
"Don",
"t",
"forget",
"to",
"add",
"await",
"self",
".",
"_client",
".",
"send_debug",
".",
"To",
"grab",
"a",
"unit",
"s",
"3d",
"position",
"use",
"unit",
".",
"position3d",
"Usually",
"the",
"Z"... | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/client.py#L397-L404 | [
"def",
"debug_text_world",
"(",
"self",
",",
"text",
":",
"str",
",",
"pos",
":",
"Union",
"[",
"Unit",
",",
"Point2",
",",
"Point3",
"]",
",",
"color",
"=",
"None",
",",
"size",
":",
"int",
"=",
"8",
")",
":",
"if",
"isinstance",
"(",
"pos",
","... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | Client.debug_line_out | Draws a line from p0 to p1. Don't forget to add 'await self._client.send_debug'. | sc2/client.py | def debug_line_out(self, p0: Union[Unit, Point2, Point3], p1: Union[Unit, Point2, Point3], color=None):
""" Draws a line from p0 to p1. Don't forget to add 'await self._client.send_debug'. """
self._debug_lines.append(
debug_pb.DebugLine(
line=debug_pb.Line(p0=self.to_debug_p... | def debug_line_out(self, p0: Union[Unit, Point2, Point3], p1: Union[Unit, Point2, Point3], color=None):
""" Draws a line from p0 to p1. Don't forget to add 'await self._client.send_debug'. """
self._debug_lines.append(
debug_pb.DebugLine(
line=debug_pb.Line(p0=self.to_debug_p... | [
"Draws",
"a",
"line",
"from",
"p0",
"to",
"p1",
".",
"Don",
"t",
"forget",
"to",
"add",
"await",
"self",
".",
"_client",
".",
"send_debug",
"."
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/client.py#L409-L416 | [
"def",
"debug_line_out",
"(",
"self",
",",
"p0",
":",
"Union",
"[",
"Unit",
",",
"Point2",
",",
"Point3",
"]",
",",
"p1",
":",
"Union",
"[",
"Unit",
",",
"Point2",
",",
"Point3",
"]",
",",
"color",
"=",
"None",
")",
":",
"self",
".",
"_debug_lines"... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | Client.debug_box_out | Draws a box with p_min and p_max as corners. Don't forget to add 'await self._client.send_debug'. | sc2/client.py | def debug_box_out(self, p_min: Union[Unit, Point2, Point3], p_max: Union[Unit, Point2, Point3], color=None):
""" Draws a box with p_min and p_max as corners. Don't forget to add 'await self._client.send_debug'. """
self._debug_boxes.append(
debug_pb.DebugBox(
min=self.to_debu... | def debug_box_out(self, p_min: Union[Unit, Point2, Point3], p_max: Union[Unit, Point2, Point3], color=None):
""" Draws a box with p_min and p_max as corners. Don't forget to add 'await self._client.send_debug'. """
self._debug_boxes.append(
debug_pb.DebugBox(
min=self.to_debu... | [
"Draws",
"a",
"box",
"with",
"p_min",
"and",
"p_max",
"as",
"corners",
".",
"Don",
"t",
"forget",
"to",
"add",
"await",
"self",
".",
"_client",
".",
"send_debug",
"."
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/client.py#L418-L424 | [
"def",
"debug_box_out",
"(",
"self",
",",
"p_min",
":",
"Union",
"[",
"Unit",
",",
"Point2",
",",
"Point3",
"]",
",",
"p_max",
":",
"Union",
"[",
"Unit",
",",
"Point2",
",",
"Point3",
"]",
",",
"color",
"=",
"None",
")",
":",
"self",
".",
"_debug_b... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | Client.debug_sphere_out | Draws a sphere at point p with radius r. Don't forget to add 'await self._client.send_debug'. | sc2/client.py | def debug_sphere_out(self, p: Union[Unit, Point2, Point3], r: Union[int, float], color=None):
""" Draws a sphere at point p with radius r. Don't forget to add 'await self._client.send_debug'. """
self._debug_spheres.append(
debug_pb.DebugSphere(p=self.to_debug_point(p), r=r, color=self.to_de... | def debug_sphere_out(self, p: Union[Unit, Point2, Point3], r: Union[int, float], color=None):
""" Draws a sphere at point p with radius r. Don't forget to add 'await self._client.send_debug'. """
self._debug_spheres.append(
debug_pb.DebugSphere(p=self.to_debug_point(p), r=r, color=self.to_de... | [
"Draws",
"a",
"sphere",
"at",
"point",
"p",
"with",
"radius",
"r",
".",
"Don",
"t",
"forget",
"to",
"add",
"await",
"self",
".",
"_client",
".",
"send_debug",
"."
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/client.py#L426-L430 | [
"def",
"debug_sphere_out",
"(",
"self",
",",
"p",
":",
"Union",
"[",
"Unit",
",",
"Point2",
",",
"Point3",
"]",
",",
"r",
":",
"Union",
"[",
"int",
",",
"float",
"]",
",",
"color",
"=",
"None",
")",
":",
"self",
".",
"_debug_spheres",
".",
"append"... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | Client.send_debug | Sends the debug draw execution. Put this after your debug creation functions. | sc2/client.py | async def send_debug(self):
""" Sends the debug draw execution. Put this after your debug creation functions. """
await self._execute(
debug=sc_pb.RequestDebug(
debug=[
debug_pb.DebugCommand(
draw=debug_pb.DebugDraw(
... | async def send_debug(self):
""" Sends the debug draw execution. Put this after your debug creation functions. """
await self._execute(
debug=sc_pb.RequestDebug(
debug=[
debug_pb.DebugCommand(
draw=debug_pb.DebugDraw(
... | [
"Sends",
"the",
"debug",
"draw",
"execution",
".",
"Put",
"this",
"after",
"your",
"debug",
"creation",
"functions",
"."
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/client.py#L432-L451 | [
"async",
"def",
"send_debug",
"(",
"self",
")",
":",
"await",
"self",
".",
"_execute",
"(",
"debug",
"=",
"sc_pb",
".",
"RequestDebug",
"(",
"debug",
"=",
"[",
"debug_pb",
".",
"DebugCommand",
"(",
"draw",
"=",
"debug_pb",
".",
"DebugDraw",
"(",
"text",
... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | Client.to_debug_color | Helper function for color conversion | sc2/client.py | def to_debug_color(self, color):
""" Helper function for color conversion """
if color is None:
return debug_pb.Color(r=255, g=255, b=255)
else:
r = getattr(color, "r", getattr(color, "x", 255))
g = getattr(color, "g", getattr(color, "y", 255))
b =... | def to_debug_color(self, color):
""" Helper function for color conversion """
if color is None:
return debug_pb.Color(r=255, g=255, b=255)
else:
r = getattr(color, "r", getattr(color, "x", 255))
g = getattr(color, "g", getattr(color, "y", 255))
b =... | [
"Helper",
"function",
"for",
"color",
"conversion"
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/client.py#L453-L466 | [
"def",
"to_debug_color",
"(",
"self",
",",
"color",
")",
":",
"if",
"color",
"is",
"None",
":",
"return",
"debug_pb",
".",
"Color",
"(",
"r",
"=",
"255",
",",
"g",
"=",
"255",
",",
"b",
"=",
"255",
")",
"else",
":",
"r",
"=",
"getattr",
"(",
"c... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | Client.to_debug_point | Helper function for point conversion | sc2/client.py | def to_debug_point(self, point: Union[Unit, Point2, Point3]) -> common_pb.Point:
""" Helper function for point conversion """
if isinstance(point, Unit):
point = point.position3d
return common_pb.Point(x=point.x, y=point.y, z=getattr(point, "z", 0)) | def to_debug_point(self, point: Union[Unit, Point2, Point3]) -> common_pb.Point:
""" Helper function for point conversion """
if isinstance(point, Unit):
point = point.position3d
return common_pb.Point(x=point.x, y=point.y, z=getattr(point, "z", 0)) | [
"Helper",
"function",
"for",
"point",
"conversion"
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/client.py#L468-L472 | [
"def",
"to_debug_point",
"(",
"self",
",",
"point",
":",
"Union",
"[",
"Unit",
",",
"Point2",
",",
"Point3",
"]",
")",
"->",
"common_pb",
".",
"Point",
":",
"if",
"isinstance",
"(",
"point",
",",
"Unit",
")",
":",
"point",
"=",
"point",
".",
"positio... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | Client.to_debug_message | Helper function to create debug texts | sc2/client.py | def to_debug_message(
self, text: str, color=None, pos: Optional[Union[Point2, Point3]] = None, size: int = 8
) -> debug_pb.DebugText:
""" Helper function to create debug texts """
color = self.to_debug_color(color)
pt3d = self.to_debug_point(pos) if isinstance(pos, Point3) else None... | def to_debug_message(
self, text: str, color=None, pos: Optional[Union[Point2, Point3]] = None, size: int = 8
) -> debug_pb.DebugText:
""" Helper function to create debug texts """
color = self.to_debug_color(color)
pt3d = self.to_debug_point(pos) if isinstance(pos, Point3) else None... | [
"Helper",
"function",
"to",
"create",
"debug",
"texts"
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/client.py#L474-L482 | [
"def",
"to_debug_message",
"(",
"self",
",",
"text",
":",
"str",
",",
"color",
"=",
"None",
",",
"pos",
":",
"Optional",
"[",
"Union",
"[",
"Point2",
",",
"Point3",
"]",
"]",
"=",
"None",
",",
"size",
":",
"int",
"=",
"8",
")",
"->",
"debug_pb",
... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | Pointlike.distance_to_point2 | Same as the function above, but should be 3-4 times faster because of the dropped asserts and conversions and because it doesnt use a loop (itertools or zip). | sc2/position.py | def distance_to_point2(self, p2: "Point2") -> Union[int, float]:
""" Same as the function above, but should be 3-4 times faster because of the dropped asserts and conversions and because it doesnt use a loop (itertools or zip). """
return ((self[0] - p2[0]) ** 2 + (self[1] - p2[1]) ** 2) ** 0.5 | def distance_to_point2(self, p2: "Point2") -> Union[int, float]:
""" Same as the function above, but should be 3-4 times faster because of the dropped asserts and conversions and because it doesnt use a loop (itertools or zip). """
return ((self[0] - p2[0]) ** 2 + (self[1] - p2[1]) ** 2) ** 0.5 | [
"Same",
"as",
"the",
"function",
"above",
"but",
"should",
"be",
"3",
"-",
"4",
"times",
"faster",
"because",
"of",
"the",
"dropped",
"asserts",
"and",
"conversions",
"and",
"because",
"it",
"doesnt",
"use",
"a",
"loop",
"(",
"itertools",
"or",
"zip",
")... | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/position.py#L32-L34 | [
"def",
"distance_to_point2",
"(",
"self",
",",
"p2",
":",
"\"Point2\"",
")",
"->",
"Union",
"[",
"int",
",",
"float",
"]",
":",
"return",
"(",
"(",
"self",
"[",
"0",
"]",
"-",
"p2",
"[",
"0",
"]",
")",
"**",
"2",
"+",
"(",
"self",
"[",
"1",
"... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | Pointlike._distance_squared | Function used to not take the square root as the distances will stay proportionally the same. This is to speed up the sorting process. | sc2/position.py | def _distance_squared(self, p2: "Point2") -> Union[int, float]:
""" Function used to not take the square root as the distances will stay proportionally the same. This is to speed up the sorting process. """
return (self[0] - p2[0]) ** 2 + (self[1] - p2[1]) ** 2 | def _distance_squared(self, p2: "Point2") -> Union[int, float]:
""" Function used to not take the square root as the distances will stay proportionally the same. This is to speed up the sorting process. """
return (self[0] - p2[0]) ** 2 + (self[1] - p2[1]) ** 2 | [
"Function",
"used",
"to",
"not",
"take",
"the",
"square",
"root",
"as",
"the",
"distances",
"will",
"stay",
"proportionally",
"the",
"same",
".",
"This",
"is",
"to",
"speed",
"up",
"the",
"sorting",
"process",
"."
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/position.py#L36-L38 | [
"def",
"_distance_squared",
"(",
"self",
",",
"p2",
":",
"\"Point2\"",
")",
"->",
"Union",
"[",
"int",
",",
"float",
"]",
":",
"return",
"(",
"self",
"[",
"0",
"]",
"-",
"p2",
"[",
"0",
"]",
")",
"**",
"2",
"+",
"(",
"self",
"[",
"1",
"]",
"-... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | Pointlike.sort_by_distance | This returns the target points sorted as list. You should not pass a set or dict since those are not sortable.
If you want to sort your units towards a point, use 'units.sorted_by_distance_to(point)' instead. | sc2/position.py | def sort_by_distance(self, ps: Union["Units", List["Point2"]]) -> List["Point2"]:
""" This returns the target points sorted as list. You should not pass a set or dict since those are not sortable.
If you want to sort your units towards a point, use 'units.sorted_by_distance_to(point)' instead. """
... | def sort_by_distance(self, ps: Union["Units", List["Point2"]]) -> List["Point2"]:
""" This returns the target points sorted as list. You should not pass a set or dict since those are not sortable.
If you want to sort your units towards a point, use 'units.sorted_by_distance_to(point)' instead. """
... | [
"This",
"returns",
"the",
"target",
"points",
"sorted",
"as",
"list",
".",
"You",
"should",
"not",
"pass",
"a",
"set",
"or",
"dict",
"since",
"those",
"are",
"not",
"sortable",
".",
"If",
"you",
"want",
"to",
"sort",
"your",
"units",
"towards",
"a",
"p... | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/position.py#L40-L47 | [
"def",
"sort_by_distance",
"(",
"self",
",",
"ps",
":",
"Union",
"[",
"\"Units\"",
",",
"List",
"[",
"\"Point2\"",
"]",
"]",
")",
"->",
"List",
"[",
"\"Point2\"",
"]",
":",
"if",
"len",
"(",
"ps",
")",
"==",
"1",
":",
"return",
"ps",
"[",
"0",
"]... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | Pointlike.closest | This function assumes the 2d distance is meant | sc2/position.py | def closest(self, ps: Union["Units", List["Point2"], Set["Point2"]]) -> Union["Unit", "Point2"]:
""" This function assumes the 2d distance is meant """
assert ps
if len(ps) == 1:
return ps[0]
closest_distance_squared = math.inf
for p2 in ps:
p2pos = p2
... | def closest(self, ps: Union["Units", List["Point2"], Set["Point2"]]) -> Union["Unit", "Point2"]:
""" This function assumes the 2d distance is meant """
assert ps
if len(ps) == 1:
return ps[0]
closest_distance_squared = math.inf
for p2 in ps:
p2pos = p2
... | [
"This",
"function",
"assumes",
"the",
"2d",
"distance",
"is",
"meant"
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/position.py#L49-L63 | [
"def",
"closest",
"(",
"self",
",",
"ps",
":",
"Union",
"[",
"\"Units\"",
",",
"List",
"[",
"\"Point2\"",
"]",
",",
"Set",
"[",
"\"Point2\"",
"]",
"]",
")",
"->",
"Union",
"[",
"\"Unit\"",
",",
"\"Point2\"",
"]",
":",
"assert",
"ps",
"if",
"len",
"... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | Pointlike.distance_to_closest | This function assumes the 2d distance is meant | sc2/position.py | def distance_to_closest(self, ps: Union["Units", List["Point2"], Set["Point2"]]) -> Union[int, float]:
""" This function assumes the 2d distance is meant """
assert ps
closest_distance_squared = math.inf
for p2 in ps:
if not isinstance(p2, Point2):
p2 = p2.pos... | def distance_to_closest(self, ps: Union["Units", List["Point2"], Set["Point2"]]) -> Union[int, float]:
""" This function assumes the 2d distance is meant """
assert ps
closest_distance_squared = math.inf
for p2 in ps:
if not isinstance(p2, Point2):
p2 = p2.pos... | [
"This",
"function",
"assumes",
"the",
"2d",
"distance",
"is",
"meant"
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/position.py#L65-L75 | [
"def",
"distance_to_closest",
"(",
"self",
",",
"ps",
":",
"Union",
"[",
"\"Units\"",
",",
"List",
"[",
"\"Point2\"",
"]",
",",
"Set",
"[",
"\"Point2\"",
"]",
"]",
")",
"->",
"Union",
"[",
"int",
",",
"float",
"]",
":",
"assert",
"ps",
"closest_distanc... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | Pointlike.furthest | This function assumes the 2d distance is meant | sc2/position.py | def furthest(self, ps: Union["Units", List["Point2"], Set["Point2"]]) -> Union["Unit", "Pointlike"]:
""" This function assumes the 2d distance is meant """
assert ps
if len(ps) == 1:
return ps[0]
furthest_distance_squared = -math.inf
for p2 in ps:
p2pos = ... | def furthest(self, ps: Union["Units", List["Point2"], Set["Point2"]]) -> Union["Unit", "Pointlike"]:
""" This function assumes the 2d distance is meant """
assert ps
if len(ps) == 1:
return ps[0]
furthest_distance_squared = -math.inf
for p2 in ps:
p2pos = ... | [
"This",
"function",
"assumes",
"the",
"2d",
"distance",
"is",
"meant"
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/position.py#L77-L91 | [
"def",
"furthest",
"(",
"self",
",",
"ps",
":",
"Union",
"[",
"\"Units\"",
",",
"List",
"[",
"\"Point2\"",
"]",
",",
"Set",
"[",
"\"Point2\"",
"]",
"]",
")",
"->",
"Union",
"[",
"\"Unit\"",
",",
"\"Pointlike\"",
"]",
":",
"assert",
"ps",
"if",
"len",... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | Pointlike.distance_to_furthest | This function assumes the 2d distance is meant | sc2/position.py | def distance_to_furthest(self, ps: Union["Units", List["Point2"], Set["Point2"]]) -> Union[int, float]:
""" This function assumes the 2d distance is meant """
assert ps
furthest_distance_squared = -math.inf
for p2 in ps:
if not isinstance(p2, Point2):
p2 = p2.... | def distance_to_furthest(self, ps: Union["Units", List["Point2"], Set["Point2"]]) -> Union[int, float]:
""" This function assumes the 2d distance is meant """
assert ps
furthest_distance_squared = -math.inf
for p2 in ps:
if not isinstance(p2, Point2):
p2 = p2.... | [
"This",
"function",
"assumes",
"the",
"2d",
"distance",
"is",
"meant"
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/position.py#L93-L103 | [
"def",
"distance_to_furthest",
"(",
"self",
",",
"ps",
":",
"Union",
"[",
"\"Units\"",
",",
"List",
"[",
"\"Point2\"",
"]",
",",
"Set",
"[",
"\"Point2\"",
"]",
"]",
")",
"->",
"Union",
"[",
"int",
",",
"float",
"]",
":",
"assert",
"ps",
"furthest_dista... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | Point2.distance2_to | Squared distance to a point. | sc2/position.py | def distance2_to(self, other: "Point2"):
"""Squared distance to a point."""
assert isinstance(other, Point2)
return (self[0] - other[0]) ** 2 + (self[1] - other[1]) ** 2 | def distance2_to(self, other: "Point2"):
"""Squared distance to a point."""
assert isinstance(other, Point2)
return (self[0] - other[0]) ** 2 + (self[1] - other[1]) ** 2 | [
"Squared",
"distance",
"to",
"a",
"point",
"."
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/position.py#L157-L160 | [
"def",
"distance2_to",
"(",
"self",
",",
"other",
":",
"\"Point2\"",
")",
":",
"assert",
"isinstance",
"(",
"other",
",",
"Point2",
")",
"return",
"(",
"self",
"[",
"0",
"]",
"-",
"other",
"[",
"0",
"]",
")",
"**",
"2",
"+",
"(",
"self",
"[",
"1"... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | Point2.circle_intersection | self is point1, p is point2, r is the radius for circles originating in both points
Used in ramp finding | sc2/position.py | def circle_intersection(self, p: "Point2", r: Union[int, float]) -> Set["Point2"]:
""" self is point1, p is point2, r is the radius for circles originating in both points
Used in ramp finding """
assert self != p
distanceBetweenPoints = self.distance_to(p)
assert r > distanceBetw... | def circle_intersection(self, p: "Point2", r: Union[int, float]) -> Set["Point2"]:
""" self is point1, p is point2, r is the radius for circles originating in both points
Used in ramp finding """
assert self != p
distanceBetweenPoints = self.distance_to(p)
assert r > distanceBetw... | [
"self",
"is",
"point1",
"p",
"is",
"point2",
"r",
"is",
"the",
"radius",
"for",
"circles",
"originating",
"in",
"both",
"points",
"Used",
"in",
"ramp",
"finding"
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/position.py#L183-L205 | [
"def",
"circle_intersection",
"(",
"self",
",",
"p",
":",
"\"Point2\"",
",",
"r",
":",
"Union",
"[",
"int",
",",
"float",
"]",
")",
"->",
"Set",
"[",
"\"Point2\"",
"]",
":",
"assert",
"self",
"!=",
"p",
"distanceBetweenPoints",
"=",
"self",
".",
"dista... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | Point2.direction_vector | Converts a vector to a direction that can face vertically, horizontally or diagonal or be zero, e.g. (0, 0), (1, -1), (1, 0) | sc2/position.py | def direction_vector(self, other: "Point2") -> "Point2":
""" Converts a vector to a direction that can face vertically, horizontally or diagonal or be zero, e.g. (0, 0), (1, -1), (1, 0) """
return self.__class__((_sign(other.x - self.x), _sign(other.y - self.y))) | def direction_vector(self, other: "Point2") -> "Point2":
""" Converts a vector to a direction that can face vertically, horizontally or diagonal or be zero, e.g. (0, 0), (1, -1), (1, 0) """
return self.__class__((_sign(other.x - self.x), _sign(other.y - self.y))) | [
"Converts",
"a",
"vector",
"to",
"a",
"direction",
"that",
"can",
"face",
"vertically",
"horizontally",
"or",
"diagonal",
"or",
"be",
"zero",
"e",
".",
"g",
".",
"(",
"0",
"0",
")",
"(",
"1",
"-",
"1",
")",
"(",
"1",
"0",
")"
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/position.py#L259-L261 | [
"def",
"direction_vector",
"(",
"self",
",",
"other",
":",
"\"Point2\"",
")",
"->",
"\"Point2\"",
":",
"return",
"self",
".",
"__class__",
"(",
"(",
"_sign",
"(",
"other",
".",
"x",
"-",
"self",
".",
"x",
")",
",",
"_sign",
"(",
"other",
".",
"y",
... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | Point2.center | Returns the central point for points in list | sc2/position.py | def center(a: Union[Set["Point2"], List["Point2"]]) -> "Point2":
""" Returns the central point for points in list """
s = Point2((0, 0))
for p in a:
s += p
return s / len(a) | def center(a: Union[Set["Point2"], List["Point2"]]) -> "Point2":
""" Returns the central point for points in list """
s = Point2((0, 0))
for p in a:
s += p
return s / len(a) | [
"Returns",
"the",
"central",
"point",
"for",
"points",
"in",
"list"
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/position.py#L267-L272 | [
"def",
"center",
"(",
"a",
":",
"Union",
"[",
"Set",
"[",
"\"Point2\"",
"]",
",",
"List",
"[",
"\"Point2\"",
"]",
"]",
")",
"->",
"\"Point2\"",
":",
"s",
"=",
"Point2",
"(",
"(",
"0",
",",
"0",
")",
")",
"for",
"p",
"in",
"a",
":",
"s",
"+=",... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | Ramp.upper | Returns the upper points of a ramp. | sc2/game_info.py | def upper(self) -> Set[Point2]:
""" Returns the upper points of a ramp. """
max_height = max([self.height_at(p) for p in self._points])
return {p for p in self._points if self.height_at(p) == max_height} | def upper(self) -> Set[Point2]:
""" Returns the upper points of a ramp. """
max_height = max([self.height_at(p) for p in self._points])
return {p for p in self._points if self.height_at(p) == max_height} | [
"Returns",
"the",
"upper",
"points",
"of",
"a",
"ramp",
"."
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/game_info.py#L37-L40 | [
"def",
"upper",
"(",
"self",
")",
"->",
"Set",
"[",
"Point2",
"]",
":",
"max_height",
"=",
"max",
"(",
"[",
"self",
".",
"height_at",
"(",
"p",
")",
"for",
"p",
"in",
"self",
".",
"_points",
"]",
")",
"return",
"{",
"p",
"for",
"p",
"in",
"self... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | Ramp.upper2_for_ramp_wall | Returns the 2 upper ramp points of the main base ramp required for the supply depot and barracks placement properties used in this file. | sc2/game_info.py | def upper2_for_ramp_wall(self) -> Set[Point2]:
""" Returns the 2 upper ramp points of the main base ramp required for the supply depot and barracks placement properties used in this file. """
if len(self.upper) > 5:
# NOTE: this was way too slow on large ramps
return set() # HAC... | def upper2_for_ramp_wall(self) -> Set[Point2]:
""" Returns the 2 upper ramp points of the main base ramp required for the supply depot and barracks placement properties used in this file. """
if len(self.upper) > 5:
# NOTE: this was way too slow on large ramps
return set() # HAC... | [
"Returns",
"the",
"2",
"upper",
"ramp",
"points",
"of",
"the",
"main",
"base",
"ramp",
"required",
"for",
"the",
"supply",
"depot",
"and",
"barracks",
"placement",
"properties",
"used",
"in",
"this",
"file",
"."
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/game_info.py#L43-L53 | [
"def",
"upper2_for_ramp_wall",
"(",
"self",
")",
"->",
"Set",
"[",
"Point2",
"]",
":",
"if",
"len",
"(",
"self",
".",
"upper",
")",
">",
"5",
":",
"# NOTE: this was way too slow on large ramps",
"return",
"set",
"(",
")",
"# HACK: makes this work for now",
"# FI... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | Ramp.barracks_in_middle | Barracks position in the middle of the 2 depots | sc2/game_info.py | def barracks_in_middle(self) -> Point2:
""" Barracks position in the middle of the 2 depots """
if len(self.upper2_for_ramp_wall) == 2:
points = self.upper2_for_ramp_wall
p1 = points.pop().offset((self.x_offset, self.y_offset))
p2 = points.pop().offset((self.x_offset,... | def barracks_in_middle(self) -> Point2:
""" Barracks position in the middle of the 2 depots """
if len(self.upper2_for_ramp_wall) == 2:
points = self.upper2_for_ramp_wall
p1 = points.pop().offset((self.x_offset, self.y_offset))
p2 = points.pop().offset((self.x_offset,... | [
"Barracks",
"position",
"in",
"the",
"middle",
"of",
"the",
"2",
"depots"
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/game_info.py#L75-L85 | [
"def",
"barracks_in_middle",
"(",
"self",
")",
"->",
"Point2",
":",
"if",
"len",
"(",
"self",
".",
"upper2_for_ramp_wall",
")",
"==",
"2",
":",
"points",
"=",
"self",
".",
"upper2_for_ramp_wall",
"p1",
"=",
"points",
".",
"pop",
"(",
")",
".",
"offset",
... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | Ramp.corner_depots | Finds the 2 depot positions on the outside | sc2/game_info.py | def corner_depots(self) -> Set[Point2]:
""" Finds the 2 depot positions on the outside """
if len(self.upper2_for_ramp_wall) == 2:
points = self.upper2_for_ramp_wall
p1 = points.pop().offset((self.x_offset, self.y_offset)) # still an error with pixelmap?
p2 = points.... | def corner_depots(self) -> Set[Point2]:
""" Finds the 2 depot positions on the outside """
if len(self.upper2_for_ramp_wall) == 2:
points = self.upper2_for_ramp_wall
p1 = points.pop().offset((self.x_offset, self.y_offset)) # still an error with pixelmap?
p2 = points.... | [
"Finds",
"the",
"2",
"depot",
"positions",
"on",
"the",
"outside"
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/game_info.py#L101-L112 | [
"def",
"corner_depots",
"(",
"self",
")",
"->",
"Set",
"[",
"Point2",
"]",
":",
"if",
"len",
"(",
"self",
".",
"upper2_for_ramp_wall",
")",
"==",
"2",
":",
"points",
"=",
"self",
".",
"upper2_for_ramp_wall",
"p1",
"=",
"points",
".",
"pop",
"(",
")",
... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | Ramp.barracks_can_fit_addon | Test if a barracks can fit an addon at natural ramp | sc2/game_info.py | def barracks_can_fit_addon(self) -> bool:
""" Test if a barracks can fit an addon at natural ramp """
# https://i.imgur.com/4b2cXHZ.png
if len(self.upper2_for_ramp_wall) == 2:
return self.barracks_in_middle.x + 1 > max(self.corner_depots, key=lambda depot: depot.x).x
raise Ex... | def barracks_can_fit_addon(self) -> bool:
""" Test if a barracks can fit an addon at natural ramp """
# https://i.imgur.com/4b2cXHZ.png
if len(self.upper2_for_ramp_wall) == 2:
return self.barracks_in_middle.x + 1 > max(self.corner_depots, key=lambda depot: depot.x).x
raise Ex... | [
"Test",
"if",
"a",
"barracks",
"can",
"fit",
"an",
"addon",
"at",
"natural",
"ramp"
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/game_info.py#L115-L120 | [
"def",
"barracks_can_fit_addon",
"(",
"self",
")",
"->",
"bool",
":",
"# https://i.imgur.com/4b2cXHZ.png",
"if",
"len",
"(",
"self",
".",
"upper2_for_ramp_wall",
")",
"==",
"2",
":",
"return",
"self",
".",
"barracks_in_middle",
".",
"x",
"+",
"1",
">",
"max",
... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | Ramp.barracks_correct_placement | Corrected placement so that an addon can fit | sc2/game_info.py | def barracks_correct_placement(self) -> Point2:
""" Corrected placement so that an addon can fit """
if len(self.upper2_for_ramp_wall) == 2:
if self.barracks_can_fit_addon:
return self.barracks_in_middle
else:
return self.barracks_in_middle.offset(... | def barracks_correct_placement(self) -> Point2:
""" Corrected placement so that an addon can fit """
if len(self.upper2_for_ramp_wall) == 2:
if self.barracks_can_fit_addon:
return self.barracks_in_middle
else:
return self.barracks_in_middle.offset(... | [
"Corrected",
"placement",
"so",
"that",
"an",
"addon",
"can",
"fit"
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/game_info.py#L123-L130 | [
"def",
"barracks_correct_placement",
"(",
"self",
")",
"->",
"Point2",
":",
"if",
"len",
"(",
"self",
".",
"upper2_for_ramp_wall",
")",
"==",
"2",
":",
"if",
"self",
".",
"barracks_can_fit_addon",
":",
"return",
"self",
".",
"barracks_in_middle",
"else",
":",
... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | GameInfo._find_ramps | Calculate (self.pathing_grid - self.placement_grid) (for sets) and then find ramps by comparing heights. | sc2/game_info.py | def _find_ramps(self) -> List[Ramp]:
"""Calculate (self.pathing_grid - self.placement_grid) (for sets) and then find ramps by comparing heights."""
rampDict = {
Point2((x, y)): self.pathing_grid[(x, y)] == 0 and self.placement_grid[(x, y)] == 0
for x in range(self.pathing_grid.wi... | def _find_ramps(self) -> List[Ramp]:
"""Calculate (self.pathing_grid - self.placement_grid) (for sets) and then find ramps by comparing heights."""
rampDict = {
Point2((x, y)): self.pathing_grid[(x, y)] == 0 and self.placement_grid[(x, y)] == 0
for x in range(self.pathing_grid.wi... | [
"Calculate",
"(",
"self",
".",
"pathing_grid",
"-",
"self",
".",
"placement_grid",
")",
"(",
"for",
"sets",
")",
"and",
"then",
"find",
"ramps",
"by",
"comparing",
"heights",
"."
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/game_info.py#L158-L168 | [
"def",
"_find_ramps",
"(",
"self",
")",
"->",
"List",
"[",
"Ramp",
"]",
":",
"rampDict",
"=",
"{",
"Point2",
"(",
"(",
"x",
",",
"y",
")",
")",
":",
"self",
".",
"pathing_grid",
"[",
"(",
"x",
",",
"y",
")",
"]",
"==",
"0",
"and",
"self",
"."... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | GameInfo._find_groups | From a set/list of points, this function will try to group points together | sc2/game_info.py | def _find_groups(
self, points: Set[Point2], minimum_points_per_group: int = 8, max_distance_between_points: int = 2
) -> List[Set[Point2]]:
""" From a set/list of points, this function will try to group points together """
""" Paint clusters of points in rectangular map using flood fill alg... | def _find_groups(
self, points: Set[Point2], minimum_points_per_group: int = 8, max_distance_between_points: int = 2
) -> List[Set[Point2]]:
""" From a set/list of points, this function will try to group points together """
""" Paint clusters of points in rectangular map using flood fill alg... | [
"From",
"a",
"set",
"/",
"list",
"of",
"points",
"this",
"function",
"will",
"try",
"to",
"group",
"points",
"together"
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/game_info.py#L170-L224 | [
"def",
"_find_groups",
"(",
"self",
",",
"points",
":",
"Set",
"[",
"Point2",
"]",
",",
"minimum_points_per_group",
":",
"int",
"=",
"8",
",",
"max_distance_between_points",
":",
"int",
"=",
"2",
")",
"->",
"List",
"[",
"Set",
"[",
"Point2",
"]",
"]",
... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | split_camel_case | Splits words from CamelCase text. | sc2/game_data.py | def split_camel_case(text) -> list:
"""Splits words from CamelCase text."""
return list(reduce(
lambda a, b: (a + [b] if b.isupper() else a[:-1] + [a[-1] + b]),
text,
[]
)) | def split_camel_case(text) -> list:
"""Splits words from CamelCase text."""
return list(reduce(
lambda a, b: (a + [b] if b.isupper() else a[:-1] + [a[-1] + b]),
text,
[]
)) | [
"Splits",
"words",
"from",
"CamelCase",
"text",
"."
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/game_data.py#L18-L24 | [
"def",
"split_camel_case",
"(",
"text",
")",
"->",
"list",
":",
"return",
"list",
"(",
"reduce",
"(",
"lambda",
"a",
",",
"b",
":",
"(",
"a",
"+",
"[",
"b",
"]",
"if",
"b",
".",
"isupper",
"(",
")",
"else",
"a",
"[",
":",
"-",
"1",
"]",
"+",
... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | UnitTypeData.tech_requirement | Tech-building requirement of buildings - may work for units but unreliably | sc2/game_data.py | def tech_requirement(self) -> Optional[UnitTypeId]:
""" Tech-building requirement of buildings - may work for units but unreliably """
if self._proto.tech_requirement == 0:
return None
if self._proto.tech_requirement not in self._game_data.units:
return None
retur... | def tech_requirement(self) -> Optional[UnitTypeId]:
""" Tech-building requirement of buildings - may work for units but unreliably """
if self._proto.tech_requirement == 0:
return None
if self._proto.tech_requirement not in self._game_data.units:
return None
retur... | [
"Tech",
"-",
"building",
"requirement",
"of",
"buildings",
"-",
"may",
"work",
"for",
"units",
"but",
"unreliably"
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/game_data.py#L177-L183 | [
"def",
"tech_requirement",
"(",
"self",
")",
"->",
"Optional",
"[",
"UnitTypeId",
"]",
":",
"if",
"self",
".",
"_proto",
".",
"tech_requirement",
"==",
"0",
":",
"return",
"None",
"if",
"self",
".",
"_proto",
".",
"tech_requirement",
"not",
"in",
"self",
... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | UnitTypeData.tech_alias | Building tech equality, e.g. OrbitalCommand is the same as CommandCenter | sc2/game_data.py | def tech_alias(self) -> Optional[List[UnitTypeId]]:
""" Building tech equality, e.g. OrbitalCommand is the same as CommandCenter """
""" Building tech equality, e.g. Hive is the same as Lair and Hatchery """
return_list = []
for tech_alias in self._proto.tech_alias:
if tech_a... | def tech_alias(self) -> Optional[List[UnitTypeId]]:
""" Building tech equality, e.g. OrbitalCommand is the same as CommandCenter """
""" Building tech equality, e.g. Hive is the same as Lair and Hatchery """
return_list = []
for tech_alias in self._proto.tech_alias:
if tech_a... | [
"Building",
"tech",
"equality",
"e",
".",
"g",
".",
"OrbitalCommand",
"is",
"the",
"same",
"as",
"CommandCenter"
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/game_data.py#L186-L197 | [
"def",
"tech_alias",
"(",
"self",
")",
"->",
"Optional",
"[",
"List",
"[",
"UnitTypeId",
"]",
"]",
":",
"\"\"\" Building tech equality, e.g. Hive is the same as Lair and Hatchery \"\"\"",
"return_list",
"=",
"[",
"]",
"for",
"tech_alias",
"in",
"self",
".",
"_proto",
... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | UnitTypeData.unit_alias | Building type equality, e.g. FlyingOrbitalCommand is the same as OrbitalCommand | sc2/game_data.py | def unit_alias(self) -> Optional[UnitTypeId]:
""" Building type equality, e.g. FlyingOrbitalCommand is the same as OrbitalCommand """
if self._proto.unit_alias == 0:
return None
if self._proto.unit_alias not in self._game_data.units:
return None
""" For flying Orb... | def unit_alias(self) -> Optional[UnitTypeId]:
""" Building type equality, e.g. FlyingOrbitalCommand is the same as OrbitalCommand """
if self._proto.unit_alias == 0:
return None
if self._proto.unit_alias not in self._game_data.units:
return None
""" For flying Orb... | [
"Building",
"type",
"equality",
"e",
".",
"g",
".",
"FlyingOrbitalCommand",
"is",
"the",
"same",
"as",
"OrbitalCommand"
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/game_data.py#L200-L207 | [
"def",
"unit_alias",
"(",
"self",
")",
"->",
"Optional",
"[",
"UnitTypeId",
"]",
":",
"if",
"self",
".",
"_proto",
".",
"unit_alias",
"==",
"0",
":",
"return",
"None",
"if",
"self",
".",
"_proto",
".",
"unit_alias",
"not",
"in",
"self",
".",
"_game_dat... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | UnitTypeData.cost_zerg_corrected | This returns 25 for extractor and 200 for spawning pool instead of 75 and 250 respectively | sc2/game_data.py | def cost_zerg_corrected(self) -> "Cost":
""" This returns 25 for extractor and 200 for spawning pool instead of 75 and 250 respectively """
if self.race == Race.Zerg and Attribute.Structure.value in self.attributes:
# a = self._game_data.units(UnitTypeId.ZERGLING)
# print(a)
... | def cost_zerg_corrected(self) -> "Cost":
""" This returns 25 for extractor and 200 for spawning pool instead of 75 and 250 respectively """
if self.race == Race.Zerg and Attribute.Structure.value in self.attributes:
# a = self._game_data.units(UnitTypeId.ZERGLING)
# print(a)
... | [
"This",
"returns",
"25",
"for",
"extractor",
"and",
"200",
"for",
"spawning",
"pool",
"instead",
"of",
"75",
"and",
"250",
"respectively"
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/game_data.py#L222-L234 | [
"def",
"cost_zerg_corrected",
"(",
"self",
")",
"->",
"\"Cost\"",
":",
"if",
"self",
".",
"race",
"==",
"Race",
".",
"Zerg",
"and",
"Attribute",
".",
"Structure",
".",
"value",
"in",
"self",
".",
"attributes",
":",
"# a = self._game_data.units(UnitTypeId.ZERGLIN... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | UnitTypeData.morph_cost | This returns 150 minerals for OrbitalCommand instead of 550 | sc2/game_data.py | def morph_cost(self) -> Optional["Cost"]:
""" This returns 150 minerals for OrbitalCommand instead of 550 """
# Fix for BARRACKSREACTOR which has tech alias [REACTOR] which has (0, 0) cost
if self.tech_alias is None or self.tech_alias[0] in {UnitTypeId.TECHLAB, UnitTypeId.REACTOR}:
r... | def morph_cost(self) -> Optional["Cost"]:
""" This returns 150 minerals for OrbitalCommand instead of 550 """
# Fix for BARRACKSREACTOR which has tech alias [REACTOR] which has (0, 0) cost
if self.tech_alias is None or self.tech_alias[0] in {UnitTypeId.TECHLAB, UnitTypeId.REACTOR}:
r... | [
"This",
"returns",
"150",
"minerals",
"for",
"OrbitalCommand",
"instead",
"of",
"550"
] | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/game_data.py#L237-L249 | [
"def",
"morph_cost",
"(",
"self",
")",
"->",
"Optional",
"[",
"\"Cost\"",
"]",
":",
"# Fix for BARRACKSREACTOR which has tech alias [REACTOR] which has (0, 0) cost",
"if",
"self",
".",
"tech_alias",
"is",
"None",
"or",
"self",
".",
"tech_alias",
"[",
"0",
"]",
"in",... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | property_cache_once_per_frame | This decorator caches the return value for one game loop, then clears it if it is accessed in a different game loop
Only works on properties of the bot object because it requires access to self.state.game_loop | sc2/cache.py | def property_cache_once_per_frame(f):
""" This decorator caches the return value for one game loop, then clears it if it is accessed in a different game loop
Only works on properties of the bot object because it requires access to self.state.game_loop """
f.frame = -1
f.cache = None
@wraps(f)
d... | def property_cache_once_per_frame(f):
""" This decorator caches the return value for one game loop, then clears it if it is accessed in a different game loop
Only works on properties of the bot object because it requires access to self.state.game_loop """
f.frame = -1
f.cache = None
@wraps(f)
d... | [
"This",
"decorator",
"caches",
"the",
"return",
"value",
"for",
"one",
"game",
"loop",
"then",
"clears",
"it",
"if",
"it",
"is",
"accessed",
"in",
"a",
"different",
"game",
"loop",
"Only",
"works",
"on",
"properties",
"of",
"the",
"bot",
"object",
"because... | Dentosal/python-sc2 | python | https://github.com/Dentosal/python-sc2/blob/608bd25f04e89d39cef68b40101d8e9a8a7f1634/sc2/cache.py#L28-L43 | [
"def",
"property_cache_once_per_frame",
"(",
"f",
")",
":",
"f",
".",
"frame",
"=",
"-",
"1",
"f",
".",
"cache",
"=",
"None",
"@",
"wraps",
"(",
"f",
")",
"def",
"inner",
"(",
"self",
")",
":",
"if",
"f",
".",
"frame",
"!=",
"self",
".",
"state",... | 608bd25f04e89d39cef68b40101d8e9a8a7f1634 |
train | AndroAuto.go | Launch the analysis.
this will start a total of `max_fetcher` threads. | androguard/core/analysis/auto.py | def go(self):
"""
Launch the analysis.
this will start a total of `max_fetcher` threads.
"""
myandro = self.settings["my"]
def worker(idx, q):
"""
Worker Thread
"""
l.debug("Running worker-%d" % idx)
while Tru... | def go(self):
"""
Launch the analysis.
this will start a total of `max_fetcher` threads.
"""
myandro = self.settings["my"]
def worker(idx, q):
"""
Worker Thread
"""
l.debug("Running worker-%d" % idx)
while Tru... | [
"Launch",
"the",
"analysis",
"."
] | androguard/androguard | python | https://github.com/androguard/androguard/blob/984c0d981be2950cf0451e484f7b0d4d53bc4911/androguard/core/analysis/auto.py#L95-L191 | [
"def",
"go",
"(",
"self",
")",
":",
"myandro",
"=",
"self",
".",
"settings",
"[",
"\"my\"",
"]",
"def",
"worker",
"(",
"idx",
",",
"q",
")",
":",
"\"\"\"\n Worker Thread\n \"\"\"",
"l",
".",
"debug",
"(",
"\"Running worker-%d\"",
"%",
"... | 984c0d981be2950cf0451e484f7b0d4d53bc4911 |
train | DefaultAndroAnalysis.filter_file | This method is called in order to filer a specific app
:param log: an object which corresponds to a unique app
:param bytes fileraw: the raw file as bytes
:rtype: a tuple with 2 elements, the return value (boolean) if it is necessary to
continue the analysis and the file type | androguard/core/analysis/auto.py | def filter_file(self, log, fileraw):
"""
This method is called in order to filer a specific app
:param log: an object which corresponds to a unique app
:param bytes fileraw: the raw file as bytes
:rtype: a tuple with 2 elements, the return value (boolean) if it is necessary to
... | def filter_file(self, log, fileraw):
"""
This method is called in order to filer a specific app
:param log: an object which corresponds to a unique app
:param bytes fileraw: the raw file as bytes
:rtype: a tuple with 2 elements, the return value (boolean) if it is necessary to
... | [
"This",
"method",
"is",
"called",
"in",
"order",
"to",
"filer",
"a",
"specific",
"app"
] | androguard/androguard | python | https://github.com/androguard/androguard/blob/984c0d981be2950cf0451e484f7b0d4d53bc4911/androguard/core/analysis/auto.py#L224-L236 | [
"def",
"filter_file",
"(",
"self",
",",
"log",
",",
"fileraw",
")",
":",
"file_type",
"=",
"androconf",
".",
"is_android_raw",
"(",
"fileraw",
")",
"if",
"file_type",
"in",
"[",
"\"APK\"",
",",
"\"DEX\"",
",",
"\"DEY\"",
",",
"\"AXML\"",
",",
"\"ARSC\"",
... | 984c0d981be2950cf0451e484f7b0d4d53bc4911 |
train | DefaultAndroAnalysis.create_adex | This method is called in order to create an Analysis object
:param log: an object which corresponds to a unique app
:param androguard.core.bytecodes.dvm.DalvikVMFormat dexobj: a :class:`DalvikVMFormat` object
:rytpe: a :class:`~androguard.core.analysis.analysis.Analysis` object | androguard/core/analysis/auto.py | def create_adex(self, log, dexobj):
"""
This method is called in order to create an Analysis object
:param log: an object which corresponds to a unique app
:param androguard.core.bytecodes.dvm.DalvikVMFormat dexobj: a :class:`DalvikVMFormat` object
:rytpe: a :class:`~androguard... | def create_adex(self, log, dexobj):
"""
This method is called in order to create an Analysis object
:param log: an object which corresponds to a unique app
:param androguard.core.bytecodes.dvm.DalvikVMFormat dexobj: a :class:`DalvikVMFormat` object
:rytpe: a :class:`~androguard... | [
"This",
"method",
"is",
"called",
"in",
"order",
"to",
"create",
"an",
"Analysis",
"object"
] | androguard/androguard | python | https://github.com/androguard/androguard/blob/984c0d981be2950cf0451e484f7b0d4d53bc4911/androguard/core/analysis/auto.py#L292-L303 | [
"def",
"create_adex",
"(",
"self",
",",
"log",
",",
"dexobj",
")",
":",
"vm_analysis",
"=",
"analysis",
".",
"Analysis",
"(",
"dexobj",
")",
"vm_analysis",
".",
"create_xref",
"(",
")",
"return",
"vm_analysis"
] | 984c0d981be2950cf0451e484f7b0d4d53bc4911 |
train | build_path | Build the path from node1 to node2.
The path is composed of all the nodes between node1 and node2,
node1 excluded. Although if there is a loop starting from node1, it will be
included in the path. | androguard/decompiler/dad/util.py | def build_path(graph, node1, node2, path=None):
"""
Build the path from node1 to node2.
The path is composed of all the nodes between node1 and node2,
node1 excluded. Although if there is a loop starting from node1, it will be
included in the path.
"""
if path is None:
path = []
... | def build_path(graph, node1, node2, path=None):
"""
Build the path from node1 to node2.
The path is composed of all the nodes between node1 and node2,
node1 excluded. Although if there is a loop starting from node1, it will be
included in the path.
"""
if path is None:
path = []
... | [
"Build",
"the",
"path",
"from",
"node1",
"to",
"node2",
".",
"The",
"path",
"is",
"composed",
"of",
"all",
"the",
"nodes",
"between",
"node1",
"and",
"node2",
"node1",
"excluded",
".",
"Although",
"if",
"there",
"is",
"a",
"loop",
"starting",
"from",
"no... | androguard/androguard | python | https://github.com/androguard/androguard/blob/984c0d981be2950cf0451e484f7b0d4d53bc4911/androguard/decompiler/dad/util.py#L100-L116 | [
"def",
"build_path",
"(",
"graph",
",",
"node1",
",",
"node2",
",",
"path",
"=",
"None",
")",
":",
"if",
"path",
"is",
"None",
":",
"path",
"=",
"[",
"]",
"if",
"node1",
"is",
"node2",
":",
"return",
"path",
"path",
".",
"append",
"(",
"node2",
"... | 984c0d981be2950cf0451e484f7b0d4d53bc4911 |
train | merge_inner | Merge the inner class(es) of a class:
e.g class A { ... } class A$foo{ ... } class A$bar{ ... }
==> class A { class foo{...} class bar{...} ... } | androguard/decompiler/dad/util.py | def merge_inner(clsdict):
"""
Merge the inner class(es) of a class:
e.g class A { ... } class A$foo{ ... } class A$bar{ ... }
==> class A { class foo{...} class bar{...} ... }
"""
samelist = False
done = {}
while not samelist:
samelist = True
classlist = list(clsdict.keys... | def merge_inner(clsdict):
"""
Merge the inner class(es) of a class:
e.g class A { ... } class A$foo{ ... } class A$bar{ ... }
==> class A { class foo{...} class bar{...} ... }
"""
samelist = False
done = {}
while not samelist:
samelist = True
classlist = list(clsdict.keys... | [
"Merge",
"the",
"inner",
"class",
"(",
"es",
")",
"of",
"a",
"class",
":",
"e",
".",
"g",
"class",
"A",
"{",
"...",
"}",
"class",
"A$foo",
"{",
"...",
"}",
"class",
"A$bar",
"{",
"...",
"}",
"==",
">",
"class",
"A",
"{",
"class",
"foo",
"{",
... | androguard/androguard | python | https://github.com/androguard/androguard/blob/984c0d981be2950cf0451e484f7b0d4d53bc4911/androguard/decompiler/dad/util.py#L130-L160 | [
"def",
"merge_inner",
"(",
"clsdict",
")",
":",
"samelist",
"=",
"False",
"done",
"=",
"{",
"}",
"while",
"not",
"samelist",
":",
"samelist",
"=",
"True",
"classlist",
"=",
"list",
"(",
"clsdict",
".",
"keys",
"(",
")",
")",
"for",
"classname",
"in",
... | 984c0d981be2950cf0451e484f7b0d4d53bc4911 |
train | get_type | Retrieve the java type of a descriptor (e.g : I) | androguard/decompiler/dad/util.py | def get_type(atype, size=None):
"""
Retrieve the java type of a descriptor (e.g : I)
"""
res = TYPE_DESCRIPTOR.get(atype)
if res is None:
if atype[0] == 'L':
if atype.startswith('Ljava/lang'):
res = atype[1:-1].lstrip('java/lang/').replace('/', '.')
el... | def get_type(atype, size=None):
"""
Retrieve the java type of a descriptor (e.g : I)
"""
res = TYPE_DESCRIPTOR.get(atype)
if res is None:
if atype[0] == 'L':
if atype.startswith('Ljava/lang'):
res = atype[1:-1].lstrip('java/lang/').replace('/', '.')
el... | [
"Retrieve",
"the",
"java",
"type",
"of",
"a",
"descriptor",
"(",
"e",
".",
"g",
":",
"I",
")"
] | androguard/androguard | python | https://github.com/androguard/androguard/blob/984c0d981be2950cf0451e484f7b0d4d53bc4911/androguard/decompiler/dad/util.py#L170-L189 | [
"def",
"get_type",
"(",
"atype",
",",
"size",
"=",
"None",
")",
":",
"res",
"=",
"TYPE_DESCRIPTOR",
".",
"get",
"(",
"atype",
")",
"if",
"res",
"is",
"None",
":",
"if",
"atype",
"[",
"0",
"]",
"==",
"'L'",
":",
"if",
"atype",
".",
"startswith",
"... | 984c0d981be2950cf0451e484f7b0d4d53bc4911 |
train | get_params_type | Return the parameters type of a descriptor (e.g (IC)V) | androguard/decompiler/dad/util.py | def get_params_type(descriptor):
"""
Return the parameters type of a descriptor (e.g (IC)V)
"""
params = descriptor.split(')')[0][1:].split()
if params:
return [param for param in params]
return [] | def get_params_type(descriptor):
"""
Return the parameters type of a descriptor (e.g (IC)V)
"""
params = descriptor.split(')')[0][1:].split()
if params:
return [param for param in params]
return [] | [
"Return",
"the",
"parameters",
"type",
"of",
"a",
"descriptor",
"(",
"e",
".",
"g",
"(",
"IC",
")",
"V",
")"
] | androguard/androguard | python | https://github.com/androguard/androguard/blob/984c0d981be2950cf0451e484f7b0d4d53bc4911/androguard/decompiler/dad/util.py#L192-L199 | [
"def",
"get_params_type",
"(",
"descriptor",
")",
":",
"params",
"=",
"descriptor",
".",
"split",
"(",
"')'",
")",
"[",
"0",
"]",
"[",
"1",
":",
"]",
".",
"split",
"(",
")",
"if",
"params",
":",
"return",
"[",
"param",
"for",
"param",
"in",
"params... | 984c0d981be2950cf0451e484f7b0d4d53bc4911 |
train | create_png | Creates a PNG from a given :class:`~androguard.decompiler.dad.graph.Graph`.
:param str cls_name: name of the class
:param str meth_name: name of the method
:param androguard.decompiler.dad.graph.Graph graph:
:param str dir_name: output directory | androguard/decompiler/dad/util.py | def create_png(cls_name, meth_name, graph, dir_name='graphs2'):
"""
Creates a PNG from a given :class:`~androguard.decompiler.dad.graph.Graph`.
:param str cls_name: name of the class
:param str meth_name: name of the method
:param androguard.decompiler.dad.graph.Graph graph:
:param str dir_name... | def create_png(cls_name, meth_name, graph, dir_name='graphs2'):
"""
Creates a PNG from a given :class:`~androguard.decompiler.dad.graph.Graph`.
:param str cls_name: name of the class
:param str meth_name: name of the method
:param androguard.decompiler.dad.graph.Graph graph:
:param str dir_name... | [
"Creates",
"a",
"PNG",
"from",
"a",
"given",
":",
"class",
":",
"~androguard",
".",
"decompiler",
".",
"dad",
".",
"graph",
".",
"Graph",
"."
] | androguard/androguard | python | https://github.com/androguard/androguard/blob/984c0d981be2950cf0451e484f7b0d4d53bc4911/androguard/decompiler/dad/util.py#L202-L213 | [
"def",
"create_png",
"(",
"cls_name",
",",
"meth_name",
",",
"graph",
",",
"dir_name",
"=",
"'graphs2'",
")",
":",
"m_name",
"=",
"''",
".",
"join",
"(",
"x",
"for",
"x",
"in",
"meth_name",
"if",
"x",
".",
"isalnum",
"(",
")",
")",
"name",
"=",
"''... | 984c0d981be2950cf0451e484f7b0d4d53bc4911 |
train | read | Open and read a file
:param filename: filename to open and read
:param binary: True if the file should be read as binary
:return: bytes if binary is True, str otherwise | androguard/util.py | def read(filename, binary=True):
"""
Open and read a file
:param filename: filename to open and read
:param binary: True if the file should be read as binary
:return: bytes if binary is True, str otherwise
"""
with open(filename, 'rb' if binary else 'r') as f:
return f.read() | def read(filename, binary=True):
"""
Open and read a file
:param filename: filename to open and read
:param binary: True if the file should be read as binary
:return: bytes if binary is True, str otherwise
"""
with open(filename, 'rb' if binary else 'r') as f:
return f.read() | [
"Open",
"and",
"read",
"a",
"file"
] | androguard/androguard | python | https://github.com/androguard/androguard/blob/984c0d981be2950cf0451e484f7b0d4d53bc4911/androguard/util.py#L5-L14 | [
"def",
"read",
"(",
"filename",
",",
"binary",
"=",
"True",
")",
":",
"with",
"open",
"(",
"filename",
",",
"'rb'",
"if",
"binary",
"else",
"'r'",
")",
"as",
"f",
":",
"return",
"f",
".",
"read",
"(",
")"
] | 984c0d981be2950cf0451e484f7b0d4d53bc4911 |
train | get_certificate_name_string | Format the Name type of a X509 Certificate in a human readable form.
:param name: Name object to return the DN from
:param short: Use short form (default: False)
:param delimiter: Delimiter string or character between two parts (default: ', ')
:type name: dict or :class:`asn1crypto.x509.Name`
:typ... | androguard/util.py | def get_certificate_name_string(name, short=False, delimiter=', '):
"""
Format the Name type of a X509 Certificate in a human readable form.
:param name: Name object to return the DN from
:param short: Use short form (default: False)
:param delimiter: Delimiter string or character between two parts... | def get_certificate_name_string(name, short=False, delimiter=', '):
"""
Format the Name type of a X509 Certificate in a human readable form.
:param name: Name object to return the DN from
:param short: Use short form (default: False)
:param delimiter: Delimiter string or character between two parts... | [
"Format",
"the",
"Name",
"type",
"of",
"a",
"X509",
"Certificate",
"in",
"a",
"human",
"readable",
"form",
"."
] | androguard/androguard | python | https://github.com/androguard/androguard/blob/984c0d981be2950cf0451e484f7b0d4d53bc4911/androguard/util.py#L17-L61 | [
"def",
"get_certificate_name_string",
"(",
"name",
",",
"short",
"=",
"False",
",",
"delimiter",
"=",
"', '",
")",
":",
"if",
"isinstance",
"(",
"name",
",",
"asn1crypto",
".",
"x509",
".",
"Name",
")",
":",
"name",
"=",
"name",
".",
"native",
"# For the... | 984c0d981be2950cf0451e484f7b0d4d53bc4911 |
train | QColorButton.onColorPicker | Show color-picker dialog to select color.
Qt will use the native dialog by default. | androguard/gui/HexViewMode.py | def onColorPicker(self):
"""
Show color-picker dialog to select color.
Qt will use the native dialog by default.
"""
dlg = QtGui.QColorDialog(QtGui.QColor(self._color), None)
# if self._color:
# dlg.setCurrentColor(QtGui.QColor(self._color))
if dlg.... | def onColorPicker(self):
"""
Show color-picker dialog to select color.
Qt will use the native dialog by default.
"""
dlg = QtGui.QColorDialog(QtGui.QColor(self._color), None)
# if self._color:
# dlg.setCurrentColor(QtGui.QColor(self._color))
if dlg.... | [
"Show",
"color",
"-",
"picker",
"dialog",
"to",
"select",
"color",
"."
] | androguard/androguard | python | https://github.com/androguard/androguard/blob/984c0d981be2950cf0451e484f7b0d4d53bc4911/androguard/gui/HexViewMode.py#L955-L968 | [
"def",
"onColorPicker",
"(",
"self",
")",
":",
"dlg",
"=",
"QtGui",
".",
"QColorDialog",
"(",
"QtGui",
".",
"QColor",
"(",
"self",
".",
"_color",
")",
",",
"None",
")",
"# if self._color:",
"# dlg.setCurrentColor(QtGui.QColor(self._color))",
"if",
"dlg",
".",... | 984c0d981be2950cf0451e484f7b0d4d53bc4911 |
train | AnalyzeAPK | Analyze an android application and setup all stuff for a more quickly
analysis!
If session is None, no session is used at all. This is the default
behaviour.
If you like to continue your work later, it might be a good idea to use a
session.
A default session can be created by using :meth:`~get_d... | androguard/misc.py | def AnalyzeAPK(_file, session=None, raw=False):
"""
Analyze an android application and setup all stuff for a more quickly
analysis!
If session is None, no session is used at all. This is the default
behaviour.
If you like to continue your work later, it might be a good idea to use a
session.... | def AnalyzeAPK(_file, session=None, raw=False):
"""
Analyze an android application and setup all stuff for a more quickly
analysis!
If session is None, no session is used at all. This is the default
behaviour.
If you like to continue your work later, it might be a good idea to use a
session.... | [
"Analyze",
"an",
"android",
"application",
"and",
"setup",
"all",
"stuff",
"for",
"a",
"more",
"quickly",
"analysis!",
"If",
"session",
"is",
"None",
"no",
"session",
"is",
"used",
"at",
"all",
".",
"This",
"is",
"the",
"default",
"behaviour",
".",
"If",
... | androguard/androguard | python | https://github.com/androguard/androguard/blob/984c0d981be2950cf0451e484f7b0d4d53bc4911/androguard/misc.py#L31-L77 | [
"def",
"AnalyzeAPK",
"(",
"_file",
",",
"session",
"=",
"None",
",",
"raw",
"=",
"False",
")",
":",
"log",
".",
"debug",
"(",
"\"AnalyzeAPK\"",
")",
"if",
"session",
":",
"log",
".",
"debug",
"(",
"\"Using existing session {}\"",
".",
"format",
"(",
"ses... | 984c0d981be2950cf0451e484f7b0d4d53bc4911 |
train | AnalyzeDex | Analyze an android dex file and setup all stuff for a more quickly analysis !
:param filename: the filename of the android dex file or a buffer which represents the dex file
:type filename: string
:param session: A session (Default None)
:rtype: return a tuple of (sha256hash, :class:`DalvikVMFormat`, ... | androguard/misc.py | def AnalyzeDex(filename, session=None):
"""
Analyze an android dex file and setup all stuff for a more quickly analysis !
:param filename: the filename of the android dex file or a buffer which represents the dex file
:type filename: string
:param session: A session (Default None)
:rtype: retu... | def AnalyzeDex(filename, session=None):
"""
Analyze an android dex file and setup all stuff for a more quickly analysis !
:param filename: the filename of the android dex file or a buffer which represents the dex file
:type filename: string
:param session: A session (Default None)
:rtype: retu... | [
"Analyze",
"an",
"android",
"dex",
"file",
"and",
"setup",
"all",
"stuff",
"for",
"a",
"more",
"quickly",
"analysis",
"!"
] | androguard/androguard | python | https://github.com/androguard/androguard/blob/984c0d981be2950cf0451e484f7b0d4d53bc4911/androguard/misc.py#L80-L98 | [
"def",
"AnalyzeDex",
"(",
"filename",
",",
"session",
"=",
"None",
")",
":",
"log",
".",
"debug",
"(",
"\"AnalyzeDex\"",
")",
"if",
"not",
"session",
":",
"session",
"=",
"get_default_session",
"(",
")",
"with",
"open",
"(",
"filename",
",",
"\"rb\"",
")... | 984c0d981be2950cf0451e484f7b0d4d53bc4911 |
train | AnalyzeODex | Analyze an android odex file and setup all stuff for a more quickly analysis !
:param filename: the filename of the android dex file or a buffer which represents the dex file
:type filename: string
:param session: The Androguard Session to add the ODex to (default: None)
:rtype: return a tuple of (sha... | androguard/misc.py | def AnalyzeODex(filename, session=None):
"""
Analyze an android odex file and setup all stuff for a more quickly analysis !
:param filename: the filename of the android dex file or a buffer which represents the dex file
:type filename: string
:param session: The Androguard Session to add the ODex t... | def AnalyzeODex(filename, session=None):
"""
Analyze an android odex file and setup all stuff for a more quickly analysis !
:param filename: the filename of the android dex file or a buffer which represents the dex file
:type filename: string
:param session: The Androguard Session to add the ODex t... | [
"Analyze",
"an",
"android",
"odex",
"file",
"and",
"setup",
"all",
"stuff",
"for",
"a",
"more",
"quickly",
"analysis",
"!"
] | androguard/androguard | python | https://github.com/androguard/androguard/blob/984c0d981be2950cf0451e484f7b0d4d53bc4911/androguard/misc.py#L101-L119 | [
"def",
"AnalyzeODex",
"(",
"filename",
",",
"session",
"=",
"None",
")",
":",
"log",
".",
"debug",
"(",
"\"AnalyzeODex\"",
")",
"if",
"not",
"session",
":",
"session",
"=",
"get_default_session",
"(",
")",
"with",
"open",
"(",
"filename",
",",
"\"rb\"",
... | 984c0d981be2950cf0451e484f7b0d4d53bc4911 |
train | RunDecompiler | Run the decompiler on a specific analysis
:param d: the DalvikVMFormat object
:type d: :class:`DalvikVMFormat` object
:param dx: the analysis of the format
:type dx: :class:`VMAnalysis` object
:param decompiler: the type of decompiler to use ("dad", "dex2jad", "ded")
:type decompiler: string | androguard/misc.py | def RunDecompiler(d, dx, decompiler_name):
"""
Run the decompiler on a specific analysis
:param d: the DalvikVMFormat object
:type d: :class:`DalvikVMFormat` object
:param dx: the analysis of the format
:type dx: :class:`VMAnalysis` object
:param decompiler: the type of decompiler to use ("... | def RunDecompiler(d, dx, decompiler_name):
"""
Run the decompiler on a specific analysis
:param d: the DalvikVMFormat object
:type d: :class:`DalvikVMFormat` object
:param dx: the analysis of the format
:type dx: :class:`VMAnalysis` object
:param decompiler: the type of decompiler to use ("... | [
"Run",
"the",
"decompiler",
"on",
"a",
"specific",
"analysis"
] | androguard/androguard | python | https://github.com/androguard/androguard/blob/984c0d981be2950cf0451e484f7b0d4d53bc4911/androguard/misc.py#L122-L159 | [
"def",
"RunDecompiler",
"(",
"d",
",",
"dx",
",",
"decompiler_name",
")",
":",
"if",
"decompiler_name",
"is",
"not",
"None",
":",
"log",
".",
"debug",
"(",
"\"Decompiler ...\"",
")",
"decompiler_name",
"=",
"decompiler_name",
".",
"lower",
"(",
")",
"# TODO ... | 984c0d981be2950cf0451e484f7b0d4d53bc4911 |
train | sign_apk | Use jarsigner to sign an APK file.
:param filename: APK file on disk to sign (path)
:param keystore: path to keystore
:param storepass: your keystorage passphrase | androguard/misc.py | def sign_apk(filename, keystore, storepass):
"""
Use jarsigner to sign an APK file.
:param filename: APK file on disk to sign (path)
:param keystore: path to keystore
:param storepass: your keystorage passphrase
"""
from subprocess import Popen, PIPE, STDOUT
# TODO use apksigner instead... | def sign_apk(filename, keystore, storepass):
"""
Use jarsigner to sign an APK file.
:param filename: APK file on disk to sign (path)
:param keystore: path to keystore
:param storepass: your keystorage passphrase
"""
from subprocess import Popen, PIPE, STDOUT
# TODO use apksigner instead... | [
"Use",
"jarsigner",
"to",
"sign",
"an",
"APK",
"file",
"."
] | androguard/androguard | python | https://github.com/androguard/androguard/blob/984c0d981be2950cf0451e484f7b0d4d53bc4911/androguard/misc.py#L162-L177 | [
"def",
"sign_apk",
"(",
"filename",
",",
"keystore",
",",
"storepass",
")",
":",
"from",
"subprocess",
"import",
"Popen",
",",
"PIPE",
",",
"STDOUT",
"# TODO use apksigner instead of jarsigner",
"cmd",
"=",
"Popen",
"(",
"[",
"androconf",
".",
"CONF",
"[",
"\"... | 984c0d981be2950cf0451e484f7b0d4d53bc4911 |
train | clean_file_name | Return a filename version, which has no characters in it which are forbidden.
On Windows these are for example <, /, ?, ...
The intention of this function is to allow distribution of files to different OSes.
:param filename: string to clean
:param unique: check if the filename is already taken and app... | androguard/misc.py | def clean_file_name(filename, unique=True, replace="_", force_nt=False):
"""
Return a filename version, which has no characters in it which are forbidden.
On Windows these are for example <, /, ?, ...
The intention of this function is to allow distribution of files to different OSes.
:param filena... | def clean_file_name(filename, unique=True, replace="_", force_nt=False):
"""
Return a filename version, which has no characters in it which are forbidden.
On Windows these are for example <, /, ?, ...
The intention of this function is to allow distribution of files to different OSes.
:param filena... | [
"Return",
"a",
"filename",
"version",
"which",
"has",
"no",
"characters",
"in",
"it",
"which",
"are",
"forbidden",
".",
"On",
"Windows",
"these",
"are",
"for",
"example",
"<",
"/",
"?",
"..."
] | androguard/androguard | python | https://github.com/androguard/androguard/blob/984c0d981be2950cf0451e484f7b0d4d53bc4911/androguard/misc.py#L180-L237 | [
"def",
"clean_file_name",
"(",
"filename",
",",
"unique",
"=",
"True",
",",
"replace",
"=",
"\"_\"",
",",
"force_nt",
"=",
"False",
")",
":",
"if",
"re",
".",
"match",
"(",
"r'[<>:\"/\\\\|?* .\\x00-\\x1f]'",
",",
"replace",
")",
":",
"raise",
"ValueError",
... | 984c0d981be2950cf0451e484f7b0d4d53bc4911 |
train | load_permissions | Load the Permissions for the given apilevel.
The permissions lists are generated using this tool: https://github.com/U039b/aosp_permissions_extraction
Has a fallback to select the maximum or minimal available API level.
For example, if 28 is requested but only 26 is available, 26 is returned.
If 5 is ... | androguard/core/api_specific_resources/__init__.py | def load_permissions(apilevel, permtype='permissions'):
"""
Load the Permissions for the given apilevel.
The permissions lists are generated using this tool: https://github.com/U039b/aosp_permissions_extraction
Has a fallback to select the maximum or minimal available API level.
For example, if 28... | def load_permissions(apilevel, permtype='permissions'):
"""
Load the Permissions for the given apilevel.
The permissions lists are generated using this tool: https://github.com/U039b/aosp_permissions_extraction
Has a fallback to select the maximum or minimal available API level.
For example, if 28... | [
"Load",
"the",
"Permissions",
"for",
"the",
"given",
"apilevel",
"."
] | androguard/androguard | python | https://github.com/androguard/androguard/blob/984c0d981be2950cf0451e484f7b0d4d53bc4911/androguard/core/api_specific_resources/__init__.py#L13-L65 | [
"def",
"load_permissions",
"(",
"apilevel",
",",
"permtype",
"=",
"'permissions'",
")",
":",
"if",
"permtype",
"not",
"in",
"[",
"'permissions'",
",",
"'groups'",
"]",
":",
"raise",
"ValueError",
"(",
"\"The type of permission list is not known.\"",
")",
"# Usually ... | 984c0d981be2950cf0451e484f7b0d4d53bc4911 |
train | load_permission_mappings | Load the API/Permission mapping for the requested API level.
If the requetsed level was not found, None is returned.
:param apilevel: integer value of the API level, i.e. 24 for Android 7.0
:return: a dictionary of {MethodSignature: [List of Permissions]} | androguard/core/api_specific_resources/__init__.py | def load_permission_mappings(apilevel):
"""
Load the API/Permission mapping for the requested API level.
If the requetsed level was not found, None is returned.
:param apilevel: integer value of the API level, i.e. 24 for Android 7.0
:return: a dictionary of {MethodSignature: [List of Permissions]}... | def load_permission_mappings(apilevel):
"""
Load the API/Permission mapping for the requested API level.
If the requetsed level was not found, None is returned.
:param apilevel: integer value of the API level, i.e. 24 for Android 7.0
:return: a dictionary of {MethodSignature: [List of Permissions]}... | [
"Load",
"the",
"API",
"/",
"Permission",
"mapping",
"for",
"the",
"requested",
"API",
"level",
".",
"If",
"the",
"requetsed",
"level",
"was",
"not",
"found",
"None",
"is",
"returned",
"."
] | androguard/androguard | python | https://github.com/androguard/androguard/blob/984c0d981be2950cf0451e484f7b0d4d53bc4911/androguard/core/api_specific_resources/__init__.py#L68-L83 | [
"def",
"load_permission_mappings",
"(",
"apilevel",
")",
":",
"root",
"=",
"os",
".",
"path",
".",
"dirname",
"(",
"os",
".",
"path",
".",
"realpath",
"(",
"__file__",
")",
")",
"permissions_file",
"=",
"os",
".",
"path",
".",
"join",
"(",
"root",
",",... | 984c0d981be2950cf0451e484f7b0d4d53bc4911 |
train | split_if_nodes | Split IfNodes in two nodes, the first node is the header node, the
second one is only composed of the jump condition. | androguard/decompiler/dad/graph.py | def split_if_nodes(graph):
"""
Split IfNodes in two nodes, the first node is the header node, the
second one is only composed of the jump condition.
"""
node_map = {n: n for n in graph}
to_update = set()
for node in graph.nodes[:]:
if node.type.is_cond:
if len(node.get_in... | def split_if_nodes(graph):
"""
Split IfNodes in two nodes, the first node is the header node, the
second one is only composed of the jump condition.
"""
node_map = {n: n for n in graph}
to_update = set()
for node in graph.nodes[:]:
if node.type.is_cond:
if len(node.get_in... | [
"Split",
"IfNodes",
"in",
"two",
"nodes",
"the",
"first",
"node",
"is",
"the",
"header",
"node",
"the",
"second",
"one",
"is",
"only",
"composed",
"of",
"the",
"jump",
"condition",
"."
] | androguard/androguard | python | https://github.com/androguard/androguard/blob/984c0d981be2950cf0451e484f7b0d4d53bc4911/androguard/decompiler/dad/graph.py#L212-L272 | [
"def",
"split_if_nodes",
"(",
"graph",
")",
":",
"node_map",
"=",
"{",
"n",
":",
"n",
"for",
"n",
"in",
"graph",
"}",
"to_update",
"=",
"set",
"(",
")",
"for",
"node",
"in",
"graph",
".",
"nodes",
"[",
":",
"]",
":",
"if",
"node",
".",
"type",
... | 984c0d981be2950cf0451e484f7b0d4d53bc4911 |
train | simplify | Simplify the CFG by merging/deleting statement nodes when possible:
If statement B follows statement A and if B has no other predecessor
besides A, then we can merge A and B into a new statement node.
We also remove nodes which do nothing except redirecting the control
flow (nodes which only contains a ... | androguard/decompiler/dad/graph.py | def simplify(graph):
"""
Simplify the CFG by merging/deleting statement nodes when possible:
If statement B follows statement A and if B has no other predecessor
besides A, then we can merge A and B into a new statement node.
We also remove nodes which do nothing except redirecting the control
f... | def simplify(graph):
"""
Simplify the CFG by merging/deleting statement nodes when possible:
If statement B follows statement A and if B has no other predecessor
besides A, then we can merge A and B into a new statement node.
We also remove nodes which do nothing except redirecting the control
f... | [
"Simplify",
"the",
"CFG",
"by",
"merging",
"/",
"deleting",
"statement",
"nodes",
"when",
"possible",
":",
"If",
"statement",
"B",
"follows",
"statement",
"A",
"and",
"if",
"B",
"has",
"no",
"other",
"predecessor",
"besides",
"A",
"then",
"we",
"can",
"mer... | androguard/androguard | python | https://github.com/androguard/androguard/blob/984c0d981be2950cf0451e484f7b0d4d53bc4911/androguard/decompiler/dad/graph.py#L275-L329 | [
"def",
"simplify",
"(",
"graph",
")",
":",
"redo",
"=",
"True",
"while",
"redo",
":",
"redo",
"=",
"False",
"node_map",
"=",
"{",
"}",
"to_update",
"=",
"set",
"(",
")",
"for",
"node",
"in",
"graph",
".",
"nodes",
"[",
":",
"]",
":",
"if",
"node"... | 984c0d981be2950cf0451e484f7b0d4d53bc4911 |
train | dom_lt | Dominator algorithm from Lengauer-Tarjan | androguard/decompiler/dad/graph.py | def dom_lt(graph):
"""Dominator algorithm from Lengauer-Tarjan"""
def _dfs(v, n):
semi[v] = n = n + 1
vertex[n] = label[v] = v
ancestor[v] = 0
for w in graph.all_sucs(v):
if not semi[w]:
parent[w] = v
n = _dfs(w, n)
pred[w]... | def dom_lt(graph):
"""Dominator algorithm from Lengauer-Tarjan"""
def _dfs(v, n):
semi[v] = n = n + 1
vertex[n] = label[v] = v
ancestor[v] = 0
for w in graph.all_sucs(v):
if not semi[w]:
parent[w] = v
n = _dfs(w, n)
pred[w]... | [
"Dominator",
"algorithm",
"from",
"Lengauer",
"-",
"Tarjan"
] | androguard/androguard | python | https://github.com/androguard/androguard/blob/984c0d981be2950cf0451e484f7b0d4d53bc4911/androguard/decompiler/dad/graph.py#L332-L392 | [
"def",
"dom_lt",
"(",
"graph",
")",
":",
"def",
"_dfs",
"(",
"v",
",",
"n",
")",
":",
"semi",
"[",
"v",
"]",
"=",
"n",
"=",
"n",
"+",
"1",
"vertex",
"[",
"n",
"]",
"=",
"label",
"[",
"v",
"]",
"=",
"v",
"ancestor",
"[",
"v",
"]",
"=",
"... | 984c0d981be2950cf0451e484f7b0d4d53bc4911 |
train | bfs | Breadth first search
Yields all nodes found from the starting point
:param start: start node | androguard/decompiler/dad/graph.py | def bfs(start):
"""
Breadth first search
Yields all nodes found from the starting point
:param start: start node
"""
to_visit = [start]
visited = {start}
while to_visit:
node = to_visit.pop(0)
yield node
if node.exception_analysis:
for _, _, exceptio... | def bfs(start):
"""
Breadth first search
Yields all nodes found from the starting point
:param start: start node
"""
to_visit = [start]
visited = {start}
while to_visit:
node = to_visit.pop(0)
yield node
if node.exception_analysis:
for _, _, exceptio... | [
"Breadth",
"first",
"search"
] | androguard/androguard | python | https://github.com/androguard/androguard/blob/984c0d981be2950cf0451e484f7b0d4d53bc4911/androguard/decompiler/dad/graph.py#L395-L416 | [
"def",
"bfs",
"(",
"start",
")",
":",
"to_visit",
"=",
"[",
"start",
"]",
"visited",
"=",
"{",
"start",
"}",
"while",
"to_visit",
":",
"node",
"=",
"to_visit",
".",
"pop",
"(",
"0",
")",
"yield",
"node",
"if",
"node",
".",
"exception_analysis",
":",
... | 984c0d981be2950cf0451e484f7b0d4d53bc4911 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.