Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop workers from moving #197

Open
zeroN1 opened this issue Apr 15, 2024 · 0 comments
Open

Stop workers from moving #197

zeroN1 opened this issue Apr 15, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@zeroN1
Copy link

zeroN1 commented Apr 15, 2024

I have a simple bot script where I am trying to issue a stop command to workers to stop and do nothing. I have the following script:

import sc2
import sc2.action
from sc2.bot_ai import BotAI
import sc2.constants
import sc2.game_data
import sc2.ids
from sc2.player import Bot, Computer
from sc2.ids.unit_typeid import UnitTypeId
import os

import sc2.unit
import sc2.units

os.environ["SC2PATH"] = "C:\\sc2\\StarCraft II"

def stop_all_units(bot: BotAI):
    '''
        Stop all units by cancelling all active and pending orders
    '''
    #u: sc2.unit.Unit = bot.units[0]
    #o: sc2.unit.UnitOrder = u.orders[0]
    #a: sc2.unit.AbilityId = o.ability
    print("Stopping all workers")
    for worker in bot.workers:
        if worker:
            print(f"{type(worker.hold_position)} {type(worker.stop)}")
            worker.stop()

class SimpleBot(BotAI):
    async def on_step(self, iteration):
        global HasInformedUnitsInfo
        #print_info(bot=self, iteration=iteration)
        #if not HasInformedUnitsInfo:
        stop_all_units(self)
            #HasInformedUnitsInfo = True

sc2.run_game(
    sc2.maps.get("AcropolisLE"),
    [Bot(sc2.Race.Zerg, SimpleBot()), Computer(sc2.Race.Zerg, sc2.Difficulty.Hard)],
    realtime=True
)

The above is the code I have. On every iteration, stop_all_units is executed and I can see the printed statements on the command prompt. However, once the game starts, the workers start gathering minerals and don't stop. I have also tried hold_position() on the worker objects without success and also tried worker.move(bot.start_location.position) to move them to a spot and stop gathering.

None of the above worked for me. Are there any other ways to do this or did I miss something? I am new to SC2 and maybe what I am trying makes no sense. Some pointers will be highly appreciated.

@BurnySc2 BurnySc2 added the bug Something isn't working label Apr 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants