-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.cpp
211 lines (185 loc) · 4.36 KB
/
Main.cpp
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
#include <iostream>
#include <string.h>
using namespace std;
class Piece {
public:
};
enum piece {
WPawn, WKnight, WBishop, WRook, WQueen, WKing,
empty,
BPawn, BKnight, BBishop, BRook, BQueen, BKing
};
int board[8][8];
void setEmpty() {
for (int i = 0; i < 8; i++) {
for (int j = 2; j < 6; j++) {
board[j][i] = empty;
}
}
}
void setPawns() {
for (int i = 0; i < 8; i++) {
board[6][i] = WPawn;
board[1][i] = BPawn;
}
}
void setNonPawns() {
board[7][1] = WKnight; board[0][1] = BKnight;
board[7][6] = WKnight; board[0][6] = BKnight;
board[7][2] = WBishop; board[0][2] = BBishop;
board[7][5] = WBishop; board[0][5] = BBishop;
board[7][0] = WRook; board[0][0] = BRook;
board[7][7] = WRook; board[0][7] = BRook;
board[7][3] = WQueen; board[0][3] = BQueen;
board[7][4] = WKing; board[0][4] = BKing;
}
void printBoard() {
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 8; j++) {
switch (board[i][j]) {
case empty:
cout << " ";
break;
case WPawn:
cout << "P ";
break;
case BPawn:
cout << "p ";
break;
case WKnight:
cout << "K ";
break;
case BKnight:
cout << "k ";
break;
case WBishop:
cout << "B ";
break;
case BBishop:
cout << "b ";
break;
case WRook:
cout << "R ";
break;
case BRook:
cout << "r ";
break;
case WQueen:
cout << "Q ";
break;
case BQueen:
cout << "q ";
break;
case WKing:
cout << "* ";
break;
case BKing:
cout << "* ";
break;
}
}
cout << endl;
}
cout << endl;
}
void movePawn(int x, int y, int a, int b) {
if (board[x][y] == WPawn) { //WHITE
if (x == 6 && a == 4 && y == b && board[x-2][y] == empty && board[x-1][y] == empty) { //checking for double first pawn move
cout << "legal double move" << endl;
board[a][b] = board[x][y];
board[x][y] = empty;
}
else if (y == b && x-1 == a){ // checking for normal first pawn move
board[a][b] = board[x][y];
board[x][y] = empty;
}
else if ((b == y+1 || b == y-1) && board[a][b] > 6 && a == x-1) { //pawn capture
board[a][b] = board[x][y];
board[x][y] = empty;
}
}
else { //BLACK
if (x == 1 && a == 3 && y == b && board[x+2][y] == empty && board[x+1][y] == empty) { //checking for double first pawn move
cout << "legal double move" << endl;
board[a][b] = board[x][y];
board[x][y] = empty;
}
else if (y == b && x+1 == a){ // checking for normal first pawn move
board[a][b] = board[x][y];
board[x][y] = empty;
}
else if ((b == y+1 || b == y-1) && board[a][b] < 6 && a == x+1) { //pawn capture
board[a][b] = board[x][y];
board[x][y] = empty;
}
}
}
void moveKnight(int x, int y, int a, int b) {
}
void chooseMove() {
int x, y, a, b;
cin >> x;
cin >> y;
cin >> a;
cin >> b;
switch (board[x][y]) {
case empty:
cout << "Invalid Piece" << endl;
break;
case WPawn:
movePawn(x, y, a, b);
break;
case BPawn:
movePawn(x, y, a, b);
break;
case WKnight:
board[a][b] = board[x][y];
board[x][y] = empty;
break;
case BKnight:
board[a][b] = board[x][y];
board[x][y] = empty;
break;
case WBishop:
board[a][b] = board[x][y];
board[x][y] = empty;
break;
case BBishop:
board[a][b] = board[x][y];
board[x][y] = empty;
break;
case WRook:
board[a][b] = board[x][y];
board[x][y] = empty;
break;
case BRook:
board[a][b] = board[x][y];
board[x][y] = empty;
break;
case WQueen:
board[a][b] = board[x][y];
board[x][y] = empty;
break;
case BQueen:
board[a][b] = board[x][y];
board[x][y] = empty;
break;
case WKing:
board[a][b] = board[x][y];
board[x][y] = empty;
break;
case BKing:
board[a][b] = board[x][y];
board[x][y] = empty;
break;
}
}
int main() {
setPawns();
setNonPawns();
setEmpty();
while(true) {
printBoard();
chooseMove();
}
}