-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPiece.cpp
More file actions
80 lines (65 loc) · 1.59 KB
/
Piece.cpp
File metadata and controls
80 lines (65 loc) · 1.59 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"Piece.h"
string Piece::getShort() {
string s = "";
s += this->colour[0];
s += this->sym;
return s;
};
string Piece::getName() {
return name;
}
void Piece::updatePosition(int rank, int file ) {
this->rank = rank;
this->file = file;
}
int Piece::checkMove(Piece* board_ref[8][8], int d_rank, int d_file, bool verbose) {
int status;
if ((status = checkLogic(d_rank, d_file, verbose)) > 0) {
if (verbose) {
cout << this->colour << "'s " << this->name << " cannot move to " << charPos(d_rank, d_file) << "!" << endl;
}
return 1;
};
if ((status = checkContext(board_ref, d_rank, d_file, false)) > 0) {
if (verbose) {
cout << this->colour << "'s " << this->name << " cannot move to " << charPos(d_rank, d_file) << "!" << endl;
}
return 1;
};
return 0;
};
int Piece::checkDiagonal(int d_rank, int d_file, bool cap_one) {
if (abs(this->rank - d_rank) != abs(this->file - d_file)) {
return 1;
}
if (cap_one && (abs(this->rank - d_rank) != 1) ) {
return 1;
}
return 0;
};
int Piece::checkVertical(int d_rank, int d_file, bool cap_one) {
if (this->file != d_file) {
return 1;
}
if (cap_one && (abs(this->rank - d_rank) != 1) ) {
return 1;
}
return 0;
};
int Piece::checkHorizontal(int d_rank, int d_file, bool cap_one) {
if (this->rank != d_rank) {
return 1;
}
if (cap_one && (abs(this->file - d_file) != 1) ) {
return 1;
}
return 0;
};
string Piece::charPos(int rank, int file){
char o_rank = rank + 49;
char o_file = file + 65;
string str = "";
str += o_file;
str += o_rank;
return str;
};