pysc2
pysc2 copied to clipboard
Checking if an action is valid?
Hi,
I'm trying to learn a bot that runs in raw mode, but at test time while running the bot I'd like to be able to check whether the bot's proposed action is valid. I know that the game will just ignore the action and do nothing if the action is invalid, but I'd like to be able to know in the code so e.g. if building a pylon fails due to lack of minerals or an invalid location, I can try again later. From what I can tell, available_actions is not quite what I need, since I'd like to be able to check an action as well as the provided args.
Certainly I could special case for each action like e.g. https://itnext.io/create-a-protoss-bot-using-raw-observations-and-actions-in-pysc2-615f41aa283e where they do checks like
if (len(completed_gateways) > 0 and obs.observation.player.minerals >= 100 and free_supply >= 2):
to make zealots. However, I would really prefer not to have to do that special casing for every possible action. Is there any way in pysc2 that I can just provide an action + args and be told whether it's going to be executed or not? Or at least be told in the next timestep if the preceding action failed?
This issue https://github.com/deepmind/pysc2/issues/163 seems like it possibly has the solution, but when I try to check last_actions, it's always empty even when my bot executes actions successfully. Maybe I'm not doing it in the right way?
Thanks! Kevin
I didn't find an easier way than doing what you described. I think pysc2 only tells you in the available_actions whether you met the unit or technological requirements for that action, but it does not check the requirements concerning resources or possible locations. You would have to check that yourself but it should not be too pain-staking, at least for the resources.