O'Reilly logo

Tkinter GUI Application Development Blueprints - Second Edition by Bhaskar Chaudhary

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Finding out the current position of the king

Before we code the method that checks whether a king is in check, we first need to know the exact position of the king. Let's define a method to find out the current position of the king, as follows (see 4.05model.py):

 def get_alphanumeric_position_of_king(self, color):   for position in self.keys():     this_piece = self.get_piece_at(position)     if isinstance(this_piece, piece.King) and this_piece.color == color:        return position

The preceding code simply iterates through all the items in the dictionary. If a given position is an instance of the King class, it simply returns its position.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required