sc2reader icon indicating copy to clipboard operation
sc2reader copied to clipboard

Cant process the replays generated by python-sc2

Open histmeisah opened this issue 1 year ago • 2 comments

I have writed some botai to play starcraft2 by python-sc2,and i find sc2reader cant process these replays. python version:3.10 sc2reader version:1.8.0 python-sc2 version: 6.5.0

code is here:

import sc2reader replay = sc2reader.load_replay('Altitude LE_20230903_161615_PROTOSS_VS_BUILD_IN_AI_MediumHard_Zerg_process_-5_checked.SC2Replay')

print(replay.players)

here is my error:

Traceback (most recent call last): File "E:\python_code\sc2data_process\process_replay\process_replay\test_sc2reader.py", line 2, in replay = sc2reader.load_replay('Altitude LE_20230903_161615_PROTOSS_VS_BUILD_IN_AI_MediumHard_Zerg_process_-5_checked.SC2Replay') File "E:\anaconda\envs\sc2env\lib\site-packages\sc2reader\factories\sc2factory.py", line 88, in load_replay return self.load(Replay, source, options, **new_options) File "E:\anaconda\envs\sc2env\lib\site-packages\sc2reader\factories\sc2factory.py", line 166, in load return self._load(cls, resource, filename=filename, options=options) File "E:\anaconda\envs\sc2env\lib\site-packages\sc2reader\factories\sc2factory.py", line 175, in _load obj = cls(resource, filename=filename, factory=self, **options) File "E:\anaconda\envs\sc2env\lib\site-packages\sc2reader\resources.py", line 302, in init self.load_all_details() File "E:\anaconda\envs\sc2env\lib\site-packages\sc2reader\resources.py", line 444, in load_all_details self.load_details() File "E:\anaconda\envs\sc2env\lib\site-packages\sc2reader\resources.py", line 389, in load_details self.region = details["cache_handles"][0].server.lower() IndexError: list index out of range

here is replay file: replays.zip

histmeisah avatar Jan 18 '24 13:01 histmeisah

IndexError issues: https://github.com/ggtracker/sc2reader/issues?q=is%3Aissue+is%3Aopen+indexerror

All four issues point to the same line of code.

Thank you sir, but it is hard to find how to solve this problem,is this problem still existence?

histmeisah avatar Jan 18 '24 14:01 histmeisah

Right, so I think the comment linking points to a general issue that the sc2reader library assumes that these replays were generated off of actually played games. Those games have things like server details and such that are pulled into the library. Since you said that python-sc2 to simulate the games, I suspect that some of these details aren't present.

A possible fix here is to see if you can bypass these lines if the cache handles aren't present. However, I'm not sure how many other places make the same assumption or if you will run into more problems down the line.

If you do get it working assuming that these details are optional, you're welcome to open a PR for it!

StoicLoofah avatar Jan 22 '24 21:01 StoicLoofah