forked from jake-edmonstone/Chess
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathabstractpiece.cc
More file actions
159 lines (124 loc) · 5.6 KB
/
abstractpiece.cc
File metadata and controls
159 lines (124 loc) · 5.6 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#include "abstractpiece.h"
#include <memory>
using namespace std;
template<typename T> bool in(const vector<T>& vec, const T& element) {
return find(vec.begin(), vec.end(), element) != vec.end();
}
AbstractPiece::AbstractPiece(string colour, string position): colour{colour}, position{position} {}
AbstractPiece::~AbstractPiece() {}
string AbstractPiece::getColour() const { return colour; }
string AbstractPiece::getPosition() const { return position; };
const vector<string> &AbstractPiece::getAvailableMoves() const { return availableMoves; }
void AbstractPiece::addAvailableMove(string move) { availableMoves.emplace_back(move); }
void AbstractPiece::addTarget(string target) { targets.emplace_back(target); }
void AbstractPiece::addThreat(string threat) { threats.emplace_back(threat); }
const std::vector<std::string> &AbstractPiece::getTargets() const { return targets; }
const std::vector<std::string> &AbstractPiece::getThreats() const { return threats; }
bool threatens(const AbstractPiece* threat, const AbstractPiece* victim) {
if (threat != nullptr && victim != nullptr) {
if (in(threat->getTargets(), victim->getName())) { return true; }
}
return false;
}
std::vector<Vec> King::getPotentialMoves() const {
return {{1,0}, {1,1}, {0,1}, {-1, 1}, {-1,0}, {-1,-1}, {0,-1}, {1,-1}};
}
std::vector<Vec> Queen::getPotentialMoves() const {
return {{ 1, 0}, { 2, 0}, { 3, 0}, { 4, 0}, { 5, 0}, { 6, 0}, { 7, 0},
{-1, 0}, {-2, 0}, {-3, 0}, {-4, 0}, {-5, 0}, {-6, 0}, {-7, 0},
{ 0, 1}, { 0, 2}, { 0, 3}, { 0, 4}, { 0, 5}, { 0, 6}, { 0, 7},
{ 0,-1}, { 0,-2}, { 0,-3}, { 0,-4}, { 0,-5}, { 0,-6}, { 0,-7},
{ 1, 1}, { 2, 2}, { 3, 3}, { 4, 4}, { 5, 5}, { 6, 6}, { 7, 7},
{-1,-1}, {-2,-2}, {-3,-3}, {-4,-4}, {-5,-5}, {-6,-6}, {-7,-7},
{ 1,-1}, { 2,-2}, { 3,-3}, { 4,-4}, { 5,-5}, { 6,-6}, { 7,-7},
{-1, 1}, {-2, 2}, {-3, 3}, {-4, 4}, {-5, 5}, {-6, 6}, {-7, 7}};
}
std::vector<Vec> Rook::getPotentialMoves() const {
return {{ 1, 0}, { 2, 0}, { 3, 0}, { 4, 0}, { 5, 0}, { 6, 0}, { 7, 0},
{-1, 0}, {-2, 0}, {-3, 0}, {-4, 0}, {-5, 0}, {-6, 0}, {-7, 0},
{ 0, 1}, { 0, 2}, { 0, 3}, { 0, 4}, { 0, 5}, { 0, 6}, { 0, 7},
{ 0,-1}, { 0,-2}, { 0,-3}, { 0,-4}, { 0,-5}, { 0,-6}, { 0,-7}};
}
std::vector<Vec> Knight::getPotentialMoves() const {
return {{2,1}, {2,-1}, {1,2}, {-1,2}, {-2,1}, {-2,-1}, {1,-2}, {-1,-2}};
}
std::vector<Vec> Bishop::getPotentialMoves() const {
return {{ 1, 1}, { 2, 2}, { 3, 3}, { 4, 4}, { 5, 5}, { 6, 6}, { 7, 7},
{-1,-1}, {-2,-2}, {-3,-3}, {-4,-4}, {-5,-5}, {-6,-6}, {-7,-7},
{ 1,-1}, { 2,-2}, { 3,-3}, { 4,-4}, { 5,-5}, { 6,-6}, { 7,-7},
{-1, 1}, {-2, 2}, {-3, 3}, {-4, 4}, {-5, 5}, {-6, 6}, {-7, 7}};
}
std::vector<Vec> WhitePawn::getPotentialMoves() const {
return {{0,1}, {0,2}, {1,1}, {-1,1}};
}
std::vector<Vec> BlackPawn::getPotentialMoves() const {
return {{0,-1}, {0,-2}, {1,-1}, {-1,-1}};
}
string King::getName() const {
return "king";
}
string Queen::getName() const {
return "queen";
}
string Rook::getName() const {
return "rook";
}
string Knight::getName() const {
return "knight";
}
string Bishop::getName() const {
return "bishop";
}
string WhitePawn::getName() const {
return "whitepawn";
}
string BlackPawn::getName() const {
return "blackpawn";
}
King::King(string colour, string position): AbstractPiece{colour, position} {}
Queen::Queen(string colour, string position): AbstractPiece{colour, position} {}
Rook::Rook(string colour, string position): AbstractPiece{colour, position} {}
Knight::Knight(string colour, string position): AbstractPiece{colour, position} {}
Bishop::Bishop(string colour, string position): AbstractPiece{colour, position} {}
BlackPawn::BlackPawn(string colour, string position): AbstractPiece{colour, position} {}
WhitePawn::WhitePawn(string colour, string position): AbstractPiece{colour, position} {}
unique_ptr<AbstractPiece> King::clone() const {
return std::make_unique<King>(*this);
}
unique_ptr<AbstractPiece> Queen::clone() const {
return std::make_unique<Queen>(*this);
}
unique_ptr<AbstractPiece> Rook::clone() const {
return std::make_unique<Rook>(*this);
}
unique_ptr<AbstractPiece> Knight::clone() const {
return std::make_unique<Knight>(*this);
}
unique_ptr<AbstractPiece> Bishop::clone() const {
return std::make_unique<Bishop>(*this);
}
unique_ptr<AbstractPiece> BlackPawn::clone() const {
return std::make_unique<BlackPawn>(*this);
}
unique_ptr<AbstractPiece> WhitePawn::clone() const {
return std::make_unique<WhitePawn>(*this);
}
int King::getRank() const { return KING_VALUE; }
int Queen::getRank() const { return QUEEN_VALUE; }
int Rook::getRank() const { return ROOK_VALUE; }
int Knight::getRank() const { return KNIGHT_VALUE; }
int Bishop::getRank() const { return BISHOP_VALUE; }
int WhitePawn::getRank() const { return PAWN_VALUE; }
int BlackPawn::getRank() const { return PAWN_VALUE; }
bool AbstractPiece::isCastleable() const { return false; }
void AbstractPiece::setCastleable(bool value) { ; }
bool King::isCastleable() const { return Castleable; }
void King::setCastleable(bool value) { Castleable = value; }
bool Rook::isCastleable() const { return Castleable; }
void Rook::setCastleable(bool value) { Castleable = value; }
bool AbstractPiece::isEnPassantable() const { return false; }
void AbstractPiece::setEnPassantable(bool value) { ; }
bool WhitePawn::isEnPassantable() const { return enPassantable; }
void WhitePawn::setEnPassantable(bool value) { enPassantable = value; }
bool BlackPawn::isEnPassantable() const { return enPassantable; }
void BlackPawn::setEnPassantable(bool value) { enPassantable = value; }