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

Rules for the Knight

The knight is a different beast because it does not move orthogonally or diagonally. It can also jump over chess pieces.

Like the rules that we followed earlier to arrive at ORTHOGONAL_POSITIONS and DIAGONAL_POSITIONS, we can similarly arrive at the rules that are required to determine the KNIGHT_POSITIONS tuple. This is defined in 4.04configurations.py, as follows:

KNIGHT_POSITIONS = ((-2,-1),(-2,1),(-1,-2),(-1,2),(1,-2),(1,2),(2,-1),(2,1))

Next, let's override the moves_available method from the Knight class (see code 4.04piece.py):

class Knight(Piece): def moves_available(self, current_position):   model = self.model   allowed_moves = []   start_position = get_numeric_notation(current_position.upper()) piece = model.get(pos.upper()) ...

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