Dentosal / python-sc2

A StarCraft II bot api client library for Python 3
MIT License
585 stars 182 forks source link

ValueError: 3794 is not a valid AbilityId #283

Open wontheone1 opened 5 years ago

wontheone1 commented 5 years ago

full stacktrace

$ python3 examples/protoss/cannon_rush.py
err = 3 /opt/blizzard/buildserver/data.noindex/repositories/sc2/branches/SC2.4.9/Game/Contrib/macteam/libs/ClampCursor/Contrib/mach_override/mach_override.c:244
err = 3 /opt/blizzard/buildserver/data.noindex/repositories/sc2/branches/SC2.4.9/Game/Contrib/macteam/libs/ClampCursor/Contrib/mach_override/mach_override.c:258
err = 3 /opt/blizzard/buildserver/data.noindex/repositories/sc2/branches/SC2.4.9/Game/Contrib/macteam/libs/ClampCursor/Contrib/mach_override/mach_override.c:263
INFO:sc2.protocol:Client status changed to Status.launched (was None)
INFO:sc2.controller:Creating new game
INFO:sc2.controller:Map:     (2)CatalystLE
INFO:sc2.controller:Players: Bot(Race.Protoss, <__main__.CannonRushBot object at 0x10b8d28d0>, name='CheeseCannon'), Computer(Race.Protoss, Difficulty.Medium)
INFO:sc2.protocol:Client status changed to Status.init_game (was Status.launched)
INFO:sc2.protocol:Client status changed to Status.in_game (was None)
INFO:root:Player id: 1 (CheeseCannon)
INFO:sc2.sc2process:kill_switch: Process cleanup
INFO:sc2.sc2process:Cleaning up...
INFO:sc2.sc2process:Cleanup complete
Traceback (most recent call last):
  File "examples/protoss/cannon_rush.py", line 60, in <module>
    main()
  File "examples/protoss/cannon_rush.py", line 57, in main
    ], realtime=False)
  File "/Users/wseobseo/.local/lib/python3.7/site-packages/sc2/main.py", line 306, in run_game
    _host_game(map_settings, players, **kwargs)
  File "/Users/wseobseo/anaconda3/lib/python3.7/asyncio/base_events.py", line 568, in run_until_complete
    return future.result()
  File "/Users/wseobseo/.local/lib/python3.7/site-packages/sc2/main.py", line 233, in _host_game
    result = await _play_game(players[0], client, realtime, portconfig, step_time_limit, game_time_limit, rgb_render_config)
  File "/Users/wseobseo/.local/lib/python3.7/site-packages/sc2/main.py", line 204, in _play_game
    result = await _play_game_ai(client, player_id, player.ai, realtime, step_time_limit, game_time_limit)
  File "/Users/wseobseo/.local/lib/python3.7/site-packages/sc2/main.py", line 91, in _play_game_ai
    game_data = await client.get_game_data()
  File "/Users/wseobseo/.local/lib/python3.7/site-packages/sc2/client.py", line 143, in get_game_data
    return GameData(result.data)
  File "/Users/wseobseo/.local/lib/python3.7/site-packages/sc2/game_data.py", line 29, in __init__
    self.abilities = {a.ability_id: AbilityData(self, a) for a in data.abilities if a.ability_id in ids}
  File "/Users/wseobseo/.local/lib/python3.7/site-packages/sc2/game_data.py", line 29, in <dictcomp>
    self.abilities = {a.ability_id: AbilityData(self, a) for a in data.abilities if a.ability_id in ids}
  File "/Users/wseobseo/.local/lib/python3.7/site-packages/sc2/game_data.py", line 93, in __init__
    assert self.id != 0
  File "/Users/wseobseo/.local/lib/python3.7/site-packages/sc2/game_data.py", line 101, in id
    return AbilityId(self._proto.remaps_to_ability_id)
  File "/Users/wseobseo/anaconda3/lib/python3.7/enum.py", line 307, in __call__
    return cls.__new__(cls, value)
  File "/Users/wseobseo/anaconda3/lib/python3.7/enum.py", line 555, in __new__
    return cls._missing_(value)
  File "/Users/wseobseo/anaconda3/lib/python3.7/enum.py", line 568, in _missing_
    raise ValueError("%r is not a valid %s" % (value, cls.__name__))
ValueError: 3794 is not a valid AbilityId
ERROR:asyncio:Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x10c14b860>

my library versions

$ pip freeze | grep 'sc\?2'
s2clientprotocol==4.9.0.74071.0
sc2==0.11.1

