Skip to content

Bug in sprite_list, solitaire example broken #824

@lwanger

Description

@lwanger

Bug Report

There are two bugs in the sprite_list::setitem method that I found while working through the solitaire example (https://arcade.academy/tutorials/card_game/index.html). Solitaire has a couple of places where a line like the following occurs (pull_to_top and shuffling):

window.card_list[1], window.card_list[2] = window.card_list[2], window.card_list[1]

For simplicity I can reproduce the bug with the line:

window.card_list[1] = window.card_list[2]

Actual behavior:

First, setitem causes a ValueError exception on the line:

value.sprite_lists.remove(item_to_be_removed)

This should be:

    self.sprite_lists.remove(item_to_be_removed)

Also, the following line shortens the length of the list by one (sets window.card_list[1] to the value in index two but does not add the value from index 1 back in -- shortening the length of the list by 1):

window.card_list[1] = window.card_list[2]

This eventually causes the solitaire example to stop with an IndexError exception.

Expected behavior:

Should swap the two values in the list, keeping the list the same length.

Steps to reproduce/example code:

import arcade

class Card(arcade.Sprite):
    def __init__(self, value):
        self.value = value
        super().__init__(None, 1.0)

    def __repr__(self):
        return f"Card={self.value}"

class MyGame(arcade.Window):
    def __init__(self):
        super().__init__(1000, 768, "shuffle test")
        self.card_list = None

    def setup(self):
        self.card_list = arcade.SpriteList()
        for i in range(5):
            self.card_list.append(Card(i))

if __name__ == "__main__":
    window = MyGame()
    window.setup()

    print(f"length of card_list = {len(window.card_list)},  card_list={window.card_list.sprite_list}")
    window.card_list[1] = window.card_list[2]
    print(f"length of card_list = {len(window.card_list)}, card_list={window.card_list.sprite_list}")

What would it help with?

Gettting the tutorial code to work

Where is it located?

sprite_list.py::setitem

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions