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 "stone.h"
0008 
0009 #include "kigo_debug.h"
0010 
0011 namespace Kigo {
0012 
0013 Stone Stone::Pass = Stone();
0014 Stone Stone::Invalid = Stone();
0015 
0016 Stone::Stone(char x, int y, float value)
0017     : m_x(x), m_y(y), m_value(value)
0018 {
0019 }
0020 
0021 Stone::Stone(const QString &stone, float value)
0022     : m_x(0), m_y(0), m_value(value)
0023 {
0024     if (stone.size() >= 2) {
0025         m_x = stone[0].toUpper().toLatin1();
0026         m_y = QStringView(stone).mid(1).toInt();
0027     }
0028 }
0029 
0030 Stone::Stone(const Stone &other)
0031     : m_x(other.m_x), m_y(other.m_y), m_value(other.m_value)
0032 {
0033 }
0034 
0035 Stone &Stone::operator=(const Stone &other)
0036 {
0037     m_x = other.m_x;
0038     m_y = other.m_y;
0039     m_value = other.m_value;
0040     return *this;
0041 }
0042 
0043 bool Stone::isValid() const
0044 {
0045     // Go coordinates are somewhat complicated ...
0046     return m_y >= 1 && m_y <= 19 && m_x >= 'A' && m_x != 'I' && m_x <= 'T';
0047 }
0048 
0049 QByteArray Stone::toLatin1() const
0050 {
0051     return QByteArray(m_x + QByteArray::number(m_y));
0052 }
0053 
0054 QString Stone::toString() const
0055 {
0056     return QString(QLatin1Char(m_x) + QString::number(m_y));
0057 }
0058 
0059 QDebug operator<<(QDebug debug, const Stone &stone)
0060 {
0061     debug.nospace() << "stone at " << stone.x() << "," << stone.y()
0062                     << " of value " << stone.value();
0063     return debug;
0064 }
0065 
0066 bool operator==(const Stone &stone, const Stone &other)
0067 {
0068     return (stone.x() == other.x()) && (stone.y() == other.y());
0069 }
0070 
0071 } // End of namespace Kigo