Skip to content

Commit 44c3f1d

Browse files
committed
Improve archon morph test and fix already_pending for archons
1 parent 731c12c commit 44c3f1d

3 files changed

Lines changed: 43 additions & 33 deletions

File tree

sc2/bot_ai.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -842,12 +842,18 @@ def already_pending(self, unit_type: Union[UpgradeId, UnitTypeId]) -> float:
842842
amount_of_CCs_in_queue_and_production: int = self.already_pending(UnitTypeId.COMMANDCENTER)
843843
amount_of_lairs_morphing: int = self.already_pending(UnitTypeId.LAIR)
844844
845-
846845
:param unit_type:
847846
"""
848847
if isinstance(unit_type, UpgradeId):
849848
return self.already_pending_upgrade(unit_type)
850-
ability = self.game_data.units[unit_type.value].creation_ability.exact_id
849+
try:
850+
ability = self.game_data.units[unit_type.value].creation_ability.exact_id
851+
except AttributeError:
852+
# Hotfix for checking pending archons
853+
if unit_type == UnitTypeId.ARCHON:
854+
return self._abilities_all_units[0][AbilityId.ARCHON_WARP_TARGET] / 2
855+
logger.error(f"Uncaught UnitTypeId: {unit_type}")
856+
return 0
851857
return self._abilities_all_units[0][ability]
852858

853859
def worker_en_route_to_build(self, unit_type: UnitTypeId) -> float:

sc2/bot_ai_internal.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,13 @@ def _abilities_all_units(self) -> Tuple[CounterType[AbilityId], Dict[AbilityId,
273273
if self.race != Race.Terran or not unit.is_structure:
274274
# If an SCV is constructing a building, already_pending would count this structure twice
275275
# (once from the SCV order, and once from "not structure.is_ready")
276-
creation_ability: AbilityId = self.game_data.units[unit.type_id.value].creation_ability.exact_id
277-
abilities_amount[creation_ability] += 1
276+
if unit.type_id == UnitTypeId.ARCHON:
277+
# Hotfix for archons in morph state
278+
creation_ability = AbilityId.ARCHON_WARP_TARGET
279+
abilities_amount[creation_ability] += 2
280+
else:
281+
creation_ability: AbilityId = self.game_data.units[unit.type_id.value].creation_ability.exact_id
282+
abilities_amount[creation_ability] += 1
278283
max_build_progress[creation_ability] = max(
279284
max_build_progress.get(creation_ability, 0), unit.build_progress
280285
)

test/autotest_bot.py

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ def __init__(self):
3939
# There will be 20 iterations of the bot doing nothing between tests
4040
self.iteration_wait_time_between_actions = 20
4141

42-
self.scv_action_list = ["move", "patrol", "attack", "hold", "scan_move"]
43-
4442
# Variables for test_botai_actions11
4543

4644
async def on_start(self):
@@ -154,7 +152,6 @@ async def test_botai_actions1(self):
154152

155153
await self._advance_steps(2)
156154
logger.warning("Action test 01 successful.")
157-
return
158155

159156
# Test BotAI action: move all SCVs to center of map
160157
async def test_botai_actions2(self):
@@ -166,12 +163,13 @@ def temp_filter(unit: Unit):
166163
or unit.is_attacking
167164
)
168165

169-
while self.units.filter(lambda unit: temp_filter(unit)).amount < len(self.scv_action_list):
166+
scv_action_list = ["move", "patrol", "attack", "hold", "scan_move"]
167+
while self.units.filter(lambda unit: temp_filter(unit)).amount < len(scv_action_list):
170168
scv: Unit
171169
for index, scv in enumerate(self.workers):
172-
if index > len(self.scv_action_list):
170+
if index > len(scv_action_list):
173171
scv.stop()
174-
action = self.scv_action_list[index % len(self.scv_action_list)]
172+
action = scv_action_list[index % len(scv_action_list)]
175173
if action == "move":
176174
scv.move(center)
177175
elif action == "patrol":
@@ -185,7 +183,6 @@ def temp_filter(unit: Unit):
185183

186184
await self._advance_steps(2)
187185
logger.warning("Action test 02 successful.")
188-
return
189186

190187
# Test BotAI action: move some scvs to the center, some to minerals
191188
async def test_botai_actions3(self):
@@ -204,7 +201,6 @@ async def test_botai_actions3(self):
204201
await self._advance_steps(2)
205202
await self._advance_steps(2)
206203
logger.warning("Action test 03 successful.")
207-
return
208204

209205
# Test BotAI action: move all SCVs to mine minerals near townhall
210206
async def test_botai_actions4(self):
@@ -216,7 +212,6 @@ async def test_botai_actions4(self):
216212
await self._advance_steps(2)
217213
await self._advance_steps(2)
218214
logger.warning("Action test 04 successful.")
219-
return
220215

221216
# Test BotAI action: self.expand_now() which tests for get_next_expansion, select_build_worker, can_place, find_placement, build and can_afford
222217
async def test_botai_actions5(self):
@@ -241,7 +236,6 @@ async def test_botai_actions5(self):
241236

242237
await self._advance_steps(2)
243238
logger.warning("Action test 05 successful.")
244-
return
245239

246240
# Test if reaper grenade shows up in effects
247241
async def test_botai_actions6(self):
@@ -268,7 +262,6 @@ async def test_botai_actions6(self):
268262
# Wait for effectts to time out
269263
await self._advance_steps(100)
270264
logger.warning("Action test 06 successful.")
271-
return
272265

273266
# Test ravager effects
274267
async def test_botai_actions7(self):
@@ -293,7 +286,6 @@ async def test_botai_actions7(self):
293286
# Wait for effectts to time out
294287
await self._advance_steps(100)
295288
logger.warning("Action test 07 successful.")
296-
return
297289

298290
# Test if train function works on hatchery, lair, hive
299291
async def test_botai_actions8(self):
@@ -326,39 +318,47 @@ async def test_botai_actions8(self):
326318
await self.client.debug_kill_unit(townhalls | queens | pool)
327319
await self._advance_steps(2)
328320
logger.warning("Action test 08 successful.")
329-
return
330321

331322
# Morph an archon from 2 high templars
332323
async def test_botai_actions9(self):
333324
center = self.game_info.map_center
334-
target_amount = 2
335-
HTs = self.units(UnitTypeId.HIGHTEMPLAR)
336-
archons = self.units(UnitTypeId.ARCHON)
325+
await self.client.debug_create_unit(
326+
[
327+
[UnitTypeId.HIGHTEMPLAR, 1, center, 1],
328+
[UnitTypeId.DARKTEMPLAR, 1, center + Point2((5, 0)), 1],
329+
]
330+
)
331+
await self._advance_steps(4)
332+
assert self.already_pending(UnitTypeId.ARCHON) == 0
337333

338334
while 1:
339-
HTs = self.units(UnitTypeId.HIGHTEMPLAR)
340-
if HTs.amount < target_amount:
341-
await self.client.debug_create_unit([[UnitTypeId.HIGHTEMPLAR, target_amount - HTs.amount, center, 1]])
335+
for templar in self.units.of_type({UnitTypeId.HIGHTEMPLAR, UnitTypeId.DARKTEMPLAR}):
336+
templar(AbilityId.MORPH_ARCHON)
337+
338+
await self._advance_steps(4)
342339

340+
templars = self.units.of_type({UnitTypeId.HIGHTEMPLAR, UnitTypeId.DARKTEMPLAR})
341+
archons = self.units(UnitTypeId.ARCHON)
342+
if templars.amount > 0:
343+
# High templars are on their way to morph ot morph has started
344+
assert self.already_pending(UnitTypeId.ARCHON) == 1
343345
else:
344-
for ht in HTs:
345-
ht(AbilityId.MORPH_ARCHON)
346+
# Morph started
347+
assert self.already_pending(UnitTypeId.ARCHON) == archons.not_ready.amount
346348

347-
await self._advance_steps(2)
348349
# Check if condition is met
349-
HTs = self.units(UnitTypeId.HIGHTEMPLAR)
350-
archons = self.units(UnitTypeId.ARCHON)
351-
if archons.amount == 1:
350+
if archons.ready.amount == 1:
351+
assert templars.amount == 0
352+
assert self.already_pending(UnitTypeId.ARCHON) == 0
352353
break
353354

354355
# Cleanup
355356
if archons:
356357
await self.client.debug_kill_unit(archons)
357-
if HTs:
358-
await self.client.debug_kill_unit(HTs)
358+
if templars:
359+
await self.client.debug_kill_unit(templars)
359360
await self._advance_steps(2)
360361
logger.warning("Action test 09 successful.")
361-
return
362362

363363
# Morph 400 banelings from 400 lings in the same frame
364364
async def test_botai_actions10(self):
@@ -401,7 +401,6 @@ async def test_botai_actions10(self):
401401
await self.client.debug_kill_unit(lings | banes | bane_nests | bane_cocoons)
402402
await self._advance_steps(2)
403403
logger.warning("Action test 10 successful.")
404-
return
405404

406405
# Trigger anti armor missile of raven against enemy unit and check if buff was received
407406
async def test_botai_actions11(self):

0 commit comments

Comments
 (0)