Getting the source and destination position

We have called the shift method from the on_square_clicked method. The code for the shift method is responsible for the collection of the necessary arguments that are required for the shift operation.

The code for the shift method is as follows:

def shift(self, start_pos, end_pos):
selected_piece = self.controller.get_piece_at(start_pos)
piece_at_destination = self.controller.get_piece_at(end_pos)
if not piece_at_destination or piece_at_destination.color
!= selected_piece.color:
try:
self.controller.pre_move_validation(start_pos, end_pos)
except exceptions.ChessError as error:
self.info_label["text"] = error.__class__.__name__
else:
self.update_label(selected_piece, start_pos, end_pos)

The code first checks whether a chess piece exists at the destination. If a chess piece does not exist at the destination square, it calls on a method, shift, from the controller, which is a wrapper around the actual shift method from the Model class.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.242.235