Skip to content

Commit d083ca1

Browse files
committed
Merge branch 'develop' of https://github.com/BurnySc2/python-sc2 into fix_creation_ability_error
2 parents 3cf9c7d + c123c66 commit d083ca1

28 files changed

Lines changed: 164 additions & 646 deletions

.github/workflows/ci.yml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -361,12 +361,6 @@ jobs:
361361
docker exec -i my_container bash -c "poetry run coverage xml"
362362
docker cp my_container:/root/python-sc2/coverage.xml $(pwd)/coverage.xml
363363
364-
- name: Upload coverage to Codecov
365-
uses: codecov/codecov-action@v2
366-
with:
367-
token: ${{ secrets.CODECOV_TOKEN }}
368-
files: coverage.xml
369-
370364
- name: Generate html coverage files in htmlcov/ folder
371365
run: |
372366
docker exec -i my_container bash -c "poetry run coverage html"
@@ -463,7 +457,7 @@ jobs:
463457

464458
release_to_pypi:
465459
name: Pypi package release
466-
needs: [release_to_github_pages]
460+
needs: [run_test_bots, run_example_bots]
467461
runs-on: ubuntu-latest
468462
timeout-minutes: 10
469463

.pre-commit-config.yaml

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v4.2.0
3+
rev: v4.4.0
44
hooks:
55
# Check yaml files like this one and github actions if they are valid
66
- id: check-yaml
@@ -14,13 +14,13 @@ repos:
1414

1515
# Check github action workflow files
1616
- repo: https://github.com/sirosen/check-jsonschema
17-
rev: 0.14.3
17+
rev: 0.22.0
1818
hooks:
1919
- id: check-github-workflows
2020

2121
# Remove unused imports
2222
- repo: https://github.com/hadialqattan/pycln
23-
rev: v1.3.1
23+
rev: v2.1.3
2424
hooks:
2525
- id: pycln
2626
args: [--config=pyproject.toml]
@@ -33,14 +33,14 @@ repos:
3333

3434
# Sort imports
3535
- repo: https://github.com/pycqa/isort
36-
rev: 5.5.4
36+
rev: 5.12.0
3737
hooks:
3838
- id: isort
3939
files: \.(py)$
4040
args: [--settings-path=pyproject.toml]
4141

4242
- repo: https://github.com/pre-commit/pygrep-hooks
43-
rev: v1.9.0
43+
rev: v1.10.0
4444
hooks:
4545
# Check for bad code
4646
- id: python-no-eval
@@ -51,27 +51,13 @@ repos:
5151
- repo: local
5252
hooks:
5353
# Autoformat code
54-
- id: yapf-modified
55-
name: format modified python files
56-
stages: [commit]
57-
language: system
58-
entry: /bin/bash -c "poetry run yapf --in-place $(git ls-files -m '*.py')"
59-
pass_filenames: false
60-
6154
- id: yapf
6255
name: format all python files
6356
stages: [push]
6457
language: system
6558
entry: /bin/bash -c "poetry run yapf --in-place $(git ls-files '*.py')"
6659
pass_filenames: false
6760

68-
- id: pylint-modified
69-
name: pylint modified python files
70-
stages: [commit]
71-
language: system
72-
entry: /bin/bash -c "poetry run pylint $(git ls-files -m '*.py' | grep -E '(sc2)|(examples)/.*')"
73-
pass_filenames: false
74-
7561
- id: pylint
7662
name: pylint all python files
7763
stages: [push]

data/data.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

generate_dicts_from_data_json.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ def get_unit_train_build_abilities(data):
119119
AbilityId.MORPHTOBROODLORD_BROODLORD,
120120
AbilityId.MORPHZERGLINGTOBANELING_BANELING,
121121
AbilityId.MORPHTORAVAGER_RAVAGER,
122+
AbilityId.MORPHTOBANELING_BANELING,
122123
AbilityId.MORPH_LURKER,
123124
AbilityId.UPGRADETOLAIR_LAIR,
124125
AbilityId.UPGRADETOHIVE_HIVE,
@@ -430,14 +431,6 @@ def generate_redirect_abilities_dict(data: dict):
430431
_unit_data = data["Unit"]
431432
_upgrade_data = data["Upgrade"]
432433

