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

Check whether a move will cause check on the King

Though a major part of the validation check done in the preceding lines is simple, one of the validation steps needs to check whether a movement will cause the king to be in check. This is a tricky situation. We can only find this out after we have made the actual move. However, we cannot allow that movement to happen on the chessboard.

To do this, the pre_move_validation method calls a method named will_move_cause_check, which creates a copy of the Model class. Then, it performs a move on the new temporary copy to check whether it does cause a king to be in check. The code for this is as follows (4.06model.py):

def will_move_cause_check(self, start_position, end_position): tmp = deepcopy(self) ...

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