-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
80 lines (68 loc) · 2.44 KB
/
Copy pathmain.cpp
File metadata and controls
80 lines (68 loc) · 2.44 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
#include "chess.hpp"
#include <utility>
#include <vector>
#include <array>
#include "Board.hpp"
std::pair<int, int> getPosition() {
int row, col;
std::cout << "Enter row and column: ";
std::cin >> row >> col;
return {row, col};
}
int main() {
Board b;
b.printBoard();
bool check = true;
bool turn = false;
std::cout << "Enter Your Start then End Coordinates for a move in format row col, type: 8 8 to end game" << std::endl;
std::cout << "Start: ";
std::pair<int, int> start = getPosition();
std::cout << "End: ";
std::pair<int , int> end = getPosition();
// turn false - White -- Turn true - Black
while(check){
if(start.first <= 8 && start.second <=8 && start.first >= 0 && start.second >= 0 && end.first >= 0 && end.second >=0 && end.first <=8 && end.second <=8){
if(!turn){
if(b.board[start.first][start.second]->getTeam() == White){
std::string temp = b.board[end.first][end.second]->nameW;
if(b.board[start.first][start.second]->move(start, end, b)){
if(temp == "♔"){
std::cout << "Game Over";
break;
}
turn = !turn;
}
}
else{
std::cout << "Not Your Turn" << std::endl;
}
}
else{
if(b.board[start.first][start.second]->getTeam() == Black){
std::string temp = b.board[end.first][end.second]->nameW;
if(b.board[start.first][start.second]->move(start, end, b)){
if(temp == "♔"){
std::cout << "Game Over";
break;
}
turn = !turn;
}
}
else{
std::cout << "Not Your Turn" << std::endl;
}
}
}
else{
std::cout << "Out of Bounds" << std::endl;
}
b.printBoard();
std::cout << "Start: ";
start = getPosition();
std::cout << "End: ";
end = getPosition();
if(start == std::pair<int, int>{8, 8} || end == std::pair<int, int>{8, 8}){
check = false;
}
}
} // g++ -Wall -Wextra -std=c++17 main.cpp Board.cpp chess.cpp -o chess