Code Monkey home page Code Monkey logo

pysc2-tutorial's People

Contributors

ascyrax avatar skjb avatar twirrim avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pysc2-tutorial's Issues

change in observation attribute names

a lot of names have been changed. Such as obs.observation["minimap"] to obs.observation["feature_minimap"]. Similarly obs.observation["screen"] to obs.observation["feature_screen"]. Im only starting your tutorial so I dont know of other name changes but Im guessing there are others. The version of pyc2 im using is 2.0.1

Thanks for the great tutorial!

I got error

player_y, player_x = (obs.observation["minimap"][_PLAYER_RELATIVE] == _PLAYER_SELF).nonzero()

KeyError: 'minimap'

Why does it happen and how can I fix it...?

'NamedDict' object has no attribute 'feature_units'

I'm trying to run the final zerg bot (zerg_agent_step7.py) through the command:

python3 -m pysc2.bin.agent --map Simple64 --agent zergbot.ZergAgent

and I got the error:

zerglings = self.get_units_by_type(obs, units.Zerg.Zergling) File "/Users/xx/Desktop/xx/xx/pysc2-tutorial/zergbot.py", line 25, in get_units_by_type return [unit for unit in obs.observation.feature_units AttributeError: 'NamedDict' object has no attribute 'feature_units'

Error in zerg_agent_step5

I found one error in zerg_agent_step5.
At line 48, need to change
larvae = self.get_units_by_type(oba, units.Zerg.Larva)
to
larvae = self.get_units_by_type(obs, units.Zerg.Larva)

thank you for your job

Add a LICENSE

Would you mind adding an Open Source License? I don't want to use these examples in my open source bot without proper permision :)

A little question about valid_functions

Hello!

First of all I want to thank you for your tutorial which really gives me a lot help, I learned a lot through your code.

I am currently working on the Q-learning code, and I see that you used Raw_function instead of actions.FUNCTIONS in the code. I did some research but unfortunately I didn't find the difference between them. I seems to me that the origin actions.FUNCTIONS that you used in those basic agent programs are more similar to real world operations, while the utilisation of those RAW_FUNCTIONS seems to be much easier and a little bit tricky. Am I understanding right ? To simulate human operation in the game, which one should be the better choice ?

Thanks! :)

Error getting Random Range.

After i run the agent for a while i randomly get the following:

I1020 12:20:54.603614 12624 sc2_env.py:310] Episode finished. Outcome: [-1], reward: [-1], score: [1410]
I1020 12:21:01.876163 12624 sc2_env.py:240] Starting episode: 6
Took 368.270 seconds for 9110 steps: 24.737 fps
I1020 12:21:11.313090 12624 sc2_env.py:327] Environment Close
I1020 12:21:11.315090 12624 sc2_env.py:342]
Traceback (most recent call last):
File "C:\Python36\lib\runpy.py", line 193, in _run_module_as_main
"main", mod_spec)
File "C:\Python36\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Python36\lib\site-packages\pysc2\bin\agent.py", line 112, in
app.run(main)
File "C:\Python36\lib\site-packages\absl\app.py", line 272, in run
_run_main(main, argv)
File "C:\Python36\lib\site-packages\absl\app.py", line 237, in _run_main
sys.exit(main(argv))
File "C:\Python36\lib\site-packages\pysc2\bin\agent.py", line 98, in main
run_thread(agent_cls, FLAGS.map, FLAGS.render)
File "C:\Python36\lib\site-packages\pysc2\bin\agent.py", line 77, in run_thread
run_loop.run_loop([agent], env, FLAGS.max_agent_steps)
File "C:\Python36\lib\site-packages\pysc2\env\run_loop.py", line 41, in run_loop
for agent, timestep in zip(agents, timesteps)]
File "C:\Python36\lib\site-packages\pysc2\env\run_loop.py", line 41, in
for agent, timestep in zip(agents, timesteps)]
File "C:\Python36\Lib\site-packages\pysc2\agents\smart_agent.py", line 177, in step
i = random.randrange(0, len(unit_y) - 1)
File "C:\Python36\lib\random.py", line 198, in randrange
raise ValueError("empty range for randrange() (%d,%d, %d)" % (istart, istop, width))
ValueError: empty range for randrange() (0,0, 0)
I1020 12:21:11.364095 12624 sc2_env.py:327] Environment Close
I1020 12:21:11.365095 12624 sc2_env.py:342]
I1020 12:21:11.367095 12624 sc2_env.py:327] Environment Close
I1020 12:21:11.375099 12624 sc2_env.py:342]
W1020 12:21:14.483033 12624 sc_process.py:183] Killing the process.
I1020 12:21:15.275633 12624 sc_process.py:166] Shutdown with return code: 1

