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.06—model.py):
def will_move_cause_check(self, start_position, end_position): tmp = deepcopy(self) ...