Chess Game in C++














































Chess Game in C++



In this C++ article (with video) ,We implement the most popular 2-player of Chess in C++ .The Game have been designed in C++ keeping in mind the object oriented practices of the  C++ . The Base class i.e Gamepiece Class has 2 pure virtual functions i.e these functions has to be over-ridden who even extends the base class or else the extending class also becomes the abstract class. Getpiece & AreSquareLegal are 2 virtual functions in the base class  . Gamepiece is an abstract class as it has pure virtual functions .

UML Diagram of the Classes




The Gamepiece class as two pure virtual functions: GetPiece() and AreSquaresLegal(). The function GetPiece() is overridden by each piece class to return the char that signifies each piece type: 'P' = pawn, 'N' = knight, 'R' = rook, 'B' = bishop, 'Q' = queen, and 'K' = king. The function AreSquaresLegal() is overridden to test the source and destination locations versus the movement rules for the particular piece.

The board is numbered on the left and bottom from 1 to 8 (as shown above) so that locations ca be specified as a two-digit number and moves can specified as a pair of two-digit numbers. The green squares show the legal moves for a knight. So, that 54 to 42 is a legal move and will return true if passed into the knight's AreSquaresLegal() function.




The main game board is an 8 by 8 array of pointers to piece objects. This is where the polymorphism comes in. Any square can hold any piece or none at all. If we want to know whether a piece can make a certain move, we just pass in the move to the IsLegalMove() function in the piece class. Then correct function is called for any of the pieces: pawn, knight, bishop, rook, queen, and king. However, all we know when the function is called is that it is a piece.

Now we will go through the each of the functions so , that implementations of the functions become clear .

class KnightPiece : public GamePiece
{
public:
KnightPiece(char cColor) : GamePiece(cColor) {}
~KnightPiece() {}
private:
virtual char GetPiece() {
return 'N';
}
bool AreSquaresLegal(int iSrcRow, int iSrcCol, int iDestRow, int iDestCol, GamePiece* GameBoard[8][8]) {
// Destination square is unoccupied or occupied by opposite color
if ((iSrcCol == iDestCol + 1) || (iSrcCol == iDestCol - 1)) {
if ((iSrcRow == iDestRow + 2) || (iSrcRow == iDestRow - 2)) {
return true;
}
}
if ((iSrcCol == iDestCol + 2) || (iSrcCol == iDestCol - 2)) {
if ((iSrcRow == iDestRow + 1) || (iSrcRow == iDestRow - 1)) {
return true;
}
}
return false;
}
};


Rule For Bishop

class BishopPiece : public GamePiece
{
public:
BishopPiece(char cColor) : GamePiece(cColor) {}
~BishopPiece() {}
private:
virtual char GetPiece() {
return 'B';
}
bool AreSquaresLegal(int iSrcRow, int iSrcCol, int iDestRow, int iDestCol, GamePiece* GameBoard[8][8]) {
if ((iDestCol - iSrcCol == iDestRow - iSrcRow) || (iDestCol - iSrcCol == iSrcRow - iDestRow)) {
// Make sure that all invervening squares are empty
int iRowOffset = (iDestRow - iSrcRow > 0) ? 1 : -1;
int iColOffset = (iDestCol - iSrcCol > 0) ? 1 : -1;
int iCheckRow;
int iCheckCol;
for (iCheckRow = iSrcRow + iRowOffset, iCheckCol = iSrcCol + iColOffset;
iCheckRow != iDestRow;
iCheckRow = iCheckRow + iRowOffset, iCheckCol = iCheckCol + iColOffset)
{
if (GameBoard[iCheckRow][iCheckCol] != 0) {
return false;
}
}
return true;
}
return false;
}
};


Rule for Rook Piece