TypeError: reduction operation 'argmax' not allowed for this dtype

I'm trying to run the script but I'm getting this error.

I1208 14:55:06.231405 6620 sc2_env.py:200] Environment is ready.
I1208 14:55:06.232910 6620 sc2_env.py:240] Starting episode: 1
Took 0.063 seconds for 1 steps: 15.957 fps
I1208 14:55:06.295577 6620 sc2_env.py:327] Environment Close
I1208 14:55:06.295577 6620 sc2_env.py:342]
Traceback (most recent call last):
File "C:\Programy\Python\Python36\lib\runpy.py", line 193, in _run_module_as_main
"main", mod_spec)
File "C:\Programy\Python\Python36\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Programy\Python\Python36\lib\site-packages\pysc2\bin\agent.py", line 112, in
app.run(main)
File "C:\Programy\Python\Python36\lib\site-packages\absl\app.py", line 274, in run
_run_main(main, argv)
File "C:\Programy\Python\Python36\lib\site-packages\absl\app.py", line 238, in _run_main
sys.exit(main(argv))
File "C:\Programy\Python\Python36\lib\site-packages\pysc2\bin\agent.py", line 98, in main
run_thread(agent_cls, FLAGS.map, FLAGS.render)
File "C:\Programy\Python\Python36\lib\site-packages\pysc2\bin\agent.py", line 77, in run_thread
run_loop.run_loop([agent], env, FLAGS.max_agent_steps)
File "C:\Programy\Python\Python36\lib\site-packages\pysc2\env\run_loop.py", line 41, in run_loop
for agent, timestep in zip(agents, timesteps)]
File "C:\Programy\Python\Python36\lib\site-packages\pysc2\env\run_loop.py", line 41, in
for agent, timestep in zip(agents, timesteps)]
File "I:\Starcraft 2 Projects\SmartBot\SMBot.py", line 177, in step
rl_action = self.qlearn.choose_action(str(current_state))
File "I:\Starcraft 2 Projects\SmartBot\SMBot.py", line 80, in choose_action
action = state_action.idxmax()
File "C:\Programy\Python\Python36\lib\site-packages\pandas\core\series.py", line 1357, in idxmax
i = nanops.nanargmax(_values_from_object(self), skipna=skipna)
File "C:\Programy\Python\Python36\lib\site-packages\pandas\core\nanops.py", line 74, in _f
raise TypeError(msg.format(name=f.name.replace('nan', '')))
TypeError: reduction operation 'argmax' not allowed for this dtype
I1208 14:55:06.309614 6620 sc2_env.py:327] Environment Close
I1208 14:55:06.309614 6620 sc2_env.py:342]
I1208 14:55:06.310115 6620 sc2_env.py:327] Environment Close
I1208 14:55:06.310115 6620 sc2_env.py:342]
W1208 14:55:09.418379 6620 sc_process.py:183] Killing the process.
I1208 14:55:09.544715 6620 sc_process.py:166] Shutdown with return code: 1

Army rallies aren't working correctly for me

When I used the latest code from https://github.com/skjb/pysc2-tutorial/blob/master/Building%20a%20Basic%20Agent/simple_agent.py, the first Marine would rally across the map alone. Then a few extra Marines would get built, but never attack. I fixed this by changing a single line:

elif obs.observation["player"][_SUPPLY_USED] == obs.observation["player"][_SUPPLY_MAX] and not self.army_rallied:

It's possible I have an error, but I can't see what it might be. Before I made the change, I noticed that the barracks often gets deselected, and Marines sometimes wouldn't build until I selected it manually. My understanding was/is that "train_marine_quick" should appear in obs.observation["available_actions"] even if the rax isn't selected. Is that correct?

