Python Forum
Python chess game to detect winner
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python chess game to detect winner
#1
def destroy_piece(self, piece):
        """ Removes piece from the canvans and click-handler
            automatily called by move_piece
        """
        img1=piece.get_img_int(0)
        img2=piece.get_img_int(1)
        
        del self._on_clicks[str(img1)]
        del self._on_clicks[str(img2)]
        
        self.delete(piece.get_img_int(0))
        self.delete(piece.get_img_int(1))
        
        self.destroyed_pieces = []
        self.destroyed_pieces.append(piece)
        
        for elem in self.destroyed_pieces:
            if elem in self.destroyed_pieces == "bk.png" or "wk.png":
                messagebox.showinfo("WINNER")
                print (self.destroyed_pieces)
So I am trying to write out a message when the king has been killed by adding all destroyed pieces and when the king is in the list the winner gets announced, however it is not working,
buran write Dec-13-2020, 06:27 PM:
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.
Reply
#2
Well, the first problem is that the king is never killed in chess. The game ends the turn before before that.

That said, this might work for you.
for elem in self.destroyed_pieces:
    if elem == "bk.png":
        messagebox.showinfo("White Wins")
    if elem == "wk.png":
        messagebox.showinfo("Black Wins")
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  a chess endgame problem, almost solved but not quite max22 0 169 Mar-31-2024, 06:14 PM
Last Post: max22
  optimum chess endgame with D=3 pieces doesn't give an exact moves_to_mate variable max22 1 288 Mar-21-2024, 09:31 PM
Last Post: max22
  strange behavior of chess library in Python max22 1 322 Jan-18-2024, 06:35 PM
Last Post: deanhystad
  When does Python detect Errors? stamp1t 1 451 Oct-21-2023, 05:53 PM
Last Post: deanhystad
  How to detect abnormal data in big database python vanphuht91 5 1,155 Jun-27-2023, 11:22 PM
Last Post: Skaperen
  How to detect the text above lines using OpenCV in Python pframe 0 2,526 Apr-14-2020, 09:53 AM
Last Post: pframe
  Detect finger clicks/snaps using Python fwinter102 0 2,050 Aug-12-2019, 04:02 PM
Last Post: fwinter102
  Does Python sqlite3 detect connection errors zatlas1 6 3,979 Jan-18-2019, 06:02 AM
Last Post: zatlas1
  How to detect wireless modem connected serially to my laptop in python barry76 3 3,560 Jan-08-2019, 06:18 AM
Last Post: Gribouillis
  Is there a way to detect the text font, size and color from an image in python? Maia07 2 8,690 Aug-23-2018, 01:16 PM
Last Post: Maia07

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020