-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChessGameFinal.cpp
More file actions
400 lines (400 loc) · 12.6 KB
/
Copy pathChessGameFinal.cpp
File metadata and controls
400 lines (400 loc) · 12.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
//#include <iostream>
//#include <iomanip>
//#include<cstdlib>
//#include<ctime>
//#include <windows.h>
//#include <conio.h>
//using namespace std;
//
//char board[8][8] = {
// {'r', 'n', 'b', 'q', 'k', 'b', 'n', 'r'},
// {' ', '%', ' ', '%', ' ', '%', ' ', '%'},
// {'%', ' ', '%', ' ', '%', ' ', '%', ' '},
// {' ', '%', ' ', '%', ' ', '%', ' ', '%'},
// {'%', ' ', '%', ' ', '%', ' ', '%', ' '},
// {' ', '%', ' ', '%', ' ', '%', ' ', '%'},
// {'%', ' ', '%', ' ', '%', ' ', '%', ' '},
// {'R', 'N', 'B', 'Q', 'K', 'B', 'N', 'R'}
//};
//
//
//void isCheckmate1() {
//
// int enemyPieceCount = 0;
//
//
// for (int i = 0; i < 8; i++)
// {
// for (int j = 0; j < 8; j++)
// {
// char piece = board[i][j];
//
// if (piece == 'n' || piece == 'b' || piece == 'q' || piece == 'r')
// {
// enemyPieceCount++;
// }
//
//
// }
// }
//
//
// if (enemyPieceCount == 0)
// {
// cout << "PLAYER 1 WINS";
// exit(0);
// }
//
//}
//
//void isCheckmate2() {
//
// int enemyPieceCount = 0;
//
//
// for (int i = 0; i < 8; i++)
// {
// for (int j = 0; j < 8; j++)
// {
// char piece = board[i][j];
//
// if (piece == 'N' || piece == 'B' || piece == 'Q' || piece == 'R')
// {
// enemyPieceCount++;
// }
//
//
// }
// }
//
//
// if (enemyPieceCount == 0)
// {
// cout << "PLAYER 2 WINS";
// exit(0);
// }
//
//}
//
//
//void start();
//void chessboard();
//bool movement(int, int, int, int);
//bool validmove1(char board[][8], int initialrow, int initialcolumn, int nextrow, int nextcolumn, int s);
//
//
//bool isValidKnightMove(int srcRow, int srcCol, int destRow, int destCol) {
// int rowDiff = abs(destRow - srcRow);
// int colDiff = abs(destCol - srcCol);
//
// // Knight moves in an L-shape: 2 squares in one direction and 1 square in the perpendicular direction
// if ((rowDiff == 2 && colDiff == 1) || (rowDiff == 1 && colDiff == 2)) {
// return true;
// }
// cout << "Inavalid Knight Move";
// return false;
//}
//
//
//bool isValidKingMove(int srcRow, int srcCol, int destRow, int destCol) {
// int rowDiff = abs(destRow - srcRow);
// int colDiff = abs(destCol - srcCol);
//
// // Moving one square in any direction
// if ((rowDiff == 1 && colDiff == 0) || (rowDiff == 0 && colDiff == 1) || (rowDiff == 1 && colDiff == 1)) {
// return true;
// }
//
// cout << "Inavalid King Move";
// return false;
//}
//bool isValidRookMove(int srcRow, int srcCol, int destRow, int destCol) {
// // Moving horizontally
// if (srcRow == destRow && srcCol != destCol) {
// return true;
// }
//
// // Moving vertically
// if (srcRow != destRow && srcCol == destCol) {
// return true;
// }
//
// cout << "Inavalid Rook Move";
// return false;
//}
//
//bool isValidBishopMove(int srcRow, int srcCol, int destRow, int destCol) {
// int rowDiff = abs(destRow - srcRow);
// int colDiff = abs(destCol - srcCol);
//
// // Moving diagonally (equal row and column differences)
// if (rowDiff == colDiff) {
// return true;
// }
// cout << "Inavalid Bishoop Move";
// return false;
//}
//
//
//
//bool isValidQueenMove(int srcRow, int srcCol, int destRow, int destCol) {
// // Moving horizontally or vertically
// if (isValidRookMove(srcRow, srcCol, destRow, destCol)) {
// return true;
// }
//
// // Moving diagonally
// if (isValidBishopMove(srcRow, srcCol, destRow, destCol)) {
// return true;
// }
// cout << "Inavalid Queen Move";
// return false;
//}
//
//bool validmove2(char board[][8], int initialrow, int initialcolumn, int nextrow, int nextcolumn, int s)
//{
// if (board[nextrow][nextcolumn] == 'k' || board[nextrow][nextcolumn] == 'r' || board[nextrow][nextcolumn] == 'n' || board[nextrow][nextcolumn] == 'b')
// {
// cout << "Invalid Move , Hitting on your Piece"; return true;
// }
//
// else return false;
//}
//
//int main()
//{
//
//
// start();
//
// return 0;
//}
//void start() {
// system("Color B0");
// char choice;
// int quotes;
// srand(time(0));
// quotes = (rand() % 8) + 1;
// //////////////////////////////////////////////////////////////Starting Interface//////////////////////////////////////////////////////////////
// cout << "***********************************************************************************************************************";
// cout << setw(80) << " _____ _ _ _____ _____ _____\n";
// cout << setw(80) << " / ____| | | | | | ____| / ____| / ____|\n";
// cout << setw(81) << "| | | |__| | | |__ | (___ | (___ \n";
// cout << setw(80) << "| | | __ | | __| \\___ \\ \\___ \\ \n";
// cout << setw(80) << "| |____ | | | | | |___ ____)| ____)|\n";
// cout << setw(46) << " \\_____| " << " |_| |_| |_____| |_____/ |_____/ \n";
// cout << "***********************************************************************************************************************" << endl << endl << endl;
//
//
// cout << "Menu: " << endl << endl << endl;
// cout << "(N)ew game" << endl;
// cout << "(Q)uit" << endl;
// cout << "Enter your choice: ";
// cin >> choice;
// if (choice == 'N' || choice == 'n') {
// chessboard();
//
// }
// else if (choice == 'I' || choice == 'i') {
// Instructions();
// }
// else if (choice == 'Q' || choice == 'q') {
// switch (quotes) {
// case 1:
// cout << "Once the game is over, he says, the king and the pawn go back in the same box. In lifeand death we are equal. " << endl << " - Lisa Renee Jones" << endl << endl;
//
// cout << "******************************************************Game Ended!******************************************************" << endl << endl;
// break;
// case 2:
// cout << "When you see a good move, look for a better one. " << endl << " -Emanuel Lasker" << endl << endl;
//
// cout << "******************************************************Game Ended!******************************************************" << endl << endl;
// break;
// case 3:
// cout << "Every chess master was once a beginner. " << endl << " -Irving Chernev" << endl << endl;
//
// cout << "******************************************************Game Ended!******************************************************" << endl << endl;
// break;
// case 4:
// cout << "My problem with chess was that all my pieces wanted to end the game as soon as possible. " << endl << " -Dave Barry" << endl << endl;
//
// cout << "******************************************************Game Ended!******************************************************" << endl << endl;
// break;
// case 5:
// cout << "In life, as in chess, forethought wins. " << endl << " -Charles Buxton" << endl << endl;
//
// cout << "******************************************************Game Ended!******************************************************" << endl << endl;
// break;
// case 6:
// cout << "Critical thinking is the most important factor with chess. As it is in life, you need to think before you make decisions. " << endl << "-Hikaru Nakamura" << endl << endl;
//
// cout << "******************************************************Game Ended!******************************************************" << endl << endl;
// break;
// case 7:
// cout << "Some part of a mistake is always correct. " << endl << " -Savielly Tartakover" << endl << endl;
//
// cout << "******************************************************Game Ended!******************************************************" << endl << endl;
// break;
//
//
// }
// }
//
//}
//void chessboard() {
// const int s = 8;
// int initialrow, initialcolumn, nextrow, nextcolumn;
// bool b = 1;
//
//
// bool isPlayerTurn = true;
// // Display the board
//
// while (b)
// {
// system("cls");
// cout << endl << endl << endl;
// for (int i = 0; i < s + 1; i++) {
// for (int j = 0; j < s + 1; j++) {
// if (i == 0) {
// if (j == 8)
// cout << " ";
// else if (i == 0)
// cout << "\t" << j;
// }
// else if (j == 0) {
// cout << endl << i - 1 << "\t";
// }
// if (i > 0 && j > 0)
// cout << board[i - 1][j - 1] << "\t";
// }
// if (i == 0)
// cout << endl;
// else
// cout << endl << endl;
// }
//
// if (isPlayerTurn)
// {
// cout << "\nPlayer 1: \n";
// }
//
// else
// {
// cout << "\nPlayer 2: \n";
// }
//
//
//
// ////////Taking input for movemennt ///
// cout << "Enter the coordinates of the chess piece you want to move respectively(i.e 02): ";
// cin >> initialrow >> initialcolumn;
// cout << "Enter the coordinates of the chess piece you want to move respectively(i.e 04): ";
// cin >> nextrow >> nextcolumn;
//
//
// if (isPlayerTurn) {
//
// if (validmove1(board, initialrow, initialcolumn, nextrow, nextcolumn, s))
// continue;
//
// if (!(board[initialrow][initialcolumn] == 'N' || board[initialrow][initialcolumn] == 'K' || board[initialrow][initialcolumn] == 'B' || board[initialrow][initialcolumn] == 'Q' || board[initialrow][initialcolumn] == 'R'))
// {
// cout << "\nInvalid Move Player 1\n";
// // Sleep(2000);
// continue;
// }
//
//
// }
// else {
//
// if (validmove2(board, initialrow, initialcolumn, nextrow, nextcolumn, s))
// continue;
//
// if (!(board[initialrow][initialcolumn] == 'n' || board[initialrow][initialcolumn] == 'k' || board[initialrow][initialcolumn] == 'b' || board[initialrow][initialcolumn] == 'q' || board[initialrow][initialcolumn] == 'r'))
// {
// cout << "\nInvalid Move Player 2\n";
// //Sleep(2000);
// continue;
//
// }
//
// }
//
//
//
//
//
//
//
//
// if (!movement(initialrow, initialcolumn, nextrow, nextcolumn))
// continue;
//
// if ((board[initialrow][initialcolumn] == 'N' || board[initialrow][initialcolumn] == 'n') && !isValidKnightMove(initialrow, initialcolumn, nextrow, nextcolumn))
// continue;
//
// if ((board[initialrow][initialcolumn] == 'K' || board[initialrow][initialcolumn] == 'k') && !isValidKingMove(initialrow, initialcolumn, nextrow, nextcolumn))
// continue;
// if ((board[initialrow][initialcolumn] == 'R' || board[initialrow][initialcolumn] == 'r') && !isValidRookMove(initialrow, initialcolumn, nextrow, nextcolumn))
// continue;
// if ((board[initialrow][initialcolumn] == 'B' || board[initialrow][initialcolumn] == 'b') && !isValidBishopMove(initialrow, initialcolumn, nextrow, nextcolumn))
// continue;
// if ((board[initialrow][initialcolumn] == 'Q' || board[initialrow][initialcolumn] == 'q') && !isValidQueenMove(initialrow, initialcolumn, nextrow, nextcolumn))
// continue;
//
//
//
//
//
//
//
//
//
//
//
//
// board[nextrow][nextcolumn] = board[initialrow][initialcolumn];
// board[initialrow][initialcolumn] = ' ';
// isCheckmate2();
// isCheckmate1();
//
// isPlayerTurn = !isPlayerTurn;
// }
//
//
//
//
//
//
//
//
//
//}
//bool movement(int initialrow, int initialcolumn, int nextrow, int nextcolumn) {
//
// if ((initialrow >= 0 && initialrow <= 7 && initialcolumn >= 0 && initialcolumn <= 7 && nextrow >= 0 && nextrow <= 7 && nextcolumn >= 0 && nextcolumn <= 7))
// {
// return true;
// }
//
// else
// {
// cout << "Invalid Move, out of Board";
// return false;
// }
//}
//
//
//bool validmove1(char board[][8], int initialrow, int initialcolumn, int nextrow, int nextcolumn, int s)
//{
// if (board[nextrow][nextcolumn] == 'K' || board[nextrow][nextcolumn] == 'R' || board[nextrow][nextcolumn] == 'N' || board[nextrow][nextcolumn] == 'B')
// {
// cout << "Invalid Move , Hitting on your Piece"; return true;
// }
//
// else return false;
//}
//
//