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.

Get Tkinter GUI Application Development Blueprints - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.