python-sc2 icon indicating copy to clipboard operation
python-sc2 copied to clipboard

"AssertionError: Units object is empty" if all minerals have been mined

Open Saloshp opened this issue 6 years ago • 2 comments
trafficstars

https://github.com/Dentosal/python-sc2/blob/caf05aeee2e62c8e30279081ac46e630305117a8/sc2/bot_ai.py#L275

When no more mineral fields are left, an assertion exception is thrown

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/sc2/main.py", line 144, in _play_game_ai
    await ai.on_step(iteration)
  File "./main.py", line 500, in on_step
    await self.distribute_workers()
  File "/usr/local/lib/python3.7/site-packages/sc2/bot_ai.py", line 276, in distribute_workers
    mf = self.state.mineral_field.closest_to(idle_worker)
  File "/usr/local/lib/python3.7/site-packages/sc2/units.py", line 163, in closest_to
    assert self, "Units object is empty"
AssertionError: Units object is empty

Saloshp avatar Apr 28 '19 23:04 Saloshp

thank you for this report. the distribute workers function is far from optimal and mostly just to get you started without having to worry about worker micro when you start to write a bot

if you want to have something that is more polished, you will have to write your own function for this i will change this to be safe for lategame scenarios with no minerals left, but keep in mind that this function is not perfect and never will be.

tweakimp avatar Apr 30 '19 23:04 tweakimp

Fixed in https://github.com/Dentosal/python-sc2/pull/270

tweakimp avatar May 01 '19 16:05 tweakimp