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

Tracking all available moves

The code needed to keep track of all the available moves for a player is as follows:

def get_all_available_moves(self, color):  result = []  for position in self.keys():    piece = self.get_piece_at(position)    if piece and piece.color == color:       moves = piece.moves_available(position)       if moves:         result.extend(moves)  return result

The description of the code is as follows:

  • We have already coded the moves_available method in the previous iteration
  • The preceding method simply iterates through every item in the dictionary and appends the moves_available result for every chess piece of a given color in a list named result

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