class RookPiece : public GamePiece
{
public:
RookPiece(char cColor) : GamePiece(cColor) {}
~RookPiece() {}
private:
virtual char GetPiece() {
return 'R';
}
bool AreSquaresLegal(int iSrcRow, int iSrcCol, int iDestRow, int iDestCol, GamePiece* GameBoard[8][8]) {
if (iSrcRow == iDestRow) {
// Make sure that all invervening squares are empty
int iColOffset = (iDestCol - iSrcCol > 0) ? 1 : -1;
for (int iCheckCol = iSrcCol + iColOffset; iCheckCol != iDestCol; iCheckCol = iCheckCol + iColOffset) {
if (GameBoard[iSrcRow][iCheckCol] != 0) {
return false;
}
}
return true;
} else if (iDestCol == iSrcCol) {
// Make sure that all invervening squares are empty
int iRowOffset = (iDestRow - iSrcRow > 0) ? 1 : -1;
for (int iCheckRow = iSrcRow + iRowOffset; iCheckRow != iDestRow; iCheckRow = iCheckRow + iRowOffset) {
if (GameBoard[iCheckRow][iSrcCol] != 0) {
return false;
}
}
return true;
}
return false;
}
};


For Queen Piece

class QueenPiece : public GamePiece
{
public:
QueenPiece(char cColor) : GamePiece(cColor) {}
~QueenPiece() {}
private:
virtual char GetPiece() {
return 'Q';
}
bool AreSquaresLegal(int iSrcRow, int iSrcCol, int iDestRow, int iDestCol, GamePiece* GameBoard[8][8]) {
if (iSrcRow == iDestRow) {
// Make sure that all invervening squares are empty
int iColOffset = (iDestCol - iSrcCol > 0) ? 1 : -1;
for (int iCheckCol = iSrcCol + iColOffset; iCheckCol != iDestCol; iCheckCol = iCheckCol + iColOffset) {
if (GameBoard[iSrcRow][iCheckCol] != 0) {
return false;
}
}
return true;
} else if (iDestCol == iSrcCol) {
// Make sure that all invervening squares are empty
int iRowOffset = (iDestRow - iSrcRow > 0) ? 1 : -1;
for (int iCheckRow = iSrcRow + iRowOffset; iCheckRow != iDestRow; iCheckRow = iCheckRow + iRowOffset) {
if (GameBoard[iCheckRow][iSrcCol] != 0) {
return false;
}
}
return true;
} else if ((iDestCol - iSrcCol == iDestRow - iSrcRow) || (iDestCol - iSrcCol == iSrcRow - iDestRow)) {
// Make sure that all invervening squares are empty
int iRowOffset = (iDestRow - iSrcRow > 0) ? 1 : -1;
int iColOffset = (iDestCol - iSrcCol > 0) ? 1 : -1;
int iCheckRow;
int iCheckCol;
for (iCheckRow = iSrcRow + iRowOffset, iCheckCol = iSrcCol + iColOffset;
iCheckRow != iDestRow;
iCheckRow = iCheckRow + iRowOffset, iCheckCol = iCheckCol + iColOffset)
{
if (GameBoard[iCheckRow][iCheckCol] != 0) {
return false;
}
}
return true;
}
return false;
}
};


For King Piece 

class KingPiece : public GamePiece
{
public:
KingPiece(char cColor) : GamePiece(cColor) {}
~KingPiece() {}
private:
virtual char GetPiece() {
return 'K';
}
bool AreSquaresLegal(int iSrcRow, int iSrcCol, int iDestRow, int iDestCol, GamePiece* GameBoard[8][8]) {
int iRowDelta = iDestRow - iSrcRow;
int iColDelta = iDestCol - iSrcCol;
if (((iRowDelta >= -1) && (iRowDelta <= 1)) &&
((iColDelta >= -1) && (iColDelta <= 1)))
{
return true;
}
return false;
}
};


                      Keys to sysmbols used 

 * = white space

 Blank space = black space

 WP = White pawn &  BP = Black pawn

 WN = White Knight & BN = Black Knight

 WB = White Bishop & BB = Black Bishop

 WR = White Rook & BR = Black Rook

 WQ = White Queen & BQ = Black Queen

 WK = White King & BK =Black King

Rule for move is :

Move by selecting row & column to another valid location using row & column

Valid location is checked by the code , invalid location is entered then user is prompted to enter once again


Final Complete Code



