Grokking the Object Oriented Design Interview

0% completed

Design Chess

Let's design a system to play online chess.

Chess is a two-player strategy board game played on a chessboard, which is a checkered gameboard with 64 squares arranged in an 8×8 grid. There are a few versions of game types that people play all over the world. In this design problem, we are going to focus on designing a two-player online chess game.

System Requirements

We'll focus on the following set of requirements while designing the game of chess:

  1. The system should support two online players to play a game of chess.

  2. All rules of international chess will be followed.

3

.....

.....

.....

Like the course? Get enrolled and start learning!
E H

E H

· 2 years ago

  1. The Knight and King classes both have the following code to see if the end box has a Piece of the same colour as the King. If the Box is empty however, wouldn't getPiece return null, and in return throw an error when isWhite is called on it?
if (end.getPiece().isWhite() == this.isWhite()) { return false; }
  1. The boxes matrix is never initialized in the Board class, so "resetting" the board in the constructor will cause a null pointer exception.
A

akshayavb99

· 2 years ago

What does it mean when a class has a function with same name as the class?

class Board:

def init(self):

self.__boxes = [[]]

def Board(self):

self.reset_board()