-
Notifications
You must be signed in to change notification settings - Fork 0
/
Piece.cpp
50 lines (42 loc) · 1.01 KB
/
Piece.cpp
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
#include "Piece.h"
#include <iomanip>
std::ostream& operator<<(std::ostream& ostream, const PieceColor& color) {
switch (color) {
case BLUE:
ostream << "B";
break;
case RED:
ostream << "R";
break;
case GREY:
ostream << "G";
break;
}
return ostream;
}
Piece::Piece() :
color(GREY), value(0) {
// bleh default color, as long as value is 0 color is "invalid"
}
Piece::Piece(const PieceColor& color, unsigned short value) :
color(color), value(value) {
}
std::ostream& operator<<(std::ostream& ostream, const Piece& piece) {
if (piece.empty()) {
ostream << " ";
} else {
ostream << piece.color << std::setw(4) << piece.value;
}
return ostream;
}
void Piece::replaceWith(Piece& otherPiece) {
color = otherPiece.color;
value = otherPiece.value;
otherPiece.clear();
}
bool Piece::empty() const {
return value == 0;
}
void Piece::clear() {
value = 0;
}