• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdegames API Reference
  • KDE Home
  • Contact Us
 

kigo

  • sources
  • kde-4.14
  • kdegames
  • kigo
  • src
  • game
stone.cpp
Go to the documentation of this file.
1 /*
2  Copyright 2008 Sascha Peilicke <sasch.pe@gmx.de>
3 
4  This program is free software; you can redistribute it and/or
5  modify it under the terms of the GNU General Public License as
6  published by the Free Software Foundation; either version 2 of
7  the License or (at your option) version 3 or any later version
8  accepted by the membership of KDE e.V. (or its successor approved
9  by the membership of KDE e.V.), which shall act as a proxy
10  defined in Section 14 of version 3 of the license.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20 
21 #include "stone.h"
22 
23 #include <QDebug>
24 
25 namespace Kigo {
26 
27 Stone Stone::Pass = Stone();
28 Stone Stone::Invalid = Stone();
29 
30 Stone::Stone(char x, int y, float value)
31  : m_x(x), m_y(y), m_value(value)
32 {
33 }
34 
35 Stone::Stone(const QString &stone, float value)
36  : m_x(0), m_y(0), m_value(value)
37 {
38  if (stone.size() >= 2) {
39  m_x = stone[0].toUpper().toLatin1();
40  m_y = stone.mid(1).toInt();
41  }
42 }
43 
44 Stone::Stone(const Stone &other)
45  : m_x(other.m_x), m_y(other.m_y), m_value(other.m_value)
46 {
47 }
48 
49 Stone &Stone::operator=(const Stone &other)
50 {
51  m_x = other.m_x;
52  m_y = other.m_y;
53  m_value = other.m_value;
54  return *this;
55 }
56 
57 bool Stone::isValid() const
58 {
59  // Go coordinates are somewhat complicated ...
60  return m_y >= 1 && m_y <= 19 && m_x >= 'A' && m_x != 'I' && m_x <= 'T';
61 }
62 
63 QByteArray Stone::toLatin1() const
64 {
65  return QByteArray(m_x + QByteArray::number(m_y));
66 }
67 
68 QString Stone::toString() const
69 {
70  return QString(m_x + QString::number(m_y));
71 }
72 
73 QDebug operator<<(QDebug debug, const Stone &stone)
74 {
75  debug.nospace() << "stone at " << stone.x() << "," << stone.y()
76  << " of value " << stone.value();
77  return debug;
78 }
79 
80 } // End of namespace Kigo
QString::toUpper
QString toUpper() const
QByteArray
Kigo::Stone::operator=
Stone & operator=(const Stone &other)
Definition: stone.cpp:49
QString::size
int size() const
QDebug::nospace
QDebug & nospace()
Kigo::Stone::Invalid
static Stone Invalid
A standard invalid move object.
Definition: stone.h:35
Kigo::Stone::isValid
bool isValid() const
Definition: stone.cpp:57
QString::number
QString number(int n, int base)
Kigo::Stone::Pass
static Stone Pass
A standard pass move object.
Definition: stone.h:34
QString::toInt
int toInt(bool *ok, int base) const
Kigo::Stone
This class represents a stone on a field of the game board.
Definition: stone.h:31
QByteArray::number
QByteArray number(int n, int base)
QString
Kigo::Stone::value
float value() const
Definition: stone.h:61
Kigo::Stone::toLatin1
QByteArray toLatin1() const
Definition: stone.cpp:63
Kigo::Stone::x
char x() const
Definition: stone.h:59
QDebug
Kigo::Stone::y
int y() const
Definition: stone.h:60
QString::toLatin1
QByteArray toLatin1() const
QString::mid
QString mid(int position, int n) const
Kigo::operator<<
QDebug operator<<(QDebug debug, const Move &move)
Definition: move.cpp:44
Kigo::Stone::toString
QString toString() const
Definition: stone.cpp:68
Kigo::Stone::Stone
Stone(char x=0, int y=0, float value=0)
Standard constructor.
Definition: stone.cpp:30
stone.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:18:29 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kigo

Skip menu "kigo"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdegames API Reference

Skip menu "kdegames API Reference"
  • granatier
  • kapman
  • kblackbox
  • kgoldrunner
  • kigo
  • kmahjongg
  • KShisen
  • ksquares
  • libkdegames
  •   highscore
  •   libkdegamesprivate
  •     kgame
  • libkmahjongg
  • palapeli
  •   libpala

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal