File indexing completed on 2024-05-19 04:04:47

0001 /*
0002     SPDX-FileCopyrightText: 2008 Sascha Peilicke <sasch.pe@gmx.de>
0003 
0004     SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005 */
0006 
0007 #include "player.h"
0008 
0009 #include "kigo_debug.h"
0010 
0011 namespace Kigo {
0012 
0013 Player::Player(Color color, Type type)
0014     : m_color(color), m_type(type), m_strength(10)
0015 {
0016 }
0017 
0018 Player::Player(const Player &other)
0019     : m_name(other.m_name), m_color(other.m_color)
0020     , m_type(other.m_type), m_strength(other.m_strength)
0021 {
0022 }
0023 
0024 Player &Player::operator=(const Player &other)
0025 {
0026     m_name = other.m_name;
0027     m_color = other.m_color;
0028     m_type = other.m_type;
0029     m_strength = other.m_strength;
0030     return *this;
0031 }
0032 
0033 bool Player::operator==(const Player &other) const
0034 {
0035     return m_name == other.m_name &&
0036            m_color == other.m_color &&
0037            m_type == other.m_type &&
0038            m_strength == other.m_strength;
0039 }
0040 
0041 bool Player::setStrength(int strength)
0042 {
0043     if (strength > 0 && strength < 11) {
0044         m_strength = strength;
0045         return true;
0046     } else {
0047         return false;
0048     }
0049 }
0050 
0051 QDebug operator<<(QDebug debug, const Player &player)
0052 {
0053     if (player.isWhite()) {
0054         debug.nospace() << "white";
0055     } else if (player.isBlack()) {
0056         debug.nospace() << "black";
0057     } else {
0058         debug.nospace() << "invalid";
0059     }
0060     debug.nospace() << " player " << player.name();
0061     return debug;
0062 }
0063 
0064 } // End of namespace Kigo