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) ...

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.