#include <iostream>
#include <stdlib.h>
class GamePiece
{
public:
GamePiece(char PieceColor) : mPieceColor(PieceColor) {}
~GamePiece() {}
virtual char GetPiece() = 0;
char GetColor() {
return mPieceColor;
}
bool IsLegalMove(int iSrcRow, int iSrcCol, int iDestRow, int iDestCol, GamePiece* GameBoard[8][8]) {
GamePiece* qpDest = GameBoard[iDestRow][iDestCol];
if ((qpDest == 0) || (mPieceColor != qpDest->GetColor())) {
return AreSquaresLegal(iSrcRow, iSrcCol, iDestRow, iDestCol, GameBoard);
}
return false;
}
private:
virtual bool AreSquaresLegal(int iSrcRow, int iSrcCol, int iDestRow, int iDestCol, GamePiece* GameBoard[8][8]) = 0;
char mPieceColor;
};

class PawnPiece : public GamePiece
{
public:
PawnPiece(char PieceColor) : GamePiece(PieceColor) {}
~PawnPiece() {}
private:
virtual char GetPiece() {
return 'P';
}
bool AreSquaresLegal(int iSrcRow, int iSrcCol, int iDestRow, int iDestCol, GamePiece* GameBoard[8][8]) {
GamePiece* qpDest = GameBoard[iDestRow][iDestCol];
if (qpDest == 0) {
// Destination square is unoccupied
if (iSrcCol == iDestCol) {
if (GetColor() == 'W') {
if (iDestRow == iSrcRow + 1) {
return true;
}
} else {
if (iDestRow == iSrcRow - 1) {
return true;
}
}
}
} else {
// Dest holds piece of opposite color
if ((iSrcCol == iDestCol + 1) || (iSrcCol == iDestCol - 1)) {
if (GetColor() == 'W') {
if (iDestRow == iSrcRow + 1) {
return true;
}
} else {
if (iDestRow == iSrcRow - 1) {
return true;
}
}
}
}
return false;
}
};

class KnightPiece : public GamePiece
{
public:
KnightPiece(char PieceColor) : GamePiece(PieceColor) {}
~KnightPiece() {}
private:
virtual char GetPiece() {
return 'N';
}
bool AreSquaresLegal(int iSrcRow, int iSrcCol, int iDestRow, int iDestCol, GamePiece* GameBoard[8][8]) {
// Destination square is unoccupied or occupied by opposite color
if ((iSrcCol == iDestCol + 1) || (iSrcCol == iDestCol - 1)) {
if ((iSrcRow == iDestRow + 2) || (iSrcRow == iDestRow - 2)) {
return true;
}
}
if ((iSrcCol == iDestCol + 2) || (iSrcCol == iDestCol - 2)) {
if ((iSrcRow == iDestRow + 1) || (iSrcRow == iDestRow - 1)) {
return true;
}
}
return false;
}
};

class BishopPiece : public GamePiece
{
public:
BishopPiece(char PieceColor) : GamePiece(PieceColor) {}
~BishopPiece() {}
private:
virtual char GetPiece() {
return 'B';
}
bool AreSquaresLegal(int iSrcRow, int iSrcCol, int iDestRow, int iDestCol, GamePiece* GameBoard[8][8]) {
if ((iDestCol - iSrcCol == iDestRow - iSrcRow) || (iDestCol - iSrcCol == iSrcRow - iDestRow)) {
// Make sure that all invervening squares are empty
int iRowOffset = (iDestRow - iSrcRow > 0) ? 1 : -1;
int iColOffset = (iDestCol - iSrcCol > 0) ? 1 : -1;
int iCheckRow;
int iCheckCol;
for (iCheckRow = iSrcRow + iRowOffset, iCheckCol = iSrcCol + iColOffset;
iCheckRow != iDestRow;
iCheckRow = iCheckRow + iRowOffset, iCheckCol = iCheckCol + iColOffset)
{
if (GameBoard[iCheckRow][iCheckCol] != 0) {
return false;
}
}
return true;
}
return false;
}
};

