Repository navigation
Expand file tree
/
Copy path7.4.cpp
More file actions
78 lines (69 loc) · 1.28 KB
/
Copy path7.4.cpp
File metadata and controls
78 lines (69 loc) · 1.28 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
/*
* Design a chess game using object oriented principles
*/
#include <cstdlib>
#include <list>
using namespace std;
enum color{black,white};
class piece {
private:
int x,y;
color piece_color;
public:
int get_x() {return x;}
int get_y() {return y;}
color get_color(){return piece_color;}
void set_x(int nx) {x=nx;}
void set_y(int ny) {y=ny;}
void move(int new_x,int new_y) {
set_y(new_y);
set_x(new_x);
}
virtual bool is_valid_move(int,int)=0;
};
class king:public piece {
bool is_valid_moove(int new_x,int new_y) {
if(abs(new_x-get_x())>1 || abs(new_y-get_y())>1) return false;
return true;
}
};
class position {
private:
list<piece*> white,black;
public:
bool check_mate();
};
class player {
private:
enum color player_color;
public:
color get_color() {return player_color;}
position move(position p);
};
class game {
private:
position current_pos;
enum color current_player;
player bp,wp;
public:
game();
void set_pieces();
void new_game() {
set_pieces();
current_player=white;
}
void begin_game() {
while(!current_pos.check_mate()) {
if(current_player==white){
current_pos=wp.move(current_pos);
current_player=black;
}
else {
current_pos=bp.move(current_pos);
current_player=white;
}
}
}
};
int main() {
}