Dentosal / python-sc2

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

Cache expansion_locations #200

Open Dentosal opened 5 years ago

tweakimp commented 5 years ago

Arent they cached here?

Dentosal commented 5 years ago

Seems like they are. I'll verify that this before closing.

merfolk commented 5 years ago

The issue is that expansion_locations needs to be called once for the values to be cached.

If the call is made for the first time inside on_step() function it can cause a timeout for the whole bot.

Our bot currently handles the first call like below, but I feel the python-sc2 library should already have the values cached.

    def _prepare_first_step(self):
        """First step extra preparations. Must not be called before _prepare_step."""
        sc2.BotAI._prepare_first_step(self)
        # Call expansion_locations so they are cached for the rest of the game.
        # This can take a long time! Hopefully this overridden method 
        # will not be subject to the timeout limit.
        self.expansion_locations.keys()