class RookPiece : public GamePiece
{
public:
RookPiece(char PieceColor) : GamePiece(PieceColor) {}
~RookPiece() {}
private:
virtual char GetPiece() {
return 'R';
}
bool AreSquaresLegal(int iSrcRow, int iSrcCol, int iDestRow, int iDestCol, GamePiece* GameBoard[8][8]) {
if (iSrcRow == iDestRow) {
// Make sure that all invervening squares are empty
int iColOffset = (iDestCol - iSrcCol > 0) ? 1 : -1;
for (int iCheckCol = iSrcCol + iColOffset; iCheckCol != iDestCol; iCheckCol = iCheckCol + iColOffset) {
if (GameBoard[iSrcRow][iCheckCol] != 0) {
return false;
}
}
return true;
} else if (iDestCol == iSrcCol) {
// Make sure that all invervening squares are empty
int iRowOffset = (iDestRow - iSrcRow > 0) ? 1 : -1;
for (int iCheckRow = iSrcRow + iRowOffset; iCheckRow != iDestRow; iCheckRow = iCheckRow + iRowOffset) {
if (GameBoard[iCheckRow][iSrcCol] != 0) {
return false;
}
}
return true;
}
return false;
}
};

class QueenPiece : public GamePiece
{
public:
QueenPiece(char PieceColor) : GamePiece(PieceColor) {}
~QueenPiece() {}
private:
virtual char GetPiece() {
return 'Q';
}
bool AreSquaresLegal(int iSrcRow, int iSrcCol, int iDestRow, int iDestCol, GamePiece* GameBoard[8][8]) {
if (iSrcRow == iDestRow) {
// Make sure that all invervening squares are empty
int iColOffset = (iDestCol - iSrcCol > 0) ? 1 : -1;
for (int iCheckCol = iSrcCol + iColOffset; iCheckCol != iDestCol; iCheckCol = iCheckCol + iColOffset) {
if (GameBoard[iSrcRow][iCheckCol] != 0) {
return false;
}
}
return true;
} else if (iDestCol == iSrcCol) {
// Make sure that all invervening squares are empty
int iRowOffset = (iDestRow - iSrcRow > 0) ? 1 : -1;
for (int iCheckRow = iSrcRow + iRowOffset; iCheckRow != iDestRow; iCheckRow = iCheckRow + iRowOffset) {
if (GameBoard[iCheckRow][iSrcCol] != 0) {
return false;
}
}
return true;
} else if ((iDestCol - iSrcCol == iDestRow - iSrcRow) || (iDestCol - iSrcCol == iSrcRow - iDestRow)) {
// Make sure that all invervening squares are empty
int iRowOffset = (iDestRow - iSrcRow > 0) ? 1 : -1;
int iColOffset = (iDestCol - iSrcCol > 0) ? 1 : -1;
int iCheckRow;
int iCheckCol;
for (iCheckRow = iSrcRow + iRowOffset, iCheckCol = iSrcCol + iColOffset;
iCheckRow != iDestRow;
iCheckRow = iCheckRow + iRowOffset, iCheckCol = iCheckCol + iColOffset)
{
if (GameBoard[iCheckRow][iCheckCol] != 0) {
return false;
}
}
return true;
}
return false;
}
};

class KingPiece : public GamePiece
{
public:
KingPiece(char PieceColor) : GamePiece(PieceColor) {}
~KingPiece() {}
private:
virtual char GetPiece() {
return 'K';
}
bool AreSquaresLegal(int iSrcRow, int iSrcCol, int iDestRow, int iDestCol, GamePiece* GameBoard[8][8]) {
int iRowDelta = iDestRow - iSrcRow;
int iColDelta = iDestCol - iSrcCol;
if (((iRowDelta >= -1) && (iRowDelta <= 1)) &&
((iColDelta >= -1) && (iColDelta <= 1)))
{
return true;
}
return false;
}
};

