Creating a Piece class

Think about it. We need to define rules for all the different chess pieces. Some attributes and methods such as color will be common to all the chess pieces, while other attributes/methods such as rules for movement will vary for each chess piece.

First, we'll define a new Piece class. This class will have the attributes and methods that are common to all the chess pieces. Then, we will define classes for every individual piece as a subclass of this parent Piece class. We can then override all the attributes and methods in these individual classes.

The code will look like this (see code 4.02piece.py):

from configurations import * class Piece(): def __init__(self, color): self.name = self.__class__.__name__.lower() if color ...

Get Tkinter GUI Application Development Blueprints 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.