├── .gitignore ├── COPYING ├── Chess.pro ├── Images.qrc ├── Images ├── bishop_black.svg ├── bishop_white.svg ├── exp.png ├── king_black.svg ├── king_white.svg ├── knight_black.svg ├── knight_white.svg ├── pawn_black.svg ├── pawn_white.svg ├── profile.png ├── queen_black.svg ├── queen_white.svg ├── rook_black.svg └── rook_white.svg ├── README.md ├── main.cpp ├── mainwindow.cpp ├── mainwindow.h ├── mainwindow.ui ├── screenshot └── screenshot.png ├── tile.cpp ├── tile.h ├── ui_mainwindow.h ├── validation.cpp └── validation.h /.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore temporary files generated 2 | build/* 3 | Makefile 4 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | 2 | CINES 3 | 4 | Name: 5 | CINES - Chess Is Not Entertainment Singally 6 | 7 | Author: 8 | Sagar Rakshe srrakshe@gmail.com 9 | Nisarg Patel 10 | Sanket Sudake sanketsudake@gmail.com 11 | Nikhil Pachpande 12 | 13 | COPYRIGHT 14 | CINES Copyright © 2012 15 | 16 | This program is free software: you can redistribute it and/or modify 17 | it under the terms of the GNU General Public License as published by 18 | the Free Software Foundation, either version 3 of the License, or 19 | (at your option) any later version. 20 | 21 | This program is distributed in the hope that it will be useful, 22 | but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | GNU General Public License for more details. 25 | 26 | You should have received a copy of the GNU General Public License 27 | along with this program. If not, see 28 | . 29 | 30 | -------------------------------------------------------------------------------- /Chess.pro: -------------------------------------------------------------------------------- 1 | #------------------------------------------------- 2 | # 3 | # Project created by QtCreator 2012-03-21T22:01:54 4 | # 5 | #------------------------------------------------- 6 | 7 | QT += core gui 8 | 9 | greaterThan(QT_MAJOR_VERSION, 4) { 10 | # Qt 5 11 | QT += widgets 12 | } 13 | 14 | TARGET = Chess 15 | TEMPLATE = app 16 | 17 | DESTDIR = build 18 | 19 | OBJECTS_DIR = $$DESTDIR/objects 20 | MOC_DIR = $$DESTDIR/moc 21 | UI_DIR = $$DESTDIR/ui 22 | RCC_DIR = $$DESTDIR/qrc 23 | 24 | SOURCES += main.cpp\ 25 | mainwindow.cpp \ 26 | tile.cpp \ 27 | validation.cpp 28 | 29 | HEADERS += mainwindow.h \ 30 | tile.h \ 31 | validation.h 32 | 33 | FORMS += mainwindow.ui 34 | 35 | RESOURCES += \ 36 | Images.qrc 37 | -------------------------------------------------------------------------------- /Images.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | Images/bishop_black.svg 4 | Images/bishop_white.svg 5 | Images/king_black.svg 6 | Images/king_white.svg 7 | Images/knight_black.svg 8 | Images/knight_white.svg 9 | Images/pawn_black.svg 10 | Images/pawn_white.svg 11 | Images/queen_black.svg 12 | Images/queen_white.svg 13 | Images/rook_black.svg 14 | Images/rook_white.svg 15 | Images/profile.png 16 | 17 | 18 | -------------------------------------------------------------------------------- /Images/bishop_black.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 15 | 17 | 18 | 20 | image/svg+xml 21 | 23 | 24 | 25 | 26 | 27 | 29 | 116 | 117 | -------------------------------------------------------------------------------- /Images/bishop_white.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 15 | 17 | 18 | 20 | image/svg+xml 21 | 23 | 24 | 25 | 26 | 27 | 29 | 124 | 125 | -------------------------------------------------------------------------------- /Images/exp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sanketsudake/CHESS-in-Qt/3e28a06450275d9727d078e30e783f98892fb417/Images/exp.png -------------------------------------------------------------------------------- /Images/king_black.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 15 | 17 | 18 | 20 | image/svg+xml 21 | 23 | 24 | 25 | 26 | 27 | 29 | 135 | 136 | -------------------------------------------------------------------------------- /Images/king_white.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 15 | 17 | 18 | 20 | image/svg+xml 21 | 23 | 24 | 25 | 26 | 27 | 29 | 143 | 144 | -------------------------------------------------------------------------------- /Images/knight_black.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 15 | 17 | 18 | 20 | image/svg+xml 21 | 23 | 24 | 25 | 26 | 27 | 29 | 101 | 102 | -------------------------------------------------------------------------------- /Images/knight_white.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 15 | 17 | 18 | 20 | image/svg+xml 21 | 23 | 24 | 25 | 26 | 27 | 29 | 123 | 124 | -------------------------------------------------------------------------------- /Images/pawn_black.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 15 | 17 | 18 | 20 | image/svg+xml 21 | 23 | 24 | 25 | 26 | 27 | 29 | 76 | 77 | -------------------------------------------------------------------------------- /Images/pawn_white.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 15 | 17 | 18 | 20 | image/svg+xml 21 | 23 | 24 | 25 | 26 | 27 | 29 | 92 | 93 | -------------------------------------------------------------------------------- /Images/profile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sanketsudake/CHESS-in-Qt/3e28a06450275d9727d078e30e783f98892fb417/Images/profile.png -------------------------------------------------------------------------------- /Images/queen_black.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 15 | 17 | 18 | 20 | image/svg+xml 21 | 23 | 24 | 25 | 26 | 27 | 29 | 141 | 142 | -------------------------------------------------------------------------------- /Images/queen_white.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 15 | 17 | 18 | 20 | image/svg+xml 21 | 23 | 24 | 25 | 26 | 27 | 29 | 139 | 140 | -------------------------------------------------------------------------------- /Images/rook_black.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 15 | 17 | 18 | 20 | image/svg+xml 21 | 23 | 24 | 25 | 26 | 27 | 29 | 73 | 74 | -------------------------------------------------------------------------------- /Images/rook_white.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 15 | 17 | 18 | 20 | image/svg+xml 21 | 23 | 24 | 25 | 26 | 27 | 29 | 83 | 84 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | CINES 2 | ===== 3 | CINES is Two player chess created in Qt-cross platform. 4 | Works fully for two players. 5 | 6 | Description 7 | -------------------------------------------------------------------- 8 | 9 | CINES is attempt to make traditional chess ,moreover we are planning 10 | to make this chess to played remotely by two players .All source is 11 | developed using Qt-Creator. This code expected to work on any platform 12 | like Windows,Unix or Mac as Qt supports cross platform. 13 | We have tried to perform validation as much as possible,it is possible 14 | that ,there may some bugs remain. There are some known bugs, 15 | we are trying to fix them. 16 | 17 | Screenshot 18 | -------------------------------------------------------------- 19 | 20 | * ![Screenshot](https://github.com/tripples/CHESS-in-Qt/blob/master/screenshot/screenshot.png) 21 | 22 | 23 | Usage 24 | ---------------------------------------------------------------- 25 | Getting started with CINES 26 | 27 | ``` 28 | $ git clone https://github.com/tripples/CHESS-in-Qt.git; cd CHESS-in-Qt 29 | $ qmake . 30 | $ make 31 | $ ./build/Chess 32 | ``` 33 | -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "mainwindow.h" 3 | #include "tile.h" 4 | 5 | int count=0,turn=1,exp[60],max=0; 6 | int wR,wC,bR,bC; 7 | Tile *click1; 8 | 9 | Tile *tile[8][8] = { { NULL } }; 10 | 11 | class Border 12 | { 13 | public: 14 | Border(); 15 | void outline(QWidget *baseWidget, int xPos, int yPos, int Pos) 16 | { 17 | QLabel *outLabel = new QLabel(baseWidget); 18 | 19 | if(!Pos) 20 | outLabel->setGeometry(xPos,yPos,552,20); //Horizontal Borders 21 | 22 | else 23 | outLabel->setGeometry(xPos,yPos,20,512); //Vertical Borders 24 | 25 | outLabel->setStyleSheet("QLabel { background-color :rgb(170, 170, 127); color : black; }"); 26 | } 27 | }; 28 | 29 | void accessories(QWidget *baseWidget) 30 | { 31 | QLabel *player2 = new QLabel(baseWidget); 32 | QLabel *name2 = new QLabel("Player 2", baseWidget); 33 | QLabel *time2 = new QLabel("00:00:00", baseWidget); 34 | 35 | QLabel *player1 = new QLabel(baseWidget); 36 | QLabel *name1 = new QLabel("Player 1", baseWidget); 37 | QLabel *time1 = new QLabel("00:00:00", baseWidget); 38 | 39 | QLabel *moves = new QLabel(baseWidget); 40 | 41 | name1->setGeometry(125,610,80,20); 42 | time1->setGeometry(120,635,80,20); 43 | player1->setGeometry(100,500,100,100); 44 | player1->setPixmap(QPixmap(":/Images/profile.png")); 45 | 46 | name2->setGeometry(125,210,80,20); 47 | time2->setGeometry(120,235,80,20); 48 | player2->setGeometry(100,100,100,100); 49 | player2->setPixmap(QPixmap(":/Images/profile.png")); 50 | 51 | moves->setGeometry(1000,105,250,550); 52 | moves->setStyleSheet("QLabel {background-color: white;}"); 53 | 54 | } 55 | 56 | void chessBoard(QWidget *baseWidget, Tile *tile[8][8]) 57 | { 58 | int i,j,k=0,hor,ver; 59 | Border *border[4]={ NULL }; 60 | 61 | //borderDisplay 62 | { 63 | border[0]->outline(baseWidget,330,105,0); 64 | border[1]->outline(baseWidget,330,637,0); 65 | border[2]->outline(baseWidget,330,125,1); 66 | border[2]->outline(baseWidget,862,125,1); 67 | } 68 | 69 | //Create 64 tiles (allocating memories to the objects of Tile class) 70 | ver=125; 71 | for(i=0;i<8;i++) 72 | { 73 | hor=350; 74 | for(j=0;j<8;j++) 75 | { 76 | tile[i][j] = new Tile(baseWidget); 77 | tile[i][j]->tileColor=(i+j)%2; 78 | tile[i][j]->piece=0; 79 | tile[i][j]->row=i; 80 | tile[i][j]->col=j; 81 | tile[i][j]->tileNum=k++; 82 | tile[i][j]->tileDisplay(); 83 | tile[i][j]->setGeometry(hor,ver,64,64); 84 | hor+=64; 85 | } 86 | ver+=64; 87 | } 88 | 89 | //white pawns 90 | for(j=0;j<8;j++) 91 | { 92 | tile[1][j]->piece=1; 93 | tile[1][j]->pieceColor=0; 94 | tile[1][j]->display('P'); 95 | } 96 | 97 | //black pawns 98 | for(j=0;j<8;j++) 99 | { 100 | tile[6][j]->piece=1; 101 | tile[6][j]->pieceColor=1; 102 | tile[6][j]->display('P'); 103 | } 104 | 105 | //white and black remaining elements 106 | for(j=0;j<8;j++) 107 | { 108 | tile[0][j]->piece=1; 109 | tile[0][j]->pieceColor=0; 110 | tile[7][j]->piece=1; 111 | tile[7][j]->pieceColor=1; 112 | } 113 | 114 | { 115 | tile[0][0]->display('R'); 116 | tile[0][1]->display('H'); 117 | tile[0][2]->display('B'); 118 | tile[0][3]->display('Q'); 119 | tile[0][4]->display('K'); 120 | tile[0][5]->display('B'); 121 | tile[0][6]->display('H'); 122 | tile[0][7]->display('R'); 123 | } 124 | 125 | 126 | { 127 | tile[7][0]->display('R'); 128 | tile[7][1]->display('H'); 129 | tile[7][2]->display('B'); 130 | tile[7][3]->display('Q'); 131 | tile[7][4]->display('K'); 132 | tile[7][5]->display('B'); 133 | tile[7][6]->display('H'); 134 | tile[7][7]->display('R'); 135 | } 136 | 137 | wR=7; 138 | wC=4; 139 | 140 | bR=0; 141 | bC=4; 142 | 143 | } 144 | 145 | int main(int argc, char *argv[]) 146 | { 147 | QApplication a(argc, argv); 148 | 149 | QWidget *myWidget = new QWidget(); 150 | myWidget->setGeometry(0,0,1370,700); 151 | 152 | accessories(myWidget); 153 | chessBoard(myWidget,tile); 154 | 155 | myWidget->show(); 156 | return a.exec(); 157 | } 158 | 159 | -------------------------------------------------------------------------------- /mainwindow.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include "ui_mainwindow.h" 3 | 4 | MainWindow::MainWindow(QWidget *parent) : 5 | QMainWindow(parent), 6 | ui(new Ui::MainWindow) 7 | { 8 | ui->setupUi(this); 9 | } 10 | 11 | MainWindow::~MainWindow() 12 | { 13 | delete ui; 14 | } 15 | 16 | 17 | void MainWindow::on_pushButton_clicked() 18 | { 19 | 20 | } 21 | 22 | -------------------------------------------------------------------------------- /mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class MainWindow; 8 | } 9 | 10 | class MainWindow : public QMainWindow 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit MainWindow(QWidget *parent = 0); 16 | ~MainWindow(); 17 | 18 | private slots: 19 | void on_pushButton_clicked(); 20 | 21 | private: 22 | Ui::MainWindow *ui; 23 | }; 24 | 25 | #endif // MAINWINDOW_H 26 | -------------------------------------------------------------------------------- /mainwindow.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 808 10 | 526 11 | 12 | 13 | 14 | MainWindow 15 | 16 | 17 | 18 | 19 | 20 | 0 21 | 0 22 | 808 23 | 25 24 | 25 | 26 | 27 | 28 | 29 | TopToolBarArea 30 | 31 | 32 | false 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /screenshot/screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sanketsudake/CHESS-in-Qt/3e28a06450275d9727d078e30e783f98892fb417/screenshot/screenshot.png -------------------------------------------------------------------------------- /tile.cpp: -------------------------------------------------------------------------------- 1 | #include "tile.h" 2 | #include "validation.h" 3 | 4 | validation *valid = new validation(); 5 | 6 | extern int count,turn; 7 | extern QWidget *myWidget; 8 | extern Tile *click1; 9 | extern Tile *tile[8][8]; 10 | 11 | void validate(Tile *temp,int c); 12 | void disOrange(); 13 | 14 | void Tile::mousePressEvent(QMouseEvent *event) 15 | { 16 | validate(this,++count); 17 | } 18 | 19 | void Tile::display(char elem) 20 | { 21 | this->pieceName=elem; 22 | 23 | if(this->pieceColor && this->piece) 24 | { 25 | switch(elem) 26 | { 27 | case 'P': this->setPixmap(QPixmap(":/Images/pawn_white.svg")); 28 | break; 29 | case 'R': this->setPixmap(QPixmap(":/Images/rook_white.svg")); 30 | break; 31 | case 'H': this->setPixmap(QPixmap(":/Images/knight_white.svg")); 32 | break; 33 | case 'K': this->setPixmap(QPixmap(":/Images/king_white.svg")); 34 | break; 35 | case 'Q': this->setPixmap(QPixmap(":/Images/queen_white.svg")); 36 | break; 37 | case 'B': this->setPixmap(QPixmap(":/Images/bishop_white.svg")); 38 | break; 39 | } 40 | } 41 | 42 | else if(this->piece) 43 | { 44 | switch(elem) 45 | { 46 | case 'P': this->setPixmap(QPixmap(":/Images/pawn_black.svg")); 47 | break; 48 | case 'R': this->setPixmap(QPixmap(":/Images/rook_black.svg")); 49 | break; 50 | case 'H': this->setPixmap(QPixmap(":/Images/knight_black.svg")); 51 | break; 52 | case 'K': this->setPixmap(QPixmap(":/Images/king_black.svg")); 53 | break; 54 | case 'Q': this->setPixmap(QPixmap(":/Images/queen_black.svg")); 55 | break; 56 | case 'B': this->setPixmap(QPixmap(":/Images/bishop_black.svg")); 57 | break; 58 | } 59 | } 60 | else 61 | this->clear(); 62 | } 63 | 64 | void validate(Tile *temp, int c) 65 | { 66 | int retValue,i; 67 | 68 | if(c==1) 69 | { 70 | if(temp->piece && (temp->pieceColor==turn)) 71 | { 72 | //exp[max++]=temp->tileNum; 73 | retValue=valid->chooser(temp); 74 | 75 | if(retValue) 76 | { 77 | click1= new Tile(); 78 | temp->setStyleSheet("QLabel {background-color: green;}"); 79 | click1=temp; 80 | } 81 | else 82 | { 83 | //temp->setStyleSheet("QLabel {background-color: red;}"); 84 | count=0; 85 | } 86 | } 87 | else 88 | { 89 | //qDebug()<<"Rascel, clicking anywhere"; 90 | count=0; 91 | } 92 | } 93 | 94 | else 95 | { 96 | 97 | if(temp->tileNum==click1->tileNum) 98 | { 99 | click1->tileDisplay(); 100 | disOrange(); 101 | max=0; 102 | count=0; 103 | } 104 | 105 | for(i=0;itileNum==exp[i]) 108 | { 109 | click1->piece=0; 110 | temp->piece=1; 111 | 112 | temp->pieceColor=click1->pieceColor; 113 | temp->pieceName=click1->pieceName; 114 | 115 | click1->display(click1->pieceName); 116 | temp->display(click1->pieceName); 117 | 118 | click1->tileDisplay(); 119 | temp->tileDisplay(); 120 | 121 | retValue=valid->check(click1); 122 | /* 123 | if(retValue) 124 | { 125 | tile[wR][wC]->setStyleSheet("QLabel {background-color: red;}"); 126 | } 127 | */ 128 | 129 | disOrange(); 130 | 131 | max=0; 132 | 133 | turn=(turn+1)%2; 134 | count=0; 135 | } 136 | 137 | else 138 | count=1; 139 | } 140 | } 141 | } 142 | 143 | void Tile::tileDisplay() 144 | { 145 | 146 | if(this->tileColor) 147 | this->setStyleSheet("QLabel {background-color: rgb(120, 120, 90);}:hover{background-color: rgb(170,85,127);}"); 148 | else 149 | this->setStyleSheet("QLabel {background-color: rgb(211, 211, 158);}:hover{background-color: rgb(170,95,127);}"); 150 | } 151 | 152 | void disOrange() 153 | { 154 | int i; 155 | 156 | for(i=0;itileDisplay(); 158 | 159 | } 160 | -------------------------------------------------------------------------------- /tile.h: -------------------------------------------------------------------------------- 1 | #ifndef TILE_H 2 | #define TILE_H 3 | #include 4 | #include 5 | 6 | class Tile: public QLabel 7 | { 8 | public: 9 | 10 | //Fields 11 | int tileColor,piece,pieceColor,row,col,tileNum; 12 | char pieceName; 13 | 14 | //Constructors 15 | Tile(QWidget* pParent=0, Qt::WindowFlags f=0) : QLabel(pParent, f) {}; 16 | Tile(const QString& text, QWidget* pParent = 0, Qt::WindowFlags f = 0) : QLabel(text, pParent, f){}; 17 | 18 | //Methods 19 | void mousePressEvent(QMouseEvent *event); 20 | void display(char elem); 21 | void tileDisplay(); 22 | }; 23 | 24 | #endif // TILE_H 25 | -------------------------------------------------------------------------------- /ui_mainwindow.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************** 2 | ** Form generated from reading UI file 'mainwindow.ui' 3 | ** 4 | ** Created: Fri Mar 30 16:21:11 2012 5 | ** by: Qt User Interface Compiler version 4.8.0 6 | ** 7 | ** WARNING! All changes made in this file will be lost when recompiling UI file! 8 | ********************************************************************************/ 9 | 10 | #ifndef UI_MAINWINDOW_H 11 | #define UI_MAINWINDOW_H 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | QT_BEGIN_NAMESPACE 25 | 26 | class Ui_MainWindow 27 | { 28 | public: 29 | QWidget *centralWidget; 30 | QMenuBar *menuBar; 31 | QToolBar *mainToolBar; 32 | QStatusBar *statusBar; 33 | 34 | void setupUi(QMainWindow *MainWindow) 35 | { 36 | if (MainWindow->objectName().isEmpty()) 37 | MainWindow->setObjectName(QString::fromUtf8("MainWindow")); 38 | MainWindow->resize(808, 526); 39 | centralWidget = new QWidget(MainWindow); 40 | centralWidget->setObjectName(QString::fromUtf8("centralWidget")); 41 | MainWindow->setCentralWidget(centralWidget); 42 | menuBar = new QMenuBar(MainWindow); 43 | menuBar->setObjectName(QString::fromUtf8("menuBar")); 44 | menuBar->setGeometry(QRect(0, 0, 808, 25)); 45 | MainWindow->setMenuBar(menuBar); 46 | mainToolBar = new QToolBar(MainWindow); 47 | mainToolBar->setObjectName(QString::fromUtf8("mainToolBar")); 48 | MainWindow->addToolBar(Qt::TopToolBarArea, mainToolBar); 49 | statusBar = new QStatusBar(MainWindow); 50 | statusBar->setObjectName(QString::fromUtf8("statusBar")); 51 | MainWindow->setStatusBar(statusBar); 52 | 53 | retranslateUi(MainWindow); 54 | 55 | QMetaObject::connectSlotsByName(MainWindow); 56 | } // setupUi 57 | 58 | void retranslateUi(QMainWindow *MainWindow) 59 | { 60 | MainWindow->setWindowTitle(QApplication::translate("MainWindow", "MainWindow", 0)); 61 | } // retranslateUi 62 | 63 | }; 64 | 65 | namespace Ui { 66 | class MainWindow: public Ui_MainWindow {}; 67 | } // namespace Ui 68 | 69 | QT_END_NAMESPACE 70 | 71 | #endif // UI_MAINWINDOW_H 72 | -------------------------------------------------------------------------------- /validation.cpp: -------------------------------------------------------------------------------- 1 | #include "validation.h" 2 | 3 | validation::validation() 4 | { 5 | //Nothing here 6 | } 7 | 8 | int validation::chooser(Tile *temp) 9 | { 10 | switch(temp->pieceName) 11 | { 12 | case 'P': flag=validatePawn(temp); 13 | break; 14 | 15 | case 'R': flag=validateRook(temp); 16 | break; 17 | 18 | case 'H': flag=validateHorse(temp); 19 | break; 20 | 21 | case 'K': flag=validateKing(temp); 22 | break; 23 | 24 | case 'Q': flag=validateQueen(temp); 25 | break; 26 | 27 | case 'B': flag=validateBishop(temp); 28 | break; 29 | 30 | } 31 | 32 | orange(); 33 | 34 | return flag; 35 | } 36 | 37 | //PAWN 38 | int validation::validatePawn(Tile *temp) 39 | { 40 | int row,col; 41 | 42 | row=temp->row; 43 | col=temp->col; 44 | retVal=0; 45 | 46 | //White Pawn 47 | if(temp->pieceColor) 48 | { 49 | if(row-1>=0 && !tile[row-1][col]->piece) 50 | { 51 | exp[max++]=tile[row-1][col]->tileNum; 52 | retVal=1; 53 | } 54 | 55 | if(row==6 && !tile[5][col]->piece && !tile[4][col]->piece) 56 | { 57 | exp[max++]=tile[row-2][col]->tileNum; 58 | retVal=1; 59 | } 60 | 61 | if(row-1>=0 && col-1>=0) 62 | { 63 | if(tile[row-1][col-1]->pieceColor!=temp->pieceColor && tile[row-1][col-1]->piece) 64 | { 65 | exp[max++]=tile[row-1][col-1]->tileNum; 66 | retVal=1; 67 | } 68 | } 69 | 70 | if(row-1>=0 && col+1<=7) 71 | { 72 | if(tile[row-1][col+1]->pieceColor!=temp->pieceColor && tile[row-1][col+1]->piece) 73 | { 74 | exp[max++]=tile[row-1][col+1]->tileNum; 75 | retVal=1; 76 | } 77 | } 78 | } 79 | else 80 | { 81 | if(row+1<=7 && !tile[row+1][col]->piece) 82 | { 83 | exp[max++]=tile[row+1][col]->tileNum; 84 | retVal=1; 85 | } 86 | 87 | if(row==1 && !tile[2][col]->piece && !tile[3][col]->piece) 88 | { 89 | exp[max++]=tile[row+2][col]->tileNum; 90 | retVal=1; 91 | } 92 | 93 | if(row+1<=7 && col-1>=0) 94 | { 95 | if(tile[row+1][col-1]->pieceColor!=temp->pieceColor && tile[row+1][col-1]->piece) 96 | { 97 | exp[max++]=tile[row+1][col-1]->tileNum; 98 | retVal=1; 99 | } 100 | } 101 | 102 | if(row+1<=7 && col+1<=7) 103 | { 104 | if(tile[row+1][col+1]->pieceColor!=temp->pieceColor && tile[row+1][col+1]->piece) 105 | { 106 | exp[max++]=tile[row+1][col+1]->tileNum; 107 | retVal=1; 108 | } 109 | } 110 | } 111 | 112 | return retVal; 113 | } 114 | 115 | 116 | //ROOK 117 | int validation::validateRook(Tile *temp) 118 | { 119 | int r,c; 120 | 121 | retVal=0; 122 | 123 | r=temp->row; 124 | c=temp->col; 125 | while(r-->0) 126 | { 127 | if(!tile[r][c]->piece) 128 | { 129 | exp[max++]=tile[r][c]->tileNum; 130 | retVal=1; 131 | } 132 | 133 | else if(tile[r][c]->pieceColor==temp->pieceColor) 134 | break; 135 | 136 | else if(tile[r][c]->pieceColor!=temp->pieceColor) 137 | { 138 | exp[max++]=tile[r][c]->tileNum; 139 | retVal=1; 140 | break; 141 | } 142 | } 143 | 144 | r=temp->row; 145 | c=temp->col; 146 | while(r++<7) 147 | { 148 | if(!tile[r][c]->piece) 149 | { 150 | exp[max++]=tile[r][c]->tileNum; 151 | retVal=1; 152 | } 153 | 154 | else if(tile[r][c]->pieceColor==temp->pieceColor) 155 | break; 156 | 157 | else if(tile[r][c]->pieceColor!=temp->pieceColor) 158 | { 159 | exp[max++]=tile[r][c]->tileNum; 160 | retVal=1; 161 | break; 162 | } 163 | } 164 | 165 | r=temp->row; 166 | c=temp->col; 167 | while(c++<7) 168 | { 169 | if(!tile[r][c]->piece) 170 | { 171 | exp[max++]=tile[r][c]->tileNum; 172 | retVal=1; 173 | } 174 | 175 | else if(tile[r][c]->pieceColor==temp->pieceColor) 176 | break; 177 | 178 | else if(tile[r][c]->pieceColor!=temp->pieceColor) 179 | { 180 | exp[max++]=tile[r][c]->tileNum; 181 | retVal=1; 182 | break; 183 | } 184 | } 185 | 186 | r=temp->row; 187 | c=temp->col; 188 | while(c-->0) 189 | { 190 | if(!tile[r][c]->piece) 191 | { 192 | exp[max++]=tile[r][c]->tileNum; 193 | retVal=1; 194 | } 195 | 196 | else if(tile[r][c]->pieceColor==temp->pieceColor) 197 | break; 198 | 199 | else if(tile[r][c]->pieceColor!=temp->pieceColor) 200 | { 201 | exp[max++]=tile[r][c]->tileNum; 202 | retVal=1; 203 | break; 204 | } 205 | } 206 | 207 | 208 | return retVal; 209 | } 210 | 211 | 212 | //HORSE 213 | int validation::validateHorse(Tile *temp) 214 | { 215 | int r,c; 216 | retVal=0; 217 | 218 | r=temp->row; 219 | c=temp->col; 220 | 221 | if(r-2>=0 && c-1>=0) 222 | { 223 | if(tile[r-2][c-1]->pieceColor!=temp->pieceColor || !tile[r-2][c-1]->piece) 224 | { 225 | exp[max++]=tile[r-2][c-1]->tileNum; 226 | retVal=1; 227 | } 228 | } 229 | 230 | if(r-2>=0 && c+1<=7) 231 | { 232 | if(tile[r-2][c+1]->pieceColor!=temp->pieceColor || !tile[r-2][c+1]->piece) 233 | { 234 | exp[max++]=tile[r-2][c+1]->tileNum; 235 | retVal=1; 236 | } 237 | } 238 | 239 | if(r-1>=0 && c-2>=0) 240 | { 241 | if(tile[r-1][c-2]->pieceColor!=temp->pieceColor || !tile[r-1][c-2]->piece) 242 | { 243 | exp[max++]=tile[r-1][c-2]->tileNum; 244 | retVal=1; 245 | } 246 | } 247 | 248 | if(r-1>=0 && c+2<=7) 249 | { 250 | if(tile[r-1][c+2]->pieceColor!=temp->pieceColor || !tile[r-1][c+2]->piece) 251 | { 252 | exp[max++]=tile[r-1][c+2]->tileNum; 253 | retVal=1; 254 | } 255 | } 256 | 257 | if(r+2<=7 && c+1<=7) 258 | { 259 | if(tile[r+2][c+1]->pieceColor!=temp->pieceColor || !tile[r+2][c+1]->piece) 260 | { 261 | exp[max++]=tile[r+2][c+1]->tileNum; 262 | retVal=1; 263 | } 264 | } 265 | 266 | if(r+2<=7 && c-1>=0) 267 | { 268 | if(tile[r+2][c-1]->pieceColor!=temp->pieceColor || !tile[r+2][c-1]->piece) 269 | { 270 | exp[max++]=tile[r+2][c-1]->tileNum; 271 | retVal=1; 272 | } 273 | } 274 | 275 | if(r+1<=7 && c-2>=0) 276 | { 277 | if(tile[r+1][c-2]->pieceColor!=temp->pieceColor || !tile[r+1][c-2]->piece) 278 | { 279 | exp[max++]=tile[r+1][c-2]->tileNum; 280 | retVal=1; 281 | } 282 | } 283 | 284 | if(r+1<=7 && c+2<=7) 285 | { 286 | if(tile[r+1][c+2]->pieceColor!=temp->pieceColor || !tile[r+1][c+2]->piece) 287 | { 288 | exp[max++]=tile[r+1][c+2]->tileNum; 289 | retVal=1; 290 | } 291 | } 292 | 293 | return retVal; 294 | } 295 | 296 | 297 | //KING 298 | int validation::validateKing(Tile *temp) 299 | { 300 | int r,c; 301 | retVal=0; 302 | 303 | r=temp->row; 304 | c=temp->col; 305 | 306 | if(r-1>=0) 307 | { 308 | if(!tile[r-1][c]->piece || tile[r-1][c]->pieceColor!=temp->pieceColor) 309 | { 310 | exp[max++]=tile[r-1][c]->tileNum; 311 | retVal=1; 312 | } 313 | } 314 | 315 | if(r+1<=7) 316 | { 317 | if(!tile[r+1][c]->piece || tile[r+1][c]->pieceColor!=temp->pieceColor) 318 | { 319 | exp[max++]=tile[r+1][c]->tileNum; 320 | retVal=1; 321 | } 322 | } 323 | 324 | if(c-1>=0) 325 | { 326 | if(!tile[r][c-1]->piece || tile[r][c-1]->pieceColor!=temp->pieceColor) 327 | { 328 | exp[max++]=tile[r][c-1]->tileNum; 329 | retVal=1; 330 | } 331 | } 332 | 333 | if(c+1<=7) 334 | { 335 | if(!tile[r][c+1]->piece || tile[r][c+1]->pieceColor!=temp->pieceColor) 336 | { 337 | exp[max++]=tile[r][c+1]->tileNum; 338 | retVal=1; 339 | } 340 | } 341 | 342 | if(r-1>=0 && c-1>=0) 343 | { 344 | if(!tile[r-1][c-1]->piece || tile[r-1][c-1]->pieceColor!=temp->pieceColor) 345 | { 346 | exp[max++]=tile[r-1][c-1]->tileNum; 347 | retVal=1; 348 | } 349 | } 350 | 351 | if(r-1>=0 && c+1<=7) 352 | { 353 | if(!tile[r-1][c+1]->piece || tile[r-1][c+1]->pieceColor!=temp->pieceColor) 354 | { 355 | exp[max++]=tile[r-1][c+1]->tileNum; 356 | retVal=1; 357 | } 358 | } 359 | 360 | if(r+1<=7 && c-1>=0) 361 | { 362 | if(!tile[r+1][c-1]->piece || tile[r+1][c-1]->pieceColor!=temp->pieceColor) 363 | { 364 | exp[max++]=tile[r+1][c-1]->tileNum; 365 | retVal=1; 366 | } 367 | } 368 | 369 | if(r+1<=7 && c+1<=7) 370 | { 371 | if(!tile[r+1][c+1]->piece || tile[r+1][c+1]->pieceColor!=temp->pieceColor) 372 | { 373 | exp[max++]=tile[r+1][c+1]->tileNum; 374 | retVal=1; 375 | } 376 | } 377 | 378 | return retVal; 379 | } 380 | 381 | 382 | //QUEEN 383 | int validation::validateQueen(Tile *temp) 384 | { 385 | int r,c; 386 | 387 | retVal=0; 388 | 389 | r=temp->row; 390 | c=temp->col; 391 | while(r-->0) 392 | { 393 | if(!tile[r][c]->piece) 394 | { 395 | exp[max++]=tile[r][c]->tileNum; 396 | retVal=1; 397 | } 398 | 399 | else if(tile[r][c]->pieceColor==temp->pieceColor) 400 | break; 401 | 402 | else if(tile[r][c]->pieceColor!=temp->pieceColor) 403 | { 404 | exp[max++]=tile[r][c]->tileNum; 405 | retVal=1; 406 | break; 407 | } 408 | } 409 | 410 | r=temp->row; 411 | c=temp->col; 412 | while(r++<7) 413 | { 414 | if(!tile[r][c]->piece) 415 | { 416 | exp[max++]=tile[r][c]->tileNum; 417 | retVal=1; 418 | } 419 | 420 | else if(tile[r][c]->pieceColor==temp->pieceColor) 421 | break; 422 | 423 | else if(tile[r][c]->pieceColor!=temp->pieceColor) 424 | { 425 | exp[max++]=tile[r][c]->tileNum; 426 | retVal=1; 427 | break; 428 | } 429 | } 430 | 431 | r=temp->row; 432 | c=temp->col; 433 | while(c++<7) 434 | { 435 | if(!tile[r][c]->piece) 436 | { 437 | exp[max++]=tile[r][c]->tileNum; 438 | retVal=1; 439 | } 440 | 441 | else if(tile[r][c]->pieceColor==temp->pieceColor) 442 | break; 443 | 444 | else if(tile[r][c]->pieceColor!=temp->pieceColor) 445 | { 446 | exp[max++]=tile[r][c]->tileNum; 447 | retVal=1; 448 | break; 449 | } 450 | } 451 | 452 | r=temp->row; 453 | c=temp->col; 454 | while(c-->0) 455 | { 456 | if(!tile[r][c]->piece) 457 | { 458 | exp[max++]=tile[r][c]->tileNum; 459 | retVal=1; 460 | } 461 | 462 | else if(tile[r][c]->pieceColor==temp->pieceColor) 463 | break; 464 | 465 | else if(tile[r][c]->pieceColor!=temp->pieceColor) 466 | { 467 | exp[max++]=tile[r][c]->tileNum; 468 | retVal=1; 469 | break; 470 | } 471 | } 472 | 473 | r=temp->row; 474 | c=temp->col; 475 | while(r-->0 && c++<7) 476 | { 477 | if(!tile[r][c]->piece) 478 | { 479 | exp[max++]=tile[r][c]->tileNum; 480 | retVal=1; 481 | } 482 | 483 | else if(tile[r][c]->pieceColor==temp->pieceColor) 484 | break; 485 | 486 | else if(tile[r][c]->pieceColor!=temp->pieceColor) 487 | { 488 | exp[max++]=tile[r][c]->tileNum; 489 | retVal=1; 490 | break; 491 | } 492 | } 493 | 494 | r=temp->row; 495 | c=temp->col; 496 | while(r-->0 && c-->0) 497 | { 498 | if(!tile[r][c]->piece) 499 | { 500 | exp[max++]=tile[r][c]->tileNum; 501 | retVal=1; 502 | } 503 | 504 | else if(tile[r][c]->pieceColor==temp->pieceColor) 505 | break; 506 | 507 | else if(tile[r][c]->pieceColor!=temp->pieceColor) 508 | { 509 | exp[max++]=tile[r][c]->tileNum; 510 | retVal=1; 511 | break; 512 | } 513 | } 514 | 515 | r=temp->row; 516 | c=temp->col; 517 | while(r++<7 && c++<7) 518 | { 519 | if(!tile[r][c]->piece) 520 | { 521 | exp[max++]=tile[r][c]->tileNum; 522 | retVal=1; 523 | } 524 | 525 | else if(tile[r][c]->pieceColor==temp->pieceColor) 526 | break; 527 | 528 | else if(tile[r][c]->pieceColor!=temp->pieceColor) 529 | { 530 | exp[max++]=tile[r][c]->tileNum; 531 | retVal=1; 532 | break; 533 | } 534 | } 535 | 536 | r=temp->row; 537 | c=temp->col; 538 | while(r++<7 && c-->0) 539 | { 540 | if(!tile[r][c]->piece) 541 | { 542 | exp[max++]=tile[r][c]->tileNum; 543 | retVal=1; 544 | } 545 | 546 | else if(tile[r][c]->pieceColor==temp->pieceColor) 547 | break; 548 | 549 | else if(tile[r][c]->pieceColor!=temp->pieceColor) 550 | { 551 | exp[max++]=tile[r][c]->tileNum; 552 | retVal=1; 553 | break; 554 | } 555 | } 556 | 557 | 558 | return retVal; 559 | } 560 | 561 | //BISHOP 562 | int validation::validateBishop(Tile *temp) 563 | { 564 | int r,c; 565 | retVal=0; 566 | 567 | r=temp->row; 568 | c=temp->col; 569 | while(r-->0 && c++<7) 570 | { 571 | if(!tile[r][c]->piece) 572 | { 573 | exp[max++]=tile[r][c]->tileNum; 574 | retVal=1; 575 | } 576 | 577 | else if(tile[r][c]->pieceColor==temp->pieceColor) 578 | break; 579 | 580 | else if(tile[r][c]->pieceColor!=temp->pieceColor) 581 | { 582 | exp[max++]=tile[r][c]->tileNum; 583 | retVal=1; 584 | break; 585 | } 586 | } 587 | 588 | r=temp->row; 589 | c=temp->col; 590 | while(r-->0 && c-->0) 591 | { 592 | if(!tile[r][c]->piece) 593 | { 594 | exp[max++]=tile[r][c]->tileNum; 595 | retVal=1; 596 | } 597 | 598 | else if(tile[r][c]->pieceColor==temp->pieceColor) 599 | break; 600 | 601 | else if(tile[r][c]->pieceColor!=temp->pieceColor) 602 | { 603 | exp[max++]=tile[r][c]->tileNum; 604 | retVal=1; 605 | break; 606 | } 607 | } 608 | 609 | r=temp->row; 610 | c=temp->col; 611 | while(r++<7 && c++<7) 612 | { 613 | if(!tile[r][c]->piece) 614 | { 615 | exp[max++]=tile[r][c]->tileNum; 616 | retVal=1; 617 | } 618 | 619 | else if(tile[r][c]->pieceColor==temp->pieceColor) 620 | break; 621 | 622 | else if(tile[r][c]->pieceColor!=temp->pieceColor) 623 | { 624 | exp[max++]=tile[r][c]->tileNum; 625 | retVal=1; 626 | break; 627 | } 628 | } 629 | 630 | r=temp->row; 631 | c=temp->col; 632 | while(r++<7 && c-->0) 633 | { 634 | if(!tile[r][c]->piece) 635 | { 636 | exp[max++]=tile[r][c]->tileNum; 637 | retVal=1; 638 | } 639 | 640 | else if(tile[r][c]->pieceColor==temp->pieceColor) 641 | break; 642 | 643 | else if(tile[r][c]->pieceColor!=temp->pieceColor) 644 | { 645 | exp[max++]=tile[r][c]->tileNum; 646 | retVal=1; 647 | break; 648 | } 649 | } 650 | 651 | return retVal; 652 | } 653 | 654 | int validation::check(Tile *temp) 655 | { 656 | int r,c,flag; 657 | retVal=0; 658 | 659 | return retVal; 660 | } 661 | 662 | void validation::orange() 663 | { 664 | int i,n; 665 | 666 | for(i=0;isetStyleSheet("QLabel {background-color: orange;}"); 668 | } 669 | -------------------------------------------------------------------------------- /validation.h: -------------------------------------------------------------------------------- 1 | #ifndef VALIDATION_H 2 | #define VALIDATION_H 3 | #include "tile.h" 4 | 5 | extern Tile *tile[8][8]; 6 | extern int exp[60],max,wR,wC; 7 | 8 | class validation 9 | { 10 | int flag,retVal; 11 | 12 | public: 13 | validation(); 14 | int chooser(Tile *temp); 15 | int validateBishop(Tile *temp); 16 | int validateQueen(Tile *temp); 17 | int validateKing(Tile *temp); 18 | int validateHorse(Tile *temp); 19 | int validateRook(Tile *temp); 20 | int validatePawn(Tile *temp); 21 | void orange(); 22 | int check(Tile *temp); 23 | }; 24 | 25 | #endif // VALIDATION_H 26 | --------------------------------------------------------------------------------