class CBoard
{
public:
CBoard() {
for (int iRow = 0; iRow < 8; ++iRow) {
for (int iCol = 0; iCol < 8; ++iCol) {
MainGameBoard[iRow][iCol] = 0;
}
}
// Allocate and place black pieces
for (int iCol = 0; iCol < 8; ++iCol) {
MainGameBoard[6][iCol] = new PawnPiece('B');
}
MainGameBoard[7][0] = new RookPiece('B');
MainGameBoard[7][1] = new KnightPiece('B');
MainGameBoard[7][2] = new BishopPiece('B');
MainGameBoard[7][3] = new KingPiece('B');
MainGameBoard[7][4] = new QueenPiece('B');
MainGameBoard[7][5] = new BishopPiece('B');
MainGameBoard[7][6] = new KnightPiece('B');
MainGameBoard[7][7] = new RookPiece('B');
// Allocate and place white pieces
for (int iCol = 0; iCol < 8; ++iCol) {
MainGameBoard[1][iCol] = new PawnPiece('W');
}
MainGameBoard[0][0] = new RookPiece('W');
MainGameBoard[0][1] = new KnightPiece('W');
MainGameBoard[0][2] = new BishopPiece('W');
MainGameBoard[0][3] = new KingPiece('W');
MainGameBoard[0][4] = new QueenPiece('W');
MainGameBoard[0][5] = new BishopPiece('W');
MainGameBoard[0][6] = new KnightPiece('W');
MainGameBoard[0][7] = new RookPiece('W');
}
~CBoard() {
for (int iRow = 0; iRow < 8; ++iRow) {
for (int iCol = 0; iCol < 8; ++iCol) {
delete MainGameBoard[iRow][iCol];
MainGameBoard[iRow][iCol] = 0;
}
}
}

void Print() {
using namespace std;
const int kiSquareWidth = 4;
const int kiSquareHeight = 3;
for (int iRow = 0; iRow < 8*kiSquareHeight; ++iRow) {
int iSquareRow = iRow/kiSquareHeight;
// Print side border with numbering
if (iRow % 3 == 1) {
cout << '-' << (char)('1' + 7 - iSquareRow) << '-';
} else {
cout << "---";
}
// Print the chess board
for (int iCol = 0; iCol < 8*kiSquareWidth; ++iCol) {
int iSquareCol = iCol/kiSquareWidth;
if (((iRow % 3) == 1) && ((iCol % 4) == 1 || (iCol % 4) == 2) && MainGameBoard[7-iSquareRow][iSquareCol] != 0) {
if ((iCol % 4) == 1) {
cout << MainGameBoard[7-iSquareRow][iSquareCol]->GetColor();
} else {
cout << MainGameBoard[7-iSquareRow][iSquareCol]->GetPiece();
}
} else {
if ((iSquareRow + iSquareCol) % 2 == 1) {
cout << '*';
} else {
cout << ' ';
}
}
}
cout << endl;
}
// Print the bottom border with numbers
for (int iRow = 0; iRow < kiSquareHeight; ++iRow) {
if (iRow % 3 == 1) {
cout << "---";
for (int iCol = 0; iCol < 8*kiSquareWidth; ++iCol) {
int iSquareCol = iCol/kiSquareWidth;
if ((iCol % 4) == 1) {
cout << (iSquareCol + 1);
} else {
cout << '-';
}
}
cout << endl;
} else {
for (int iCol = 1; iCol < 9*kiSquareWidth; ++iCol) {
cout << '-';
}
cout << endl;
}
}
}

bool IsInCheck(char PieceColor) {
// Find the king
int iKingRow;
int iKingCol;
for (int iRow = 0; iRow < 8; ++iRow) {
for (int iCol = 0; iCol < 8; ++iCol) {
if (MainGameBoard[iRow][iCol] != 0) {
if (MainGameBoard[iRow][iCol]->GetColor() == PieceColor) {
if (MainGameBoard[iRow][iCol]->GetPiece() == 'K') {
iKingRow = iRow;
iKingCol = iCol;
}
}
}
}
}
// Run through the opponent's pieces and see if any can take the king
for (int iRow = 0; iRow < 8; ++iRow) {
for (int iCol = 0; iCol < 8; ++iCol) {
if (MainGameBoard[iRow][iCol] != 0) {
if (MainGameBoard[iRow][iCol]->GetColor() != PieceColor) {
if (MainGameBoard[iRow][iCol]->IsLegalMove(iRow, iCol, iKingRow, iKingCol, MainGameBoard)) {
return true;
}
}
}
}
}

return false;
}

bool CanMove(char PieceColor) {
// Run through all pieces
for (int iRow = 0; iRow < 8; ++iRow) {
for (int iCol = 0; iCol < 8; ++iCol) {
if (MainGameBoard[iRow][iCol] != 0) {
// If it is a piece of the current player, see if it has a legal move
if (MainGameBoard[iRow][iCol]->GetColor() == PieceColor) {
for (int iMoveRow = 0; iMoveRow < 8; ++iMoveRow) {
for (int iMoveCol = 0; iMoveCol < 8; ++iMoveCol) {
if (MainGameBoard[iRow][iCol]->IsLegalMove(iRow, iCol, iMoveRow, iMoveCol, MainGameBoard)) {
// Make move and check whether king is in check
GamePiece* qpTemp = MainGameBoard[iMoveRow][iMoveCol];
MainGameBoard[iMoveRow][iMoveCol] = MainGameBoard[iRow][iCol];
MainGameBoard[iRow][iCol] = 0;
bool bCanMove = !IsInCheck(PieceColor);
// Undo the move
MainGameBoard[iRow][iCol] = MainGameBoard[iMoveRow][iMoveCol];
MainGameBoard[iMoveRow][iMoveCol] = qpTemp;
if (bCanMove) {
return true;
}
}
}
}
}
}
}
}
return false;
}

GamePiece* MainGameBoard[8][8];
};