433-
# Load pickled game data files
434-
pickled_file_path = get_map_file_path()
435-
assert pickled_file_path.is_file(), f"Could not find pickled data file {pickled_file_path}"
436-
logger.info(f"Loading pickled game data file {pickled_file_path}")
437-
with lzma.open(pickled_file_path.absolute(), "rb") as f:
438-
raw_game_data, raw_game_info, raw_observation = pickle.load(f)
439-
game_data = GameData(raw_game_data.data)
440-
441434
all_redirect_abilities: Dict[AbilityId, AbilityId] = OrderedDict2()
442435

443436
entry: dict
@@ -449,10 +442,11 @@ def generate_redirect_abilities_dict(data: dict):
449442
logger.info(f"Error with ability id value {ability_id_value}")
450443
continue
451444

452-
generic_redirect_ability_value: int = game_data.abilities[ability_id_value]._proto.remaps_to_ability_id
453-
if generic_redirect_ability_value:
454-
# Might be 0 if it has no redirect ability
455-
all_redirect_abilities[ability_id] = AbilityId(generic_redirect_ability_value)
445+
generic_redirect_ability_value = entry.get("remaps_to_ability_id", 0)
446+
if generic_redirect_ability_value == 0:
447+
# No generic ability available
448+
continue
449+
all_redirect_abilities[ability_id] = AbilityId(generic_redirect_ability_value)
456450

457451
return all_redirect_abilities
458452

poetry.lock

Lines changed: 70 additions & 184 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "burnysc2"
3-
version = "6.1.1"
3+
version = "6.3.0"
44
description = "A StarCraft II API Client for Python 3"
55
authors = ["BurnySc2 <gamingburny@gmail.com>"]
66
license = "MIT"
@@ -40,9 +40,8 @@ s2clientprotocol = "^5.0.7"
4040
scipy = "^1.7.1"
4141
protobuf = "<4.0.0"
4242

43-
[tool.poetry.dev-dependencies]
44-
codecov = "^2.1.12"
45-
coverage = "^7.0"
43+
[tool.poetry.group.dev.dependencies]
44+
coverage = "^7.2"
4645
hypothesis = "^6.23.1"
4746
matplotlib = "^3.4.3"
4847
mypy = "^0.960"

sc2/bot_ai.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,8 @@ def calculate_supply_cost(self, unit_type: UnitTypeId) -> float:
400400
:param unit_type:"""
401401
if unit_type in {UnitTypeId.ZERGLING}:
402402
return 1
403+
if unit_type in {UnitTypeId.BANELING}:
404+
return 0
403405
unit_supply_cost = self.game_data.units[unit_type.value]._proto.food_required
404406
if unit_supply_cost > 0 and unit_type in UNIT_TRAINED_FROM and len(UNIT_TRAINED_FROM[unit_type]) == 1:
405407
producer: UnitTypeId
@@ -472,11 +474,13 @@ def calculate_cost(self, item_id: Union[UnitTypeId, UpgradeId, AbilityId]) -> Co
472474
"""
473475
if isinstance(item_id, UnitTypeId):
474476
# Fix cost for reactor and techlab where the API returns 0 for both
475-
if item_id in {UnitTypeId.REACTOR, UnitTypeId.TECHLAB, UnitTypeId.ARCHON}:
477+
if item_id in {UnitTypeId.REACTOR, UnitTypeId.TECHLAB, UnitTypeId.ARCHON, UnitTypeId.BANELING}:
476478
if item_id == UnitTypeId.REACTOR:
477479
return Cost(50, 50)
478480
if item_id == UnitTypeId.TECHLAB:
479481
return Cost(50, 25)
482+
if item_id == UnitTypeId.BANELING:
483+
return Cost(25, 25)
480484
if item_id == UnitTypeId.ARCHON:
481485
return self.calculate_unit_value(UnitTypeId.ARCHON)
482486
unit_data = self.game_data.units[item_id.value]

