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
- Expectimax Algorithm in Game Theory
- Minimum possible final health of the last monster in a game
- Largest odd divisor Game to check which player wins
- Number of wins for each player in a series of Rock-Paper-Scissor game
- Design a Hit Counter
- Algorithms Design Techniques
- Design a DFA that accepts a string containing 3 a's and 3 b's
- How to design a tiny URL or URL shortener?
- Design a Logistics System
- OOPs | Object Oriented Design
- Design an efficient data structure for given operations
- Design an online book reader system
- Efficiently design Insert, Delete and Median queries on a set
- Types of Models in Object Oriented Modeling and Design
- Design a Queue data structure to get minimum or maximum in O(1) time
- Design a data structure that supports insert, delete, getRandom in O(1) with duplicates
- Implementation of Tic-Tac-Toe for 2 person game (User vs. User)
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:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
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.