-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpawn.cpp
More file actions
64 lines (58 loc) · 2.29 KB
/
Copy pathpawn.cpp
File metadata and controls
64 lines (58 loc) · 2.29 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 "pawn.h"
char Pawn::print() const {
if (this->colour == white) {
return 'P';
} else if (this->colour == black) {
return 'p';
} else {
return '?';
}
}
Name Pawn::get_name() const {
return pawn;
}
bool Pawn::check_move(Cube chessboard[5][5][5], int const dst_rank, int const dst_file, int const dst_level) const {
// move to empty cube
if (!chessboard[dst_rank][dst_file][dst_level].get_piece()) {
if (colour == white) {
if (dst_rank - rank == 1 && dst_file - file == 0 && dst_level - level == 0) {
return true;
}
if (dst_level - level == 1 && dst_rank - rank == 0 && dst_file - file == 0) {
return true;
}
} else if (colour == black) {
if (rank - dst_rank == 1 && dst_file - file == 0 && dst_level - level == 0) {
return true;
}
if (level - dst_level == 1 && dst_rank - rank == 0 && dst_file - file == 0) {
return true;
}
}
}
// diagonal capture
if (chessboard[dst_rank][dst_file][dst_level].get_piece()) {
if (colour == white && chessboard[dst_rank][dst_file][dst_level].get_piece()->get_colour() == black) {
if (dst_rank - rank == 1 && (dst_file - file == 1 || file - dst_file == 1) && dst_level - level == 0) {
return true;
}
if (dst_level - level == 1 && (dst_file - file == 1 || file - dst_file == 1) && dst_rank - rank == 0) {
return true;
}
if (dst_level - level == 1 && dst_rank - rank == 1 && dst_file - file == 0) {
return true;
}
} else if (colour == black && chessboard[dst_rank][dst_file][dst_level].get_piece()->get_colour() == white) {
if (rank - dst_rank == 1 && (dst_file - file == 1 || file - dst_file == 1) && dst_level - level == 0) {
return true;
}
if (level - dst_level == 1 && (dst_file - file == 1 || file - dst_file == 1) && dst_rank - rank == 0) {
return true;
}
if (level - dst_level == 1 && rank - dst_rank == 1 && dst_file - file == 0) {
return true;
}
}
}
return false;
}