Contributor guidelines?

@skjb I would love to contribute to this project - I am working on tutorials for getting set up with the SC2LE and for making a basic Protoss agent. Are you open to PRs?

Unmentioned/unclear control flow change, Line 36 in zerg_agent_step5.py

Nesting/relocating the drone selection block in the spawning pool conditional body was not mentioned in the tutorial, and visually unclear from code.

While it makes sense we wouldn't want to keep selecting drones, with 2-space indentations, lots of wrapped lines, and no mention, if you're not copy pasting the tutorial code, it's possible you might miss the change. I think it would be nice to make that change more explicit.

    spawning_pools = self.get_units_by_type(obs, units.Zerg.SpawningPool)
    if len(spawning_pools) == 0:
      if self.unit_type_is_selected(obs, units.Zerg.Drone):
        if (actions.FUNCTIONS.Build_SpawningPool_screen.id in 
            obs.observation.available_actions):
          x = random.randint(0, 83)
          y = random.randint(0, 83)
          
          return actions.FUNCTIONS.Build_SpawningPool_screen("now", (x, y))
    
      drones = self.get_units_by_type(obs, units.Zerg.Drone)
      if len(drones) > 0:
        drone = random.choice(drones)

        return actions.FUNCTIONS.select_point("select_all_type", (drone.x,
                                                                  drone.y))
    
    if self.unit_type_is_selected(obs, units.Zerg.Larva):
      if (actions.FUNCTIONS.Train_Zergling_quick.id in 
          obs.observation.available_actions):
        return actions.FUNCTIONS.Train_Zergling_quick("now")
    
    larvae = self.get_units_by_type(oba, units.Zerg.Larva)
    if len(larvae) > 0:
      larva = random.choice(larvae)
      
      return actions.FUNCTIONS.select_point("select_all_type", (larva.x,
                                                                larva.y))

Contact information?

Hey Steve, big fan of your PySC2 tutorials. Couldn't find your contact information online so resorting to a GitHub issue. I have my own RL company Yuri.ai and am looking for like minded people to talk to and share ideas with. Would really appreciate it if you have the time for a phone call sometime before the holidays

error trying to run agent

Running this on Mac. I get this error. Any ideas? thanks

