Ported crazyhouse piece. Working on crazyhouse game state.
[tagua.git] / src / hlvariant / chess / piece.cpp
blob72679596716a23818d871d7c61d3fc2917422aa9
1 #include "piece.h"
3 namespace HLVariant {
4 namespace Chess {
6 Piece::~Piece() { }
8 Piece::Piece(Color color, Type type)
9 : m_color(color)
10 , m_type(type) { }
12 Piece::Color Piece::color() const { return m_color; }
14 Piece::Type Piece::type() const { return m_type; }
16 QString Piece::colorName() const { return colorName(m_color); }
18 QString Piece::colorName(Color color) {
19 switch (color) {
20 case WHITE:
21 return "white";
22 case BLACK:
23 return "black";
24 default:
25 return "unknown";
29 QString Piece::typeName() const { return typeName(m_type); }
31 QString Piece::typeName(Type type) {
32 switch (type) {
33 case ROOK:
34 return "rook";
35 case BISHOP:
36 return "bishop";
37 case KNIGHT:
38 return "knight";
39 case QUEEN:
40 return "queen";
41 case KING:
42 return "king";
43 case PAWN:
44 return "pawn";
45 default:
46 return "unknown";
50 QString Piece::name() const {
51 return colorName() + '_' + typeName();
54 Piece::Color Piece::oppositeColor(Color color) {
55 switch (color) {
56 case WHITE:
57 return BLACK;
58 case BLACK:
59 return WHITE;
60 default:
61 return INVALID_COLOR;
65 bool Piece::operator==(const Piece& other) const {
66 return m_color == other.m_color &&
67 m_type == other.m_type;
70 bool Piece::operator!=(const Piece& other) const {
71 return !((*this) == other);
74 } // namespace HLVariant
75 } // namespace Chess