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

Pre-move validation

The chess piece must only be moved if it does not violate the rules of the game. For example, a chess piece can move to a valid location only if that location is not already occupied by a chess piece of the same color. Similarly, a piece can move only if it is the player's turn to move. Another rule states that a piece can only move if the resulting move does not result in check for the king of the same color. 

This pre_move_validation method is responsible for checking all the rules. If all validations pass, it calls the move method to update the move, as follows (see 4.06model.py):

    def pre_move_validation(self, initial_pos, final_pos):        initial_pos, final_pos = initial_pos.upper(), final_pos.upper() piece = self.get_piece_at(initial_pos) ...

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