Problem Statement: The problem is to design a Chess Game using Object Oriented Principles.
Asked In: Adobe, Amazon, Microsoft, etc.
These type of questions are asked in interviews to Judge the Object-Oriented Design skill of a candidate. So, first of all we should think about the classes.
The main classes will be:
- Spot: A spot represents one block of the 8×8 grid and an optional piece.
- Piece: The basic building block of the system, every piece will be placed on a spot. Piece class is an abstract class. The extended classes (Pawn, King, Queen, Rook, Knight, Bishop) implements the abstracted operations.
- Board: Board is an 8×8 set of boxes containing all active chess pieces.
- Player: Player class represents one of the participants playing the game.
- Move: Represents a game move, containing the starting and ending spot. The Move class will also keep track of the player who made the move.
- Game: This class controls the flow of a game. It keeps track of all the game moves, which player has the current turn, and the final result of the game.
- Design Snake Game
- Game Theory (Normal - form game) | Set 1 (Introduction)
- Predict the winner in Coin Game
- Minimum possible final health of the last monster in a game
- Number of wins for each player in a series of Rock-Paper-Scissor game
- Design a Hit Counter
- Design a Logistics System
- How to design a tiny URL or URL shortener?
- OOPs | Object Oriented Design
- Design an online book reader system
- Design an efficient data structure for given operations
- Efficiently design Insert, Delete and Median queries on a set
- Design a data structure that supports insert, delete, search and getRandom in constant time
- How I cracked EPAM Systems Drive 2020- Complete Guide On Preparation and FAQs
Let’s look at the details. These codes are self-explanatory. You can have a look at the properties/variables and methods of different classes.
Spot: To represent a cell on the chess board:
Piece: An abstract class to represent common functionality of all chess pieces:
King: To represent King as a chess piece:
Knight: To represent Knight as a chess piece
Similarly, we can create classes for other pieces like Queen, Pawns, Rooks, Bishops etc.
Board: To represent a chess board:
Player: An abstract class for player, it can be a human or a computer.
Move: To represent a chess move:
Game: To represent a chess game:
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.