-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbishop.cpp
More file actions
64 lines (52 loc) · 1.93 KB
/
bishop.cpp
File metadata and controls
64 lines (52 loc) · 1.93 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
#include "bishop.h"
char Bishop::print() const {
if (this->colour == white) {
return 'B';
} else if (this->colour == black) {
return 'b';
} else {
return '?';
}
}
Name Bishop::get_name() const {
return bishop;
}
bool Bishop::check_move(Cube chessboard[5][5][5], int const dst_rank, int const dst_file, int const dst_level) const {
if (chessboard[dst_rank][dst_file][dst_level].get_piece() && colour == chessboard[dst_rank][dst_file][dst_level].get_piece()->get_colour()) {
return false;
}
if (dst_rank == rank && dst_file == file && dst_level == level) {
return false;
}
if (abs(dst_rank - rank) == abs(dst_file - file) && dst_level == level) {
for (int i = 1; i < abs(dst_rank - rank); i++) {
int rank_dir = (dst_rank - rank < 0) ? -1 : 1;
int file_dir = (dst_file - file < 0) ? -1 : 1;
if (chessboard[rank + rank_dir * i][file + file_dir * i][level].get_piece()) {
return false;
}
}
return true;
}
if (abs(dst_rank - rank) == abs(dst_level - level) && dst_file == file) {
for (int i = 1; i < abs(dst_rank - rank); i++) {
int rank_dir = (dst_rank - rank < 0) ? -1 : 1;
int level_dir = (dst_level - level < 0) ? -1 : 1;
if (chessboard[rank + rank_dir * i][file][level + level_dir * i].get_piece()) {
return false;
}
}
return true;
}
if (abs(dst_file - file) == abs(dst_level - level) && dst_rank == rank) {
for (int i = 1; i < abs(dst_file - file); i++) {
int file_dir = (dst_file - file < 0) ? -1 : 1;
int level_dir = (dst_level - level < 0) ? -1 : 1;
if (chessboard[rank][file + file_dir * i][level + level_dir * i].get_piece()) {
return false;
}
}
return true;
}
return false;
}