Fix Shogi::Piece::OppositeColor.
[tagua/yd.git] / src / hlvariant / shogi / piece.cpp
blob5b93cfce2efa64e5e010ada06da92c995bc4daf1
1 /*
2 Copyright (c) 2007 Paolo Capriotti <p.capriotti@sns.it>
3 (c) 2007 Maurizio Monge <maurizio.monge@kdemail.net>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9 */
11 #include "piece.h"
13 namespace HLVariant {
14 namespace Shogi {
16 Piece::Piece(Color color, Type type)
17 : m_color(color)
18 , m_type(type)
19 , m_promoted(false) { }
21 Piece::~Piece() { }
23 void Piece::setPromoted() {
24 m_promoted = true;
27 bool Piece::promoted() const {
28 return m_promoted;
31 Piece::Color Piece::color() const { return m_color; }
33 Piece::Type Piece::type() const { return m_type; }
35 QString Piece::colorName() const { return colorName(m_color); }
37 QString Piece::colorName(Color color) {
38 switch (color) {
39 case WHITE:
40 return "white";
41 case BLACK:
42 return "black";
43 default:
44 return "unknown";
48 QString Piece::typeName() const { return typeName(m_type); }
50 QString Piece::typeName(Type type) {
51 switch (type) {
52 case KING:
53 return "king";
54 case GOLD:
55 return "gold";
56 case SILVER:
57 return "silver";
58 case KNIGHT:
59 return "knight";
60 case LANCE:
61 return "lance";
62 case ROOK:
63 return "rook";
64 case BISHOP:
65 return "bishop";
66 case PAWN:
67 return "pawn";
68 default:
69 return "unknown";
73 QString Piece::name() const {
74 QString res = colorName() + '_';
75 if (m_promoted)
76 res += "p_";
77 return res + typeName();
80 Piece::Color Piece::oppositeColor(Color color) {
81 return (color == WHITE) ? BLACK :
82 (color == BLACK) ? WHITE : INVALID_COLOR;
85 bool Piece::operator==(const Piece& other) const {
86 return m_color == other.m_color &&
87 m_type == other.m_type &&
88 m_promoted == other.m_promoted;
91 bool Piece::operator!=(const Piece& other) const {
92 return !((*this) == other);
96 } // namespace Shogi
97 } // namespace HLVariant