I1216 13:36:12.326220 4320764736 sc2_env.py:200] Environment is ready. I1216 13:36:12.352599 4320764736 sc2_env.py:240] Starting episode: 1 0/no_op () 1/move_camera (1/minimap [64, 64]) 2/select_point (6/select_point_act [4]; 0/screen [84, 84]) 3/select_rect (7/select_add [2]; 0/screen [84, 84]; 2/screen2 [84, 84]) 4/select_control_group (4/control_group_act [5]; 5/control_group_id [10]) 264/Harvest_Gather_screen (3/queued [2]; 0/screen [84, 84]) 12/Attack_screen (3/queued [2]; 0/screen [84, 84]) 13/Attack_minimap (3/queued [2]; 1/minimap [64, 64]) 274/HoldPosition_quick (3/queued [2]) 451/Smart_screen (3/queued [2]; 0/screen [84, 84]) 452/Smart_minimap (3/queued [2]; 1/minimap [64, 64]) 453/Stop_quick (3/queued [2]) 331/Move_screen (3/queued [2]; 0/screen [84, 84]) 332/Move_minimap (3/queued [2]; 1/minimap [64, 64]) 333/Patrol_screen (3/queued [2]; 0/screen [84, 84]) 334/Patrol_minimap (3/queued [2]; 1/minimap [64, 64]) 79/Build_Refinery_screen (3/queued [2]; 0/screen [84, 84]) 91/Build_SupplyDepot_screen (3/queued [2]; 0/screen [84, 84]) 220/Effect_Repair_screen (3/queued [2]; 0/screen [84, 84]) 221/Effect_Repair_autocast () 230/Effect_Spray_screen (3/queued [2]; 0/screen [84, 84]) 269/Harvest_Return_quick (3/queued [2]) 50/Build_EngineeringBay_screen (3/queued [2]; 0/screen [84, 84]) Took 1.550 seconds for 34 steps: 21.942 fps I1216 13:36:13.902295 4320764736 sc2_env.py:327] Environment Close I1216 13:36:13.902536 4320764736 sc2_env.py:342] Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/runpy.py", line 193, in _run_module_as_main "__main__", mod_spec) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/runpy.py", line 85, in _run_code exec(code, run_globals) File "/Users/craigh/python/virtual-env3/sc2ai-2/lib/python3.6/site-packages/pysc2/bin/agent.py", line 112, in <module> app.run(main) File "/Users/craigh/python/virtual-env3/sc2ai-2/lib/python3.6/site-packages/absl/app.py", line 274, in run _run_main(main, argv) File "/Users/craigh/python/virtual-env3/sc2ai-2/lib/python3.6/site-packages/absl/app.py", line 238, in _run_main sys.exit(main(argv)) File "/Users/craigh/python/virtual-env3/sc2ai-2/lib/python3.6/site-packages/pysc2/bin/agent.py", line 98, in main run_thread(agent_cls, FLAGS.map, FLAGS.render) File "/Users/craigh/python/virtual-env3/sc2ai-2/lib/python3.6/site-packages/pysc2/bin/agent.py", line 77, in run_thread run_loop.run_loop([agent], env, FLAGS.max_agent_steps) File "/Users/craigh/python/virtual-env3/sc2ai-2/lib/python3.6/site-packages/pysc2/env/run_loop.py", line 46, in run_loop timesteps = env.step(actions) File "/Users/craigh/python/virtual-env3/sc2ai-2/lib/python3.6/site-packages/pysc2/env/available_actions_printer.py", line 32, in step all_obs = super(AvailableActionsPrinter, self).step(*args, **kwargs) File "/Users/craigh/python/virtual-env3/sc2ai-2/lib/python3.6/site-packages/pysc2/env/base_env_wrapper.py", line 42, in step return self._env.step(*args, **kwargs) File "/Users/craigh/python/virtual-env3/sc2ai-2/lib/python3.6/site-packages/pysc2/lib/stopwatch.py", line 197, in _stopwatch return func(*args, **kwargs) File "/Users/craigh/python/virtual-env3/sc2ai-2/lib/python3.6/site-packages/pysc2/env/sc2_env.py", line 254, in step for c, o, a in zip(self._controllers, self._obs, actions)) File "/Users/craigh/python/virtual-env3/sc2ai-2/lib/python3.6/site-packages/pysc2/lib/run_parallel.py", line 54, in run funcs = [f if callable(f) else functools.partial(*f) for f in funcs] File "/Users/craigh/python/virtual-env3/sc2ai-2/lib/python3.6/site-packages/pysc2/lib/run_parallel.py", line 54, in <listcomp> funcs = [f if callable(f) else functools.partial(*f) for f in funcs] File "/Users/craigh/python/virtual-env3/sc2ai-2/lib/python3.6/site-packages/pysc2/env/sc2_env.py", line 254, in <genexpr> for c, o, a in zip(self._controllers, self._obs, actions)) File "/Users/craigh/python/virtual-env3/sc2ai-2/lib/python3.6/site-packages/pysc2/lib/stopwatch.py", line 197, in _stopwatch return func(*args, **kwargs) File "/Users/craigh/python/virtual-env3/sc2ai-2/lib/python3.6/site-packages/pysc2/lib/features.py", line 427, in transform_action func, func_call.arguments)) ValueError: Argument is out of range for 91/Build_SupplyDepot_screen (3/queued [2]; 0/screen [0, 0]), got: [[0], [48, 98]] I1216 13:36:13.946142 4320764736 sc2_env.py:327] Environment Close I1216 13:36:13.946537 4320764736 sc2_env.py:342] I1216 13:36:13.946666 4320764736 sc2_env.py:327] Environment Close I1216 13:36:13.946901 4320764736 sc2_env.py:342] W1216 13:36:17.142264 4320764736 sc_process.py:183] Killing the process. I1216 13:36:17.427438 4320764736 sc_process.py:166] Shutdown with return code: -9

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.