class ChessBoard
{
public:
ChessBoard() : mcPlayerTurn('W') {}
~ChessBoard() {}

void Start() {
do {
GetNextMove(mqGameBoard.MainGameBoard);
AlternateTurn();
} while (!IsGameOver());
mqGameBoard.Print();
}

void GetNextMove(GamePiece* GameBoard[8][8]) {
using namespace std;
bool bValidMove = false;
do {
system ("clear");
cout<<endl<<endl<<" Welcome to Chess Game Developed by Cppsecrets "<<endl<<endl<<endl;
cout<<" Keys to sysmbols used "<<endl<<endl<<endl;
cout<<" * = white space"<<endl;
cout<<" Blank space = black space"<<endl;
cout<<" WP = White pawn & BP = Black pawn"<<endl;
cout<<" WN = White Knight & BN = Black Knight"<<endl;
cout<<" WB = White Bishop & BB = Black Bishop"<<endl;
cout<<" WR = White Rook & BR = Black Rook"<<endl;
cout<<" WQ = White Queen & BQ = Black Queen"<<endl;
cout<<" WK = White King & BK =Black King"<<endl;
cout<<"Rule for move is :"<<endl;
cout<<"Move by selecting row & column to another valid location using row & column"<<endl<<endl<<endl;
mqGameBoard.Print();

// Get input and convert to coordinates
cout << mcPlayerTurn << "'s Move: ";
int iStartMove;
cin >> iStartMove;
int iStartRow = (iStartMove / 10) - 1;
int iStartCol = (iStartMove % 10) - 1;

cout << "To: ";
int iEndMove;
cin >> iEndMove;
int iEndRow = (iEndMove / 10) - 1;
int iEndCol = (iEndMove % 10) - 1;

// Check that the indices are in range
// and that the source and destination are different
if ((iStartRow >= 0 && iStartRow <= 7) &&
(iStartCol >= 0 && iStartCol <= 7) &&
(iEndRow >= 0 && iEndRow <= 7) &&
(iEndCol >= 0 && iEndCol <= 7)) {
// Additional checks in here
GamePiece* qpCurrPiece = GameBoard[iStartRow][iStartCol];
// Check that the piece is the correct color
if ((qpCurrPiece != 0) && (qpCurrPiece->GetColor() == mcPlayerTurn)) {
// Check that the destination is a valid destination
if (qpCurrPiece->IsLegalMove(iStartRow, iStartCol, iEndRow, iEndCol, GameBoard)) {
// Make the move
GamePiece* qpTemp = GameBoard[iEndRow][iEndCol];
GameBoard[iEndRow][iEndCol] = GameBoard[iStartRow][iStartCol];
GameBoard[iStartRow][iStartCol] = 0;
// Make sure that the current player is not in check
if (!mqGameBoard.IsInCheck(mcPlayerTurn)) {
delete qpTemp;
bValidMove = true;
} else { // Undo the last move
GameBoard[iStartRow][iStartCol] = GameBoard[iEndRow][iEndCol];
GameBoard[iEndRow][iEndCol] = qpTemp;
}
}
}
}
if (!bValidMove) {
cout << "Invalid Move!" << endl;
}
} while (!bValidMove);
}

void AlternateTurn() {
mcPlayerTurn = (mcPlayerTurn == 'W') ? 'B' : 'W';
}

bool IsGameOver() {
// Check that the current player can move
// If not, we have a stalemate or checkmate
bool bCanMove(false);
bCanMove = mqGameBoard.CanMove(mcPlayerTurn);
if (!bCanMove) {
if (mqGameBoard.IsInCheck(mcPlayerTurn)) {
AlternateTurn();
std::cout << "Checkmate, " << mcPlayerTurn << " Wins!" << std::endl;
} else {
std::cout << "Stalemate!" << std::endl;
}
}
return !bCanMove;
}
private:
CBoard mqGameBoard;
char mcPlayerTurn;
};

