python-sc2 icon indicating copy to clipboard operation
python-sc2 copied to clipboard

Duplicate actions in Realtime mode

Open Hannessa opened this issue 7 years ago • 5 comments

I noticed that some actions are run twice when realtime=True in sc2.run_game(), even though they shouldn't. This doesn't seem to happen when realtime=False.

For example, if I run examples/proxy_rax.py in realtime, there is sometimes an extra SCV queued at the CC, even though the code says that it should only train an SCV if the CC queue is empty. I also sometimes get NotEnoughMinerals error for the same reason, because it runs the build SCV action twice, but can't afford the second one (even though there's the self.can_afford(SCV) check).

I'm on Windows 10, if this has anything to do with it.

Hannessa avatar May 21 '18 19:05 Hannessa

I have this too. I'll try to look at it. Might be an issue with the API itself, but more likely my mistake.

Dentosal avatar May 30 '18 13:05 Dentosal

Yeah, I actually talked with some people on Discord that are using other frameworks, and I think they had similar issues too, so I'm afraid it might be a problem with the Blizzard API itself like you say!

Hannessa avatar May 30 '18 14:05 Hannessa

I guess a small workaround could be to use

if iteration % x == 0: # where x is some number between 2 and 6

in places where you want to make sure that you never queue a second unit or never build a second building. It happened to me too where the AI built a second extractor when it should only have built one. Adding iteration % 6 == 0 fixed it for me.

So in the proxy rax bot, that if statement could look like this:

if self.can_afford(SCV) and self.workers.amount < 16 and cc.noqueue and iteration % 6 == 0:
    await self.do(cc.train(SCV))

EDIT: After some testing, this only makes sense to use in realtime=True mode

BurnySc2 avatar May 30 '18 18:05 BurnySc2

@Dentosal any luck?

ghost avatar Jul 04 '18 18:07 ghost

No matter realtime true or false when I try to get tech lab ability for my factory it's gonna build an extra factory . Sometimes I have to move it !

beni-Lx avatar Sep 30 '18 04:09 beni-Lx