1/*******************************************************************
2 *
3 * Copyright 2013 Denis Kuplyakov <dener.kup@gmail.com>
4 *
5 * This file is part of the KDE project "KReversi"
6 *
7 * KReversi is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
10 * any later version.
11 *
12 * KReversi 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 KReversi; see the file COPYING. If not, write to
19 * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
21 *
22 ********************************************************************/
23
24#ifndef KREVERSI_PLAYER_H
25#define KREVERSI_PLAYER_H
26
27#include <kreversigame.h>
28#include <QString>
29
30class KReversiGame;
31
32/**
33 * Indicates current state of the player
34 */
35enum KReversiPlayerState {
36 /** Player is waiting for his move or smth else */
37 WAITING,
38 /** Player is thinking about his move */
39 THINKING,
40 /** Player state is unknown */
41 UNKNOWN
42};
43/**
44 * Represents abstract player. It is interface.
45 */
46class KReversiPlayer: public QObject
47{
48 Q_OBJECT
49public:
50 /**
51 * Construct player with specified @p color and @p name.
52 * @param hintAllowed determines whether hints are allowed for player
53 * @param undoAllowed determines whether undos are allowed for player
54 */
55 explicit KReversiPlayer(ChipColor color, QString name,
56 bool hintAllowed, bool undoAllowed);
57
58 /**
59 * Used to get player color
60 * @return color of player
61 */
62 ChipColor getColor() const;
63
64 /**
65 * Used to get player's name
66 * @return player's name
67 */
68 QString getName() const;
69
70 /**
71 * @return is hint allowed for player or not
72 */
73 bool isHintAllowed() const;
74
75 /**
76 * KReversiGame triggers it to to increase used hints count
77 */
78 void hintUsed();
79
80 /**
81 * @return how many times player has used hints
82 */
83 int getHintsCount();
84
85 /**
86 * @return is undo allowed for player
87 */
88 bool isUndoAllowed() const;
89
90 /**
91 * KReversiGame triggers it to to increase used undos count
92 */
93 void undoUsed();
94
95 /**
96 * @return how many times player has used undo
97 */
98 int getUndoCount();
99
100public slots:
101 /**
102 * Triggered by KReversiGame before game starts
103 * Implementation should assign @p game to m_game
104 */
105 virtual void prepare(KReversiGame* game) = 0;
106
107 /**
108 * It triggered from KReversiGame.
109 * Means that player should start think about his move.
110 */
111 virtual void takeTurn() = 0;
112
113 /**
114 * It triggered from KReversiGame.
115 * Means that player can't do move and skips it.
116 */
117 virtual void skipTurn() = 0;
118
119 /**
120 * Triggered by KReversiGame to notify player that game is over.
121 */
122 virtual void gameOver() = 0;
123
124signals:
125 /**
126 * Player emit it when want to notify about his move
127 */
128 void makeMove(KReversiMove);
129
130 /**
131 * Player emit it after he has prepared after getting prepare command
132 */
133 void ready();
134
135protected:
136 /**
137 * Game which player is playing
138 */
139 KReversiGame *m_game;
140
141 /**
142 * Is player thinking or waiting
143 */
144 KReversiPlayerState m_state;
145
146 /**
147 * Player's chip color
148 */
149 ChipColor m_color;
150
151 /**
152 * Player's name to be shown at UI
153 */
154 QString m_name;
155
156 /**
157 * Are hints enabled for player
158 */
159 bool m_hintAllowed;
160
161 /**
162 * How many times player has used hint
163 */
164 int m_hintCount;
165
166 /**
167 * Can player request undo or not
168 */
169 bool m_undoAllowed;
170
171 /**
172 * How many times player has used undo
173 */
174 int m_undoCount;
175};
176
177#endif // KREVERSIPLAYER_H
178