google-deepmind / google-deepmind/pysc2

Checking if an action is valid?

Open
#291 1 comment 1 reaction 0 assignees View on GitHub
Dominant language
Python
Stars
8.3k
Forks
1.2k
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.