int main() {
ChessBoard qGame;
qGame.Start();
return 0;
}








More Articles of Khitish Panigrahi:

Name Views Likes
Find and Replace Pattern 673 3
C++ implementation to find All combinations that add up to a given sum 608 0
Implementation of Donut.c 5706 1
Hamiltonian Cycle 2216 3
Add Lists 497 0
Unique Paths 520 3
Minimum Falling Path Sum 648 3
Word Break 595 3
Working of Internet 435 1
String Compression 1172 0
Palindromic Substrings 513 4
Formation of Process from Program 412 1
3Sum 470 3
Invert Binary Tree 755 4
0-1knapsack 623 2
Evaluate Reverse Polish Notation 1776 3
Permutations 420 4
Find Peak Element 1085 4
Maximum Subarray 449 5
Integer to Roman 2690 2
C++ Library for timing (Chrono Library) 1148 1
Programmatical termination of processes 504 1
Perfect Number 532 3
Number of Operations to Make Network Connected 1178 2
C++ implementation of Odd Even Linked List 871 0
Distance Between Bus Stops 585 3
Check if Binary Tree is BST 436 5
Partitioning the List 399 0
Function Pointer Typedef 1364 1
IOT SMART HOME 736 0
Friend Circles 1145 2
Remove duplicates from an unsorted linked list 537 0
Cycle in Undirected Graph 987 2
Multiple Word Searching Algorithm 479 8
Palindrome Partitioning 433 3
Find All Anagrams in a String 902 3
Path with Maximum Gold 710 3
Working of Home Networks 502 2
Container With Most Water 587 3
Loop Detection in LinkedList 342 0
Cheapest Flights Within K Stops 1506 2
C++ implementation of Partition Equal Subset Sum 454 0
C++ implementation to find Excel sheet Column Number 311 0
Longest Palindromic Subsequence (Print Subsequence) 1023 2
Letter Tile Possibilities 651 3
Connect all siblings in a Binary Search Tree 794 2
Minimum Path Sum 658 3
C++ Hebb Learning Implementation 2141 0
Complete Employee Management System 7230 1
Combinations 409 7
C++ implementation of Longest Increasing Subsequence 418 0
Permutation of each other 293 0
Making HTTP Requests and Handling Callbacks 772 0
Valid Anagram 404 8
Multiply Strings 1794 5
C++ implementation to detect all the cycles in an undirected graph 1044 0
Longest Palindromic Subsequence (print only length) 430 2
Edit Distance 475 2
C++ implementation of Phone Book Management System 10839 0
Rotate Image 2292 1
C++ implementation of Road Transportation Management System 2876 0
Populating Next Right Pointers in Each Node 485 2
Last Stone Weight 1937 2
C++ implementation of Word Search 881 0
C++ implementation of Subsets with duplicates 339 0
Intersection of Two Linked Lists 424 3
Operator Overloading concepts in C++ 430 0
C++ implementation of Validate IP Address 2804 0
C++ implementation of Indian Railways Reservation System 1093 0
C++ implementation of college and Attendance management 3969 0
Maximum Depth of Binary Tree 538 3
Fibonacci Number 449 5
C++ implementation to Add Strings 424 0
Variadic function in C/ C++ 672 1
Boats to Save People 889 3
C++ implementation to detect cycle in a directed graph 2238 0
Pointer to Struct 591 1
House Robber with houses arranged in circular manner 889 3
Find Single Non-repeated Number 553 3
Setting up server 343 0
The k-th Lexicographical String of All Happy Strings of Length n 708 3
Unique Paths with obstacles 663 2
longest palindromic substring(improved) 417 2
Factorial Trailing Zeroes 418 2
String Rotation 950 0
C++ implementation of Bus Booking System 3765 0
3Sum Closest 517 2
kth to last element of a singly linked list 552 0
Jump Game 758 3
Maximum Product Subarray 382 4
Longest Common Subsequence (Print only Length) 618 2
ZigZag Conversion 763 4
Implement an algorithm to determine if a string has all unique characters 409 0
Relationship between IoT and cloud computing 935 1
Last Stone Weight II(any weight can be picked) 402 0
Commutable Islands 1551 2
Longest Substring Without Repeating Characters 501 4
Longest Arithmetic Sequence 815 3
Multiple Booting Guide with detail explanation of working 406 1
Minimum number of Perfect square needed to form a number 493 7
C++ implementation of Minimum number of Perfect square needed to form a number 382 0
Combination Sum 1129 4
Max Area of Island 541 3
Letter Combinations of a Phone Number 831 4
One Distance Away 440 0
Remove Nth Node From End of List 509 6
Concept of Signed and Unsigned Numbers 633 1
Time Needed to Inform All Employees 892 2
Best Time to Buy and Sell Stock 1530 3
Top K Frequent Elements 637 7
Intersection in LinkedList 583 0
Detailed analysis of Complex number using C++ 413 1
Implement strStr() 1129 4
Check Palindrome Permutation 414 0
Maximum Length of a Concatenated String with Unique Characters 572 3
Hamiltonian Path 2456 3
Relative Sort Array 440 3
Sequential Digits 614 3
Binary Tree Zigzag Level Order Traversal 391 4
C++ implementation of Shortest Path Problem 444 0
Roman to Integer 863 2
Delete a node from BST in C++ 462 3
Number of Matching Subsequences 549 3
C++ MOVIE TICKET BOOKING SYSTEM 13758 0
Number of Islands 496 3
Course Schedule II (print the order) 425 2
Permutation Sequence 533 16
Stack Pushing Game(Push Dominoes Game) 960 3
Inheritance implementation in C++ 473 0
Complete Restaurant/canteen management system 8180 0
Valid Palindrome 859 4
Course Schedule 921 2
Longest Palindromic Substring 401 2
C++ implementation of finding Kth Smallest Element in a BST 464 0
Travelling Salesman Problem 1846 3
Dijkstra 995 2
C++ implementation of Permutation with duplicates 561 0
Priority Queue 485 0
Deadlock Simulator in C++ 2880 0
Permutation Sequence 386 4
Maximal Square 497 3
C++ implementation of Is Subsequence Program 1241 0
C++ implementation of Coin Change 1007 0
House Robber 651 3
4Sum 462 3
Minimum Size Subarray Sum 518 3
C++ implementation of parking management system 5122 0
Location Based Weather Predictor 1830 0
Climbing Stairs 484 5
String to Integer (atoi) 403 4
Children Sum Parent 476 5
C++ HEALTH MANAGEMENT SYSTEM 1923 0
Triangle 491 3
Majority Element 436 2
Longest Mountain in Array 818 4
Subarray Sum Equals K 562 3
Swap Nodes in Pairs 453 5
Restore IP Addresses 616 4
Convert String to URL 1020 0
Create Ranges 505 3
Blood Bank Management System 3443 0
Linked List Cycle 381 6
Delete Middle Node in LinkedList 588 1
Smart and Safe Cab Finder Algorithm 1290 3
Chess Game in C++ 18809 1
Delete Node in Linked List without a head pointer 714 2
C++ Adaline Implementation 1165 0
Permutation in String 416 3
Merge Intervals 621 3
Gas Station 730 7
Increasing Triplet Subsequence 734 5
Longest Common Subsequence (Print the Subsequence) 570 2

Comments