sc2/bot_ai_internal.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,13 +186,19 @@ def _find_expansion_locations(self):
186186
]
187187
# Loop the merging process as long as we change something
188188
merged_group = True
189+
height_grid: PixelMap = self.game_info.terrain_height
189190
while merged_group:
190191
merged_group = False
191192
# Check every combination of two groups
192193
for group_a, group_b in itertools.combinations(resource_groups, 2):
193194
# Check if any pair of resource of these groups is closer than threshold together
195+
# And that they are on the same terrain level
194196
if any(
195197
resource_a.distance_to(resource_b) <= resource_spread_threshold
198+
# check if terrain height measurement at resources is within 10 units
199+
# this is since some older maps have inconsistent terrain height
200+
# tiles at certain expansion locations
201+
and abs(height_grid[resource_a.position.rounded] - height_grid[resource_b.position.rounded]) <= 10
196202
for resource_a, resource_b in itertools.product(group_a, group_b)
197203
):
198204
# Remove the single groups and add the merged group

sc2/dicts/generic_redirect_abilities.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@
119119
AbilityId.CANCEL_STARPORTADDON: AbilityId.CANCEL,
120120
AbilityId.CANCEL_STASISTRAP: AbilityId.CANCEL,
121121
AbilityId.CANCEL_VOIDRAYPRISMATICALIGNMENT: AbilityId.CANCEL,
122+
AbilityId.CHANNELSNIPE_CANCEL: AbilityId.CANCEL,
122123
AbilityId.CYBERNETICSCORERESEARCH_PROTOSSAIRARMORLEVEL1: AbilityId.RESEARCH_PROTOSSAIRARMOR,
123124
AbilityId.CYBERNETICSCORERESEARCH_PROTOSSAIRARMORLEVEL2: AbilityId.RESEARCH_PROTOSSAIRARMOR,
124125
AbilityId.CYBERNETICSCORERESEARCH_PROTOSSAIRARMORLEVEL3: AbilityId.RESEARCH_PROTOSSAIRARMOR,
@@ -128,8 +129,6 @@
128129
AbilityId.DEFILERMPBURROW_BURROWDOWN: AbilityId.BURROWDOWN,
129130
AbilityId.DEFILERMPBURROW_CANCEL: AbilityId.CANCEL,
130131
AbilityId.DEFILERMPUNBURROW_BURROWUP: AbilityId.BURROWUP,
131-
AbilityId.DUMMYABIL156_MEDIVACSPEEDBOOST: AbilityId.CANCEL,
132-
AbilityId.DUMMYABIL159_MEDIVACSPEEDBOOST: AbilityId.CANCEL,
133132
AbilityId.EFFECT_BLINK_STALKER: AbilityId.EFFECT_BLINK,
134133
AbilityId.EFFECT_MASSRECALL_MOTHERSHIPCORE: AbilityId.EFFECT_MASSRECALL,
135134
AbilityId.EFFECT_MASSRECALL_NEXUS: AbilityId.EFFECT_MASSRECALL,
@@ -192,8 +191,11 @@
192191
AbilityId.LOAD_WARPPRISM: AbilityId.LOAD,
193192
AbilityId.MERGEABLE_CANCEL: AbilityId.CANCEL,
194193
AbilityId.MORPHBACKTOGATEWAY_CANCEL: AbilityId.CANCEL,
194+
AbilityId.MORPHTOBANELING_CANCEL: AbilityId.CANCEL,
195195
AbilityId.MORPHTOCOLLAPSIBLEPURIFIERTOWERDEBRIS_CANCEL: AbilityId.CANCEL,
196+
AbilityId.MORPHTOCOLLAPSIBLEROCKTOWERDEBRISRAMPLEFTGREEN_CANCEL: AbilityId.CANCEL,
196197
AbilityId.MORPHTOCOLLAPSIBLEROCKTOWERDEBRISRAMPLEFT_CANCEL: AbilityId.CANCEL,
198+
AbilityId.MORPHTOCOLLAPSIBLEROCKTOWERDEBRISRAMPRIGHTGREEN_CANCEL: AbilityId.CANCEL,
197199
AbilityId.MORPHTOCOLLAPSIBLEROCKTOWERDEBRISRAMPRIGHT_CANCEL: AbilityId.CANCEL,
198200
AbilityId.MORPHTOCOLLAPSIBLEROCKTOWERDEBRIS_CANCEL: AbilityId.CANCEL,
199201
AbilityId.MORPHTOCOLLAPSIBLETERRANTOWERDEBRISRAMPLEFT_CANCEL: AbilityId.CANCEL,

