Skip to content

Issue with color palette is breaking rendering #43

Description

@JRod-Seed

Hi,
I just installed SMAC_V2 and am experimenting with the sample code provided in the Readme. Generally, everything is working well but I see that...

If you uncomment

env.render()

an error is thrown:

Traceback (most recent call last):
  File "/Users/justinrodriguez/git/explainable_starcraft/test_driver.py", line 87, in <module>
    main()
  File "/Users/justinrodriguez/git/explainable_starcraft/test_driver.py", line 64, in main
    env.render()  # Uncomment for rendering
    ^^^^^^^^^^^^
  File "/Users/justinrodriguez/git/explainable_starcraft/.venv/lib/python3.12/site-packages/smacv2/env/starcraft2/wrapper.py", line 82, in render
    return self.env.render(mode=mode)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/justinrodriguez/git/explainable_starcraft/.venv/lib/python3.12/site-packages/smacv2/env/starcraft2/starcraft2.py", line 2285, in render
    from smacv2.env.starcraft2.render import StarCraft2Renderer
  File "/Users/justinrodriguez/git/explainable_starcraft/.venv/lib/python3.12/site-packages/smacv2/env/starcraft2/render.py", line 15, in <module>
    from pysc2.lib.renderer_human import _Surface
  File "/Users/justinrodriguez/git/explainable_starcraft/.venv/lib/python3.12/site-packages/pysc2/lib/renderer_human.py", line 35, in <module>
    from pysc2.lib import features
  File "/Users/justinrodriguez/git/explainable_starcraft/.venv/lib/python3.12/site-packages/pysc2/lib/features.py", line 350, in <module>
    SCREEN_FEATURES = ScreenFeatures(
                      ^^^^^^^^^^^^^^^
  File "/Users/justinrodriguez/git/explainable_starcraft/.venv/lib/python3.12/site-packages/pysc2/lib/features.py", line 323, in __new__
    palette=palette(scale) if callable(palette) else palette,
            ^^^^^^^^^^^^^^
  File "/Users/justinrodriguez/git/explainable_starcraft/.venv/lib/python3.12/site-packages/pysc2/lib/colors.py", line 213, in unit_type
    return categorical(static_data.UNIT_TYPES, scale)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/justinrodriguez/git/explainable_starcraft/.venv/lib/python3.12/site-packages/pysc2/lib/colors.py", line 224, in categorical
    palette = shuffled_hue(palette_size)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/justinrodriguez/git/explainable_starcraft/.venv/lib/python3.12/site-packages/pysc2/lib/colors.py", line 121, in shuffled_hue
    random.shuffle(palette, lambda: 0.5)  # Return a fixed shuffle
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: Random.shuffle() takes 2 positional arguments but 3 were given
INFO:absl:Shutdown gracefully.
INFO:absl:Shutdown with return code: -15

This stems from the lambda function embedded here:

def shuffled_hue(scale):
  palette = list(smooth_hue_palette(scale))
  random.shuffle(palette, lambda: 0.5)  # Return a fixed shuffle
  return numpy.array(palette)

If you remove the lambda function in random.shuffle(), the problem goes away and the game is able to render.

FWIW I'm running in python 3.12.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions