0
\$\begingroup\$

I am trying to make a chess game with Pygame, but am unable to remove the chess piece when it is captured. Stack Overflow already has a question on this here. But this code doesn't seem to work. When I iterate through the list, it ends up deleting many pieces.

for piece in piece_group_black:
    if piece.location.all() == selects.location.all():
        piece.kill()

Say I move white piece to capture black , this code ends up deleting a lot of pieces.

for piece in piece_group_black:
    if piece.location.all() == selects.location.all():
        pieceremove = piece

pieceremove.kill()

This removes a random piece. Same happens for when I use the code given in the answers. They just don't work.

\$\endgroup\$
1
  • 3
    \$\begingroup\$ You might want to tell us more about your piece class. What does location and location.all() do? \$\endgroup\$
    – Vaillancourt
    Jun 12 at 15:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.