Also, I use a touch bar MacBook Pro.

Could anybody help me ? thank you very much!

cu-rie commented 5 years ago

I have a same problem

GioPat commented 5 years ago

I solved this by adding in this ids in the file https://github.com/Dentosal/python-sc2/blob/master/sc2/ids/ability_id.py with random names. But still it will crash for other errors...I think that the package should be updated with respect to the latest version of the game.

xelaos commented 5 years ago

You can comment out : "assert self.id != 0" in game_data.py, then the game should run again.

BurnySc2 commented 5 years ago

It is a total mess right now.

Things were working well until StarCraft2 version 4.8.4. In 4.8.5, the pixelmap changed and self.state.upgrades stopped working. Thus, self.already_pending_upgrade(UPGRADEID) stopped working if the upgrade was completely researched (should return 1, but returns 0 instead). self.state.upgrades was fixed in SC2 version 4.9.0.

The master branch of this library is working for SC2 version 4.8.4, while the develop branch fixed the issues with pixelmap introduced in 4.8.5 (and is the same in 4.8.6). Pixelmaps were starting in the top left but are now starting in the bottom left, so they were flipped in y-axis. Also pixelmap values changed from bytes to bits (like pathing grid, placement grid, and in 4.9.0 also creep map).

Dentosal needs a working version for his competition https://artificial-overmind.reaktor.com which runs on (I believe) 4.7.1 because it is using this linux client https://github.com/Blizzard/s2client-proto#linux-packages and the master branch works fine for that.

However in SC2 client 4.9.0 a new bug got introduced (that was already there about half a year ago in november 2018) that you can't run 2 bots against each other, but running bot against built-in AI works (because only one SC2 client needs to run for this). So new competitions like Probots ( https://www.eschamp.com/probots-2019-2/ ) decided to also run on client version 4.8.4

