Skip to content

Deepcopy funktioniert auf GameState nicht #115

Done

Description

@SturmEnte

Please follow this template when reporting a bug in the Python SoCha Client. Providing as much detail as possible will help us to quickly understand and resolve the issue.

Description

Ich wollte den GameState kopieren, dafür wollte ich deepcopy aus copy benutzen.

Environment

  • Python version: 3.12
  • Operating System: Fedora 45
  • Version of the Python SoCha Client: 5.1.0

Expected Behavior

Klonen des GameStates.

Actual Behavior

Fehler:

Traceback (most recent call last):
  File "/home/sturmente/SoftwareChallenge/gho/test/gho-termin2.py", line 192, in <module>
    Starter(logic=Logic())
  File "/home/sturmente/SoftwareChallenge/gho/test/.venv/lib/python3.12/site-packages/socha/starter.py", line 116, in __init__
    self.client.start()
  File "/home/sturmente/SoftwareChallenge/gho/test/.venv/lib/python3.12/site-packages/socha/api/networking/game_client.py", line 294, in start
    self._client_loop()
  File "/home/sturmente/SoftwareChallenge/gho/test/.venv/lib/python3.12/site-packages/socha/api/networking/game_client.py", line 364, in _client_loop
    self._on_object(response)
  File "/home/sturmente/SoftwareChallenge/gho/test/.venv/lib/python3.12/site-packages/socha/api/networking/game_client.py", line 255, in _on_object
    self._on_move_request(room_id)
  File "/home/sturmente/SoftwareChallenge/gho/test/.venv/lib/python3.12/site-packages/socha/api/networking/game_client.py", line 274, in _on_move_request
    move_response = self._game_handler.calculate_move()
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/sturmente/SoftwareChallenge/gho/test/gho-termin2.py", line 155, in calculate_move
    our_move_options_before = get_team_move_options(initial_game_state)
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/sturmente/SoftwareChallenge/gho/test/gho-termin2.py", line 110, in get_team_move_options
    game_state = deepcopy(game_state)
                 ^^^^^^^^^^^^^^^^^^^^
  File "/home/sturmente/.local/share/uv/python/cpython-3.12.15-linux-x86_64-gnu/lib/python3.12/copy.py", line 151, in deepcopy
    rv = reductor(4)
         ^^^^^^^^^^^
TypeError: cannot pickle 'builtins.GameState' object

Reproduction Steps

Einen bestehenden GameState nehmen und in deepcopy übergeben.

Activity

  1. added
    bug
    on Nov 28, 2026
  2. SturmEnte commented on Nov 28, 2026

    @SturmEnte
    ContributorAuthor

    Wahrscheinlich funktionierender Workaround:

    def clone_state(gs: GameState) -> GameState:
        board = Board([[f.deepcopy() for f in row] for row in gs.board.map])
        new = GameState(
            turn=gs.turn,
            last_move=gs.last_move,
            board=board,
            start_piece=gs.start_piece,
            last_move_mono=dict(gs.last_move_mono),
        )
        for color in (Color.BLUE, Color.YELLOW, Color.RED, Color.GREEN):
            keep = set(gs.undeployed_piece_shapes(color))
            for shape in PieceShape.all():
                if shape not in keep:
                    new.remove_undeployed_piece(color, shape)
        return new

    Garantieren kann ich aber diesmal nichts.

  3. SturmEnte commented on Nov 28, 2026

    @SturmEnte
    ContributorAuthor

    Falls es bereits irgendeine einfache Möglichkeit gibt einen GameState zu klonen, habe ich das übersehen.
    Gerne mitteilen.

  4. YoEnte commented on Nov 30, 2026

    @YoEnte
    Collaborator

    Sollte in rust möglich sein, war letztes Jahr auch, habe ich ggf vergessen zu übernehmen

  5. linked a pull request that will close this issueadd deepcopy (and ne) to gamestate #117on Dec 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions