Keep game statistics

The pre_move_validation() method also calls another method called update_game_statistics() on successfully recording a move (see 4.06model.py):

    def update_game_statistics(self, piece, dest, start_pos, end_pos):
if piece.color == 'black':
self.fullmove_number += 1
self.halfmove_clock += 1
abbr = piece.name
if abbr == 'pawn':
abbr = ''
self.halfmove_clock = 0
if dest is None:
move_text = abbr + end_pos.lower()
else:
move_text = abbr + 'x' + end_pos.lower()
self.halfmove_clock = 0
self.history.append(move_text)

Congratulations, our chess game is now functional!

Let's complete the iteration by binding the File | New Game menu item to start a new game. Earlier, we defined the start_new_game() method. Now, it's simply a matter of calling it from the on_new_game_menu_clicked() method, as follows (4.06view.py):

def on_new_game_menu_clicked(self):
self.start_new_game()
..................Content has been hidden....................

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