You are on page 1of 18

Object Oriented Analysis and Design

Project

2 Player Chess Game

Submitted to -
Ms. Sarishty Gupta
Submitted by -
Akshay Nagar ( 2014UCP1524 )
Manish Patki ( 2014UCP1550 )

1
Index

Sr. no Title Page No.

1 Introduction 3

2 Modules Implemented 4

3 Development Model 5
4 Design 6

5 Implementation Details 10

6 Output for Test cases 15

2
Introduction
This project basically consists implementation of a 2 player chess
game. The basic objective a Chess game is to capture the Enemy
King. It consists of an 8x8 square board, with alternate black and
white boxes. There are 2 players, one black and other white, and
each player has certain type of pieces, namely King, Queen, Bishop,
Rook, Knight and Pawns.
Tools used –
 C++
 OpenGL

Implementation – C++ is used to implement game logic and


validate all moves. Some important classes are -
 Board – This class consists of an 8x8 matrix of pointers, where
each pointer is either a NULL (empty box), or points to a piece
present at that position. The Board is initialized with all the
pieces on their appropriate positions as per the standard Chess
rules.

 Player – This class basically signifies a player, where each


player is characterised by his/her Name, and Colour.

 Piece – The most important Class of the Game. It is the Base


class of all the different type of pieces. All the different pieces
are inherited from this class. This class basically includes Name
of the piece, its colour, and its (x,y) coordinates on the board.

 Other Derived Classes – As stated above, all the different


pieces, namely King, Queen, Bishop, Rook, Knight and Pawns
have a class of their own, and necessary attributes.
OpenGL is used to implement the basic graphics of the game.

3
Modules implemented:
The game is divided into 2 main modules

1) Graphics Module - In the graphics module, OpenGL loads the


display, which consists of the chess board, i.e. an 8x8 square
board, with alternate black and white boxes. The player
performs moves by clicking on a particular box, and then
clicking on another box where the player wishes to move the
selected piece.

2) Game module – The game module basically works at the


backend. Whenever the player performs some move on the
board, the backend code checks for all the necessary valid
conditions. That is, the module checks if the current requested
move is valid, then performs the move and updates the board,
and the turn of the player is changed accordingly. After each
and every move, some special conditions need to be checked,
like the Checkmate and Stalemate condition.
Every move performed can be classified in 2 types.
a) Legal Moves b) Pseudo Legal Moves.

Legal Moves are those moves which result in a valid game


state.
Pseudo Legal moves are those moves whose preconditions are
met, but after performing the move, the resulting board
position may be unacceptable.
Eg. A move can be called as Pseudo legal, if it moves a
particular piece into an allowed position, but this move leads to
the king going in checked state.
To avoid Pseudo Legal moves, the game module performs
Backtracking, and goes to the last valid state.

4
Development model – Prototype

Phase 1
 Initially we developed a prototype of the game.
 The prototype implemented the basic game logic and used
simple graphics.
Phase 2
 Special cases like the En Passant rule, Castling, Pawn
Promotion, Checkmate and Stalemate, Fork during En Passant
were implemented in this phase.

5
Design
DFD level 0 :

DFD level 1 :

6
Flowchart

7
Flowchart (contd.)

8
Flowchart (contd.)

9
Implementation Details
The following part contains code snippets, and inner specific
implementation details.
1) Class details.

Class Piece is an Abstract class, as it contains many pure virtual


functions. It serves as the parent class for all the subsequent
class

10
The above snippet shows that the class Queen is Multiply
Inherited from the class .

11
2) Checkmate details

Case 1 – When no possible position available for king.

Case 2 – When the check giver cannot be killed by any other


player

12
Case 3 – Path intervention by other player

13
When all the 3 check flags are set, then Checkmate condition
occurs.

3) Stalemate code

14
Output for test cases

Following section shows the behaviour of the code, when


subjected to different inputs.

1) Basic view of the Game

15
2) Illegal move.

16
3) General Checkmate condition

Check avoidance condition

17
4) Pawn promotion.

18

You might also like