Dentosal / python-sc2

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

How do I determine which type of unit has a given ability #173

Open b2coutts opened 5 years ago

b2coutts commented 5 years ago

I'm trying to make an AI that doesn't hardcode any of the tech tree, and instead infers it from the _game_data attribute of the bot at runtime. So far I'm able to pretty much build the tech tree from _game_data.units, using the tech_requirement attribute; this lets me build the tech tree as far as buildings.

The problem is with incorporating army units and research. For instance, colossi can be seen to depend on a robotics bay from its tech_requirement field, but an immortal has no tech_requirement, but you need a robotics facility to build it. All units have a creation_ability field, but there's no way to see which building can use that ability. Upgrades have the same problem.

So basically, my question is: is there a way to check, given a particular ability, which unit type(s) can use that ability? Or is there some other way to be able to tell which buildings can create which units programmatically?

BurnySc2 commented 5 years ago

As far as I know, this is a missing feature from the API.

I have hardcoded it in my bots to build units and research upgrades only from specific buildings under certain circumstances. This function could help you https://github.com/Dentosal/python-sc2/blob/695faf229140610a3e9c02e20df93856fbf948d4/sc2/bot_ai.py#L121-L124 to find out the abilities of your structures, but seeing how you write it, it sounds like you want to know at game start which buildings and units can use what abilities.

b2coutts commented 5 years ago

Yeah, I was ideally hoping to build the tech tree at game start so the bot would know what its branching options are; maybe I'll just hardcode these parts of the tech tree. Thanks for the response!

BurnySc2 commented 5 years ago

By the way, the terran units ghost, thor and battlecruiser should list techlab and their appropriate requirement (ghost academy, armory, fusion core respectively) but they only list None (at least the last time I checked).