TLDR: If you want to run the latest SC2 client version 4.9.0 on windows/mac: You need to download and install the develop branch (instruction here: https://github.com/Dentosal/python-sc2/issues/266 ) and go into the library installation in your python folder and do the following changes: In sc2/game_state.py you have to change self.creep: PixelMap = PixelMap(self.observation_raw.map_state.creep, mirrored=True) to self.creep: PixelMap = PixelMap(self.observation_raw.map_state.creep, in_bits=True, mirrored=True) and in sc2/game_data.py you have to remove the line assert self.id != 0.

Also you need to download generate_id_constants_from_stableid.py from here https://github.com/Dentosal/python-sc2 and let it run once (create subfolders sc2/ids first) to update the IDs that were changed once again in 4.9.0 Then copy these newly generated files into the sc2/ids/ folders of the library in your python installation.

GioPat commented 5 years ago

It is a total mess right now.

Things were working well until StarCraft2 version 4.8.4. In 4.8.5, the pixelmap changed and self.state.upgrades stopped working. Thus, self.already_pending_upgrade(UPGRADEID) stopped working if the upgrade was completely researched (should return 1, but returns 0 instead). self.state.upgrades was fixed in SC2 version 4.9.0.

The master branch of this library is working for SC2 version 4.8.4, while the develop branch fixed the issues with pixelmap introduced in 4.8.5 (and is the same in 4.8.6). Pixelmaps were starting in the top left but are now starting in the bottom left, so they were flipped in y-axis. Also pixelmap values changed from bytes to bits (like pathing grid, placement grid, and in 4.9.0 also creep map).

Dentosal needs a working version for his competition https://artificial-overmind.reaktor.com which runs on (I believe) 4.7.1 because it is using this linux client https://github.com/Blizzard/s2client-proto#linux-packages and the master branch works fine for that.

However in SC2 client 4.9.0 a new bug got introduced (that was already there about half a year ago in november 2018) that you can't run 2 bots against each other, but running bot against built-in AI works (because only one SC2 client needs to run for this). So new competitions like Probots ( https://www.eschamp.com/probots-2019-2/ ) decided to also run on client version 4.8.4

TLDR: If you want to run the latest SC2 client version 4.9.0 on windows/mac: You need to download and install the develop branch (instruction here: #266 ) and go into the library installation in your python folder and do the following changes: In sc2/game_state.py you have to change self.creep: PixelMap = PixelMap(self.observation_raw.map_state.creep, mirrored=True) to self.creep: PixelMap = PixelMap(self.observation_raw.map_state.creep, in_bits=True, mirrored=True) and in sc2/game_data.py you have to remove the line assert self.id != 0.

Also you need to download generate_id_constants_from_stableid.py from here https://github.com/Dentosal/python-sc2 and let it run once to update the IDs that were changed once again in 4.9.0 Then copy these newly generated files into the sc2/ids/ folders.

Running generate_id_constants_from_stableid.py gives me another assertion Error: UNLOADUNIT Traceback (most recent call last): File "generate_id_constants_from_stableid.py", line 143, in generate_python_code(parse_data(data)) File "generate_id_constants_from_stableid.py", line 75, in parse_data raise ValueError ValueError

xelaos commented 5 years ago
 if key in abilities and v["index"] == 0:
    print(key)
    # raise ValueError

Then the value is error is gone and it only affects UNLOADUNIT

PavloRyabokrys commented 5 years ago
 if key in abilities and v["index"] == 0:
    print(key)
    # raise ValueError

it helped, IDs were rewrited

PavloRyabokrys commented 5 years ago

It is a total mess right now.

Things were working well until StarCraft2 version 4.8.4. In 4.8.5, the pixelmap changed and self.state.upgrades stopped working. Thus, self.already_pending_upgrade(UPGRADEID) stopped working if the upgrade was completely researched (should return 1, but returns 0 instead). self.state.upgrades was fixed in SC2 version 4.9.0.

The master branch of this library is working for SC2 version 4.8.4, while the develop branch fixed the issues with pixelmap introduced in 4.8.5 (and is the same in 4.8.6). Pixelmaps were starting in the top left but are now starting in the bottom left, so they were flipped in y-axis. Also pixelmap values changed from bytes to bits (like pathing grid, placement grid, and in 4.9.0 also creep map).

Dentosal needs a working version for his competition https://artificial-overmind.reaktor.com which runs on (I believe) 4.7.1 because it is using this linux client https://github.com/Blizzard/s2client-proto#linux-packages and the master branch works fine for that.

However in SC2 client 4.9.0 a new bug got introduced (that was already there about half a year ago in november 2018) that you can't run 2 bots against each other, but running bot against built-in AI works (because only one SC2 client needs to run for this). So new competitions like Probots ( https://www.eschamp.com/probots-2019-2/ ) decided to also run on client version 4.8.4

TLDR: If you want to run the latest SC2 client version 4.9.0 on windows/mac: You need to download and install the develop branch (instruction here: #266 ) and go into the library installation in your python folder and do the following changes: In sc2/game_state.py you have to change self.creep: PixelMap = PixelMap(self.observation_raw.map_state.creep, mirrored=True) to self.creep: PixelMap = PixelMap(self.observation_raw.map_state.creep, in_bits=True, mirrored=True) and in sc2/game_data.py you have to remove the line assert self.id != 0.

Also you need to download generate_id_constants_from_stableid.py from here https://github.com/Dentosal/python-sc2 and let it run once (create subfolders sc2/ids first) to update the IDs that were changed once again in 4.9.0 Then copy these newly generated files into the sc2/ids/ folders of the library in your python installation.

with this correction it works fine.

thanks

wontheone1 commented 5 years ago

Rather than everyone applying their own fix / workaround, I hope a patch is released with this problem fixed... (minor version upgrade or something)

Lambdanaut commented 5 years ago

Just piping in to say this is an issue for me as well.

NotSoup commented 5 years ago

Applied fixed in this thread for same issue, now it's throwing a "AssertionError: Unsupported pixel density"

EDIT: I found the fix for this error. Delete that line of code! (that assert line in pixel_map.py)

MarcoLeonePrince commented 5 years ago

Hi All,

I have tried the work around but

It is a total mess right now. Things were working well until StarCraft2 version 4.8.4. In 4.8.5, the pixelmap changed and self.state.upgrades stopped working. Thus, self.already_pending_upgrade(UPGRADEID) stopped working if the upgrade was completely researched (should return 1, but returns 0 instead). self.state.upgrades was fixed in SC2 version 4.9.0. The master branch of this library is working for SC2 version 4.8.4, while the develop branch fixed the issues with pixelmap introduced in 4.8.5 (and is the same in 4.8.6). Pixelmaps were starting in the top left but are now starting in the bottom left, so they were flipped in y-axis. Also pixelmap values changed from bytes to bits (like pathing grid, placement grid, and in 4.9.0 also creep map). Dentosal needs a working version for his competition https://artificial-overmind.reaktor.com which runs on (I believe) 4.7.1 because it is using this linux client https://github.com/Blizzard/s2client-proto#linux-packages and the master branch works fine for that. However in SC2 client 4.9.0 a new bug got introduced (that was already there about half a year ago in november 2018) that you can't run 2 bots against each other, but running bot against built-in AI works (because only one SC2 client needs to run for this). So new competitions like Probots ( https://www.eschamp.com/probots-2019-2/ ) decided to also run on client version 4.8.4 TLDR: If you want to run the latest SC2 client version 4.9.0 on windows/mac: You need to download and install the develop branch (instruction here: #266 ) and go into the library installation in your python folder and do the following changes: In sc2/game_state.py you have to change self.creep: PixelMap = PixelMap(self.observation_raw.map_state.creep, mirrored=True) to self.creep: PixelMap = PixelMap(self.observation_raw.map_state.creep, in_bits=True, mirrored=True) and in sc2/game_data.py you have to remove the line assert self.id != 0. Also you need to download generate_id_constants_from_stableid.py from here https://github.com/Dentosal/python-sc2 and let it run once (create subfolders sc2/ids first) to update the IDs that were changed once again in 4.9.0 Then copy these newly generated files into the sc2/ids/ folders of the library in your python installation.

with this correction it works fine.

thanks

I have tried all the work around but now I receive a new error:

Traceback (most recent call last): File "main.py", line 1, in import sc2 File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/sc2/init.py", line 18, in from .data import * File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/sc2/data.py", line 56, in AbilityId.GATEWAYTRAIN_ZEALOT: AbilityId.WARPGATETRAIN_ZEALOT, File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/enum.py", line 348, in getattr raise AttributeError(name) from None AttributeError: GATEWAYTRAIN_ZEALOT

Any ideas? working with a Mac with latest OS.

Thanks!

ocnuybear commented 5 years ago
  1. Browse to c:\program files (x86)\microsoft visual studio\shared\python37_64\lib\site-packages\sc2 (I'm using Python in Visual Studio 2019 environment)
  2. Edit game_data.py and comment out 'assert self.id != 0' with # in front, save changes.
  3. Edit pixel_map.py and comment out 'assert self.bits_per_pixel % 8 == 0, "Unsupported pixel density"' with # in front, save changes.

Run again and game should work now fully updated on 4 Jul 2019

BryceWayne commented 4 years ago
  1. Browse to c:\program files (x86)\microsoft visual studio\shared\python37_64\lib\site-packages\sc2 (I'm using Python in Visual Studio 2019 environment)
  2. Edit game_data.py and comment out 'assert self.id != 0' with # in front, save changes.
  3. Edit pixel_map.py and comment out 'assert self.bits_per_pixel % 8 == 0, "Unsupported pixel density"' with # in front, save changes.

Run again and game should work now fully updated on 4 Jul 2019

There is no game_data.py to edit but the rest of pysc2 is there

ocnuybear commented 4 years ago

Thank you Batman

On Sun, 21 Jul 2019, 3:40 AM Batman notifications@github.com wrote:

  1. Browse to c:\program files (x86)\microsoft visual studio\shared\python37_64\lib\site-packages\sc2 (I'm using Python in Visual Studio 2019 environment)
  2. Edit game_data.py and comment out 'assert self.id != 0' with # in front, save changes.
  3. Edit pixel_map.py and comment out 'assert self.bits_per_pixel % 8 == 0, "Unsupported pixel density"' with # in front, save changes.

Run again and game should work now fully updated on 4 Jul 2019

There is no game_data.py to edit but the rest of pysc2 is there

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/Dentosal/python-sc2/issues/283?email_source=notifications&email_token=AMQYRNMB6X2EKWUQWDWRHYLQAO5CBA5CNFSM4HPWAO7KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD2NZDUQ#issuecomment-513511890, or mute the thread https://github.com/notifications/unsubscribe-auth/AMQYRNOYBV4RHRTBO7YLAP3QAO5CBANCNFSM4HPWAO7A .

ocnuybear commented 4 years ago

The file game_data.py ust be there otherwise you will have to copy it from the pysc2 package on github

On Sun, Jul 21, 2019 at 3:40 AM Batman notifications@github.com wrote:

  1. Browse to c:\program files (x86)\microsoft visual studio\shared\python37_64\lib\site-packages\sc2 (I'm using Python in Visual Studio 2019 environment)
  2. Edit game_data.py and comment out 'assert self.id != 0' with # in front, save changes.
  3. Edit pixel_map.py and comment out 'assert self.bits_per_pixel % 8 == 0, "Unsupported pixel density"' with # in front, save changes.

Run again and game should work now fully updated on 4 Jul 2019

There is no game_data.py to edit but the rest of pysc2 is there

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/Dentosal/python-sc2/issues/283?email_source=notifications&email_token=AMQYRNMB6X2EKWUQWDWRHYLQAO5CBA5CNFSM4HPWAO7KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD2NZDUQ#issuecomment-513511890, or mute the thread https://github.com/notifications/unsubscribe-auth/AMQYRNOYBV4RHRTBO7YLAP3QAO5CBANCNFSM4HPWAO7A .

zorroartico commented 4 years ago

@ocnuybear I had a problem with 3794 and your solution fixed the problem. Thanks.

BryceWayne commented 4 years ago

The file game_data.py ust be there otherwise you will have to copy it from the pysc2 package on github On Sun, Jul 21, 2019 at 3:40 AM Batman @.***> wrote: 1. Browse to c:\program files (x86)\microsoft visual studio\shared\python37_64\lib\site-packages\sc2 (I'm using Python in Visual Studio 2019 environment) 2. Edit game_data.py and comment out 'assert self.id != 0' with # in front, save changes. 3. Edit pixel_map.py and comment out 'assert self.bits_per_pixel % 8 == 0, "Unsupported pixel density"' with # in front, save changes. Run again and game should work now fully updated on 4 Jul 2019 There is no game_data.py to edit but the rest of pysc2 is there — You are receiving this because you commented. Reply to this email directly, view it on GitHub <#283?email_source=notifications&email_token=AMQYRNMB6X2EKWUQWDWRHYLQAO5CBA5CNFSM4HPWAO7KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD2NZDUQ#issuecomment-513511890>, or mute the thread https://github.com/notifications/unsubscribe-auth/AMQYRNOYBV4RHRTBO7YLAP3QAO5CBANCNFSM4HPWAO7A .

The file is not in the pysc2 github repo.

BryceWayne commented 4 years ago

3. Edit pixel_map.py and comment out 'assert self.bits_per_pixel % 8 == 0, "Unsupported pixel density"' with # in front, save changes.

This assert is not in the file

BryceWayne commented 4 years ago

Ok. I got it to work and this is what I did. I am using Python 3.7 and using SC2 4.9.3

  1. I force upgraded via this post. #266
  2. The post by BurnySc2 fixed my problem.

GLHF GG

ocnuybear commented 4 years ago

Strange that it differs for different users, but happy you got it to work 🙂

On Sun, Jul 21, 2019 at 4:00 PM Batman notifications@github.com wrote:

Ok. I got it to work and this is what I did. I am using Python 3.7 and using SC2 4.9.3

  1. I force upgraded via this post. #266 https://github.com/Dentosal/python-sc2/issues/266
  2. The post by BurnySc2 fixed my problem.

GLHF GG

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Dentosal/python-sc2/issues/283?email_source=notifications&email_token=AMQYRNMUCNI5GHQAYZXC2DDQARTWHA5CNFSM4HPWAO7KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD2OEECQ#issuecomment-513557002, or mute the thread https://github.com/notifications/unsubscribe-auth/AMQYRNKSBPR43D7ZIDXT6YLQARTWHANCNFSM4HPWAO7A .

BurnySc2 commented 4 years ago

You should also now be able to install from a specific fork, see https://github.com/Dentosal/python-sc2/issues/298#issuecomment-513579799

The install command on windows is

pip install pipenv
pip install --upgrade  git+https://github.com/Dentosal/python-sc2@develop
Lsp2987 commented 4 years ago
  1. Browse to c:\program files (x86)\microsoft visual studio\shared\python37_64\lib\site-packages\sc2 (I'm using Python in Visual Studio 2019 environment)
  2. Edit game_data.py and comment out 'assert self.id != 0' with # in front, save changes.
  3. Edit pixel_map.py and comment out 'assert self.bits_per_pixel % 8 == 0, "Unsupported pixel density"' with # in front, save changes.

Run again and game should work now fully updated on 4 Jul 2019

I have commented both assert self.id != 0 and 'assert self.bits_per_pixel % 8 == 0 and it worked! Thank you!

Sami-listens commented 4 years ago

I tried to follow this thread, it worked initially, but after 2 mins it gives following error :


ERROR:sc2.main:AI step threw an error ValueError: 3794 is not a valid AbilityId

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/local/lib/python3.7/site-packages/sc2/main.py", line 135, in _play_game_ai await ai.on_step(iteration) File "agentAI.py", line 16, in on_step await self.expand() File "agentAI.py", line 44, in expand await self.expand_now() File "/usr/local/lib/python3.7/site-packages/sc2/bot_ai.py", line 151, in expand_now await self.build(building, near=location, max_distance=max_distance, random_alternative=F alse, placement_step=1) File "/usr/local/lib/python3.7/site-packages/sc2/bot_ai.py", line 429, in build unit = unit or self.select_build_worker(p) File "/usr/local/lib/python3.7/site-packages/sc2/bot_ai.py", line 311, in select_build_work er if not worker.orders or len(worker.orders) == 1 and worker.orders[0].ability.id in {Abili tyId.MOVE, File "/usr/local/lib/python3.7/site-packages/sc2/game_data.py", line 101, in id return AbilityId(self._proto.remaps_to_ability_id) File "/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7 /enum.py", line 310, in call return cls.new(cls, value) File "/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7 /enum.py", line 564, in new raise exc File "/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7 /enum.py", line 548, in new result = cls.missing(value) File "/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7 /enum.py", line 577, in missing raise ValueError("%r is not a valid %s" % (value, cls.name)) ValueError: 3794 is not a valid AbilityId ERROR:sc2.main:resigning due to previous error INFO:root:Result for player id: 1: Result.Defeat INFO:sc2.protocol:Client status changed to Status.launched (was Status.in_game) INFO:sc2.protocol:Client status changed to Status.quit (was Status.launched) INFO:sc2.sc2process:kill_switch: Process cleanup INFO:sc2.sc2process:Cleaning up... INFO:sc2.sc2process:Cleanup complete ERROR:asyncio:Unclosed client session client_session: <aiohttp.client.ClientSession object at 0x109c4ed50>


Source code is : import sc2 from sc2 import run_game, maps, Race, Difficulty from sc2.player import Bot, Computer from sc2.constants import NEXUS, PROBE, PYLON, ASSIMILATOR, CYBERNETICSCORE, \ GATEWAY, STALKER

class SilentBot(sc2.BotAI): async def on_step(self, iteration):

what to do every step

    await self.distribute_workers()  # in sc2/bot_ai.py
    await self.build_workers()
    await self.build_pylons()
    await self.build_assimilators()
    await self.expand()
    await self.offensive_force_buildings()

async def build_workers(self):
    for nexus in self.units(NEXUS).ready.noqueue:
        if self.can_afford(PROBE):
            await self.do(nexus.train(PROBE))

async def build_pylons(self):
    if(self.supply_left < 5 and not self.already_pending(PYLON)):
        nexuses = self.units(NEXUS).ready
        if nexuses.exists and self.can_afford(PYLON):
            await self.build(PYLON, near = nexuses.first)

async def build_assimilators(self):
    for nexus in self.units(NEXUS).ready:
        vaspenes = self.state.vespene_geyser.closer_than(15.0, nexus)
        for vaspene in vaspenes:
            if not self.can_afford(ASSIMILATOR):
                break
            worker = self.select_build_worker(vaspene.position)
            if worker is None:
                break
            if not self.units(ASSIMILATOR).closer_than(1.0, vaspene).exists:
                await self.do(worker.build(ASSIMILATOR, vaspene))

async def expand(self):
    if self.units(NEXUS).amount < 3 and self.can_afford(NEXUS):
        await self.expand_now()

async def offensive_force_buildings(self):
    if self.units(PYLON).ready.exists:
            pylon = self.units(PYLON).ready.random
            if self.units(GATEWAY).ready.exists:
                if not self.units(CYBERNETICSCORE):
                    if self.can_afford(CYBERNETICSCORE) and not self.already_pending(CYBERNETICSCORE):
                        await self.build(CYBERNETICSCORE, near = pylon)
            else:
                if self.can_afford(GATEWAY) and not self.already_pending(GATEWAY):
                    await self.build(GATEWAY, near=pylon)

async def build_offensive_force(self):
    for gw in self.units(GATEWAY).ready.noqueue:
        if self.can_afford(STALKER) and self.supply_left > 0:
            await self.do(gw.train(STALKER))

run_game(maps.get("AbyssalReefLE"), [ Bot(Race.Protoss, SilentBot()), Computer(Race.Terran, Difficulty.Easy) ], realtime=False)


yyluio commented 4 years ago

None of the methods in this thread made any difference for me :(