-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChessPiece.cpp
More file actions
109 lines (88 loc) · 2.63 KB
/
Copy pathChessPiece.cpp
File metadata and controls
109 lines (88 loc) · 2.63 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/****************************************************/
/* */
/* Date Created: 01/12/14 */
/* Description: Implementation of ChessPiece */
/* abstract class. */
/* */
/* Date Who Description of Change */
/* 20141201 HL Created. */
/****************************************************/
#include <string>
#include "ChessPiece.hpp"
ChessPiece::~ChessPiece(){
return;
}
std::string ChessPiece::getColour() const {
if (colour == WHITE) {
return "White";
}
return "Black";
}
bool ChessPiece::clearRoute(int source_index, int destination_index,
move_type direction,
ChessPiece *board[]) {
if (destination_index > source_index) {
for (int i = source_index + direction; i < destination_index; i+=direction) {
if (board[i] != NULL) {
return false;
}
}
}
else {
for (int i = source_index + direction; i > destination_index; i+=direction) {
if (board[i] != NULL) {
return false;
}
}
}
return true;
}
bool ChessPiece::hasMoved() {
return has_moved;
}
void ChessPiece::setMove() {
has_moved = true;
return;
}
bool ChessPiece::hasSpecialMoves() {
return has_special_moves;
}
int ChessPiece::getMoveMultiple(move_type direction) {
return MAX_MULTIPLE;
}
bool ChessPiece::hasCaptureMove(move_type moves[], int &number_of_moves) {
return false;
}
bool ChessPiece::validMove(int source_index, int destination_index,
ChessPiece *board[]) {
move_type capture_moves[MAX_MOVES];
int number_of_capture_moves;
int steps;
if(board[destination_index] != NULL &&
board[destination_index]->getColour() == this->getColour())
return false;
for (int i = 0; i < number_of_moves; i++) {
steps = getMoveMultiple(moves[i]);
if ((destination_index - source_index) % moves[i] == 0 &&
(destination_index - source_index) / moves[i] > 0 &&
(destination_index - source_index) / moves[i] <= steps) {
if(hasCaptureMove(capture_moves, number_of_capture_moves) &&
board[destination_index] != NULL) {
break;
}
if(clearRoute(source_index, destination_index, moves[i], board))
return true;
return false;
}
}
if(hasCaptureMove(capture_moves, number_of_capture_moves) &&
board[destination_index] != NULL &&
board[destination_index]->getColour() != this->getColour()) {
for (int i = 0; i < number_of_capture_moves; i++) {
if((destination_index - source_index) == capture_moves[i]) {
return true;
}
}
}
return false;
}