sc2/dicts/unit_abilities.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@
124124
AbilityId.ATTACK_ATTACK, AbilityId.CORSAIRMPDISRUPTIONWEB_CORSAIRMPDISRUPTIONWEB, AbilityId.HOLDPOSITION_HOLD,
125125
AbilityId.MOVE_MOVE, AbilityId.PATROL_PATROL, AbilityId.SMART, AbilityId.STOP_STOP
126126
},
127-
UnitTypeId.CREEPTUMOR: {AbilityId.BUILD_CREEPTUMOR_TUMOR, AbilityId.SMART},
128127
UnitTypeId.CREEPTUMORBURROWED: {AbilityId.BUILD_CREEPTUMOR, AbilityId.BUILD_CREEPTUMOR_TUMOR, AbilityId.SMART},
129128
UnitTypeId.CREEPTUMORQUEEN: {AbilityId.BUILD_CREEPTUMOR_TUMOR, AbilityId.SMART},
130129
UnitTypeId.CYBERNETICSCORE: {
@@ -230,10 +229,7 @@
230229
AbilityId.EFFECT_GHOSTSNIPE, AbilityId.EMP_EMP, AbilityId.HOLDPOSITION_HOLD, AbilityId.MOVE_MOVE,
231230
AbilityId.PATROL_PATROL, AbilityId.SMART, AbilityId.STOP_STOP
232231
},
233-
UnitTypeId.GHOSTACADEMY: {
234-
AbilityId.BUILD_NUKE, AbilityId.GHOSTACADEMYRESEARCH_RESEARCHENHANCEDSHOCKWAVES,
235-
AbilityId.RESEARCH_PERSONALCLOAKING
236-
},
232+
UnitTypeId.GHOSTACADEMY: {AbilityId.BUILD_NUKE, AbilityId.RESEARCH_PERSONALCLOAKING},
237233
UnitTypeId.GHOSTNOVA: {
238234
AbilityId.ATTACK_ATTACK, AbilityId.BEHAVIOR_CLOAKON_GHOST, AbilityId.BEHAVIOR_HOLDFIREON_GHOST,
239235
AbilityId.EFFECT_GHOSTSNIPE, AbilityId.EMP_EMP, AbilityId.HOLDPOSITION_HOLD, AbilityId.MOVE_MOVE,
@@ -570,10 +566,7 @@
570566
AbilityId.BUILD_REACTOR_STARPORT, AbilityId.BUILD_TECHLAB_STARPORT, AbilityId.HOLDPOSITION_HOLD,
571567
AbilityId.LAND_STARPORT, AbilityId.MOVE_MOVE, AbilityId.PATROL_PATROL, AbilityId.SMART, AbilityId.STOP_STOP
572568
},
573-
UnitTypeId.STARPORTTECHLAB: {
574-
AbilityId.RESEARCH_BANSHEECLOAKINGFIELD, AbilityId.RESEARCH_BANSHEEHYPERFLIGHTROTORS,
575-
AbilityId.RESEARCH_RAVENCORVIDREACTOR
576-
},
569+
UnitTypeId.STARPORTTECHLAB: {AbilityId.RESEARCH_BANSHEECLOAKINGFIELD, AbilityId.RESEARCH_BANSHEEHYPERFLIGHTROTORS},
577570
UnitTypeId.SUPPLYDEPOT: {AbilityId.MORPH_SUPPLYDEPOT_LOWER},
578571
UnitTypeId.SUPPLYDEPOTLOWERED: {AbilityId.MORPH_SUPPLYDEPOT_RAISE},
579572
UnitTypeId.SWARMHOSTBURROWEDMP: {AbilityId.EFFECT_SPAWNLOCUSTS, AbilityId.SMART},
@@ -657,7 +650,7 @@
657650
},
658651
UnitTypeId.ZERGLING: {
659652
AbilityId.ATTACK_ATTACK, AbilityId.BURROWDOWN_ZERGLING, AbilityId.HOLDPOSITION_HOLD,
660-
AbilityId.MORPHZERGLINGTOBANELING_BANELING, AbilityId.MOVE_MOVE, AbilityId.PATROL_PATROL, AbilityId.SMART,
653+
AbilityId.MORPHTOBANELING_BANELING, AbilityId.MOVE_MOVE, AbilityId.PATROL_PATROL, AbilityId.SMART,
661654
AbilityId.STOP_STOP
662655
},
663656
UnitTypeId.ZERGLINGBURROWED: {AbilityId.BURROWUP_ZERGLING}

0 commit comments

Comments
 (0)