~ubuntu-branches/ubuntu/trusty/qgo/trusty

« back to all changes in this revision

Viewing changes to src/game_interfaces/qgoboard.h

  • Committer: Package Import Robot
  • Author(s): Yann Dirson
  • Date: 2012-05-19 19:05:05 UTC
  • mfrom: (5.1.3 sid)
  • Revision ID: package-import@ubuntu.com-20120519190505-lf69o1jee5aaizd9
Tags: 2~svn764-1
* The "Raise dead" release (Closes: #673520), new maintainer.
* New upstream snapshot with Qt4 support (Closes: #604589), adjusted
  build-deps.
* Switched to source format "3.0 (quilt)", adjusted build-deps.
* Switched to dh and debhelper compat level 9, adjusted build-deps.
* Build with -fpermissive.
* New build-dep libasound2-dev, remove obsolete build-dep on libxinerama-dev.
* Refreshed patches 01_gnugo and 04_desktop, leaving 20_kfreebsd away
  for this release, and removing the remaining ones, now obsolete.
* Added patch 02_usrgames for FHS-correct install location.
* Adjusted icon names in menu file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (C) 2009 by The qGo Project                                 *
 
3
 *                                                                         *
 
4
 *   This file is part of qGo.                                             *
 
5
 *                                                                         *
 
6
 *   qGo is free software: you can redistribute it and/or modify           *
 
7
 *   it under the terms of the GNU General Public License as published by  *
 
8
 *   the Free Software Foundation; either version 2 of the License, or     *
 
9
 *   (at your option) any later version.                                   *
 
10
 *                                                                         *
 
11
 *   This program is distributed in the hope that it will be useful,       *
 
12
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 
13
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 
14
 *   GNU General Public License for more details.                          *
 
15
 *                                                                         *
 
16
 *   You should have received a copy of the GNU General Public License     *
 
17
 *   along with this program; if not, see <http://www.gnu.org/licenses/>   *
 
18
 *   or write to the Free Software Foundation, Inc.,                       *
 
19
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 
20
 ***************************************************************************/
 
21
 
 
22
 
 
23
/***************************************************************************
 
24
*
 
25
* This class is the most important
 
26
* It  deals with distributing the move (and  other commands) requests 
 
27
* It is subclassed in the different proxies that can be used : local game,
 
28
* server game, and computer game
 
29
* Its the only class (apart from 'sgf parser') to modify the game tree
 
30
 
31
***************************************************************************/
 
32
 
 
33
#ifndef QGOBOARD_H
 
34
#define QGOBOARD_H
 
35
 
 
36
#include "boardwindow.h"
 
37
#include "tree.h"
 
38
#include "defines.h"
 
39
#include "qgtp.h"
 
40
 
 
41
/* I think its easier to have the computer and normal modes override a few functions to
 
42
 * null then have review and match provide the same complicated net functionality */
 
43
 
 
44
 
 
45
class qGoBoard : public QObject //, public Misc<QString>
 
46
{
 
47
        Q_OBJECT
 
48
 
 
49
public:
 
50
        qGoBoard(BoardWindow *bw, Tree * t, GameData *gd);
 
51
//      qGoBoard(qGoBoard &qgoboard );
 
52
        virtual ~qGoBoard() {}; 
 
53
        virtual void setHandicap(int handicap);
 
54
        virtual void addStone(StoneColor c, int x, int y);
 
55
 
 
56
        virtual void addMark( int x, int y, MarkType t );
 
57
        virtual void removeMark( int x, int y);
 
58
 
 
59
//      virtual void localMoveRequest(int x, int y)=0;
 
60
        virtual bool getBlackTurn(bool time = false);
 
61
        virtual void startGame() {};
 
62
        virtual void stopTime() {};
 
63
        virtual void set_move(StoneColor , QString , QString ) {};
 
64
        virtual void handleMove(class MoveRecord *) {};
 
65
        virtual void moveControl(QString &) {};
 
66
        int getMoveNumber(void);
 
67
        //virtual void set_havegd(bool b)               { have_gameData = b; }
 
68
        virtual void setModified(bool b= true)          { isModified = b;}
 
69
        virtual bool getModified()                      { return isModified; }
 
70
        virtual bool getPlaySound()                     { return playSound;}
 
71
        virtual void setPlaySound(bool b)               { playSound = b; }
 
72
        
 
73
        virtual void setResult(class GameResult & );
 
74
        virtual void kibitzReceived(const QString& txt);
 
75
        virtual void setTimerInfo(const QString&, const QString&, const QString&, const QString&) {}
 
76
        virtual void timerEvent(QTimerEvent*);
 
77
        class TimeRecord getOurTimeRecord(void);                //awkward
 
78
        class TimeRecord getTheirTimeRecord(void);
 
79
        virtual void enterScoreMode();
 
80
        virtual void leaveScoreMode();
 
81
        void toggleGroupAt(int x, int y);
 
82
        virtual void markDeadStone(int x, int y);
 
83
        virtual void markLiveStone(int x, int y);
 
84
        virtual void markDeadArea(int x, int y);
 
85
        virtual void markLiveArea(int x, int y);
 
86
 
 
87
        virtual void setNode(int , StoneColor , int , int ) {}
 
88
        virtual void requestAdjournDialog(void) {};
 
89
        virtual void requestCountDialog(void) {};
 
90
        virtual void requestMatchModeDialog(void) {};
 
91
        virtual void requestDrawDialog(void) {};
 
92
        virtual void adjournGame(void) {};
 
93
        virtual void recvRefuseAdjourn(void) {};
 
94
        virtual void recvRefuseCount(void) {};
 
95
        virtual void recvRefuseMatchMode(void) {};
 
96
        virtual void recvRefuseDraw(void) {};
 
97
//      int get_id() const { return id; }
 
98
//      void set_id(int i) { id = i; /*gd.gameNumber = i;*/ }
 
99
//      GameData get_gameData() { return gd; }
 
100
 
 
101
//      void set_title(const QString&);
 
102
//      bool get_haveTitle() { return haveTitle; }
 
103
//      void set_komi(const QString&);
 
104
//      void set_freegame(bool);
 
105
//      bool get_havegd() { return have_gameData; }
 
106
//      bool get_sentmovescmd() { return sent_movescmd; }
 
107
//      void set_sentmovescmd(bool m) { sent_movescmd = m; }
 
108
//      bool get_adj() { return adjourned; }
 
109
//      QString get_bplayer() { return gd.playerBlack; }
 
110
//      QString get_wplayer() { return gd.playerWhite; }
 
111
//      void set_adj(bool a) { adjourned = a; }
 
112
//      void set_game(Game *g);
 
113
 
 
114
//      void set_Mode(int);
 
115
//      GameMode get_Mode() { return gameMode; }
 
116
//      void set_move(StoneColor, QString, QString);
 
117
//      void send_kibitz(const QString);
 
118
//      MainWindow *get_win() { return win; }
 
119
//      void initGame() { win->getBoard()->initGame(&gd); }
 
120
//      void setMode() { win->getBoard()->setMode(gameMode); }
 
121
 
 
122
//      QString secToTime(int);
 
123
/*      void set_stopTimer();
 
124
        void set_runTimer();
 
125
        void set_gamePaused(bool p) { game_paused = p; }
 
126
        int get_boardsize() { return gd.size; }
 
127
        int get_mvcount() { return mv_counter; }
 
128
        void set_myColorIsBlack(bool b);
 
129
        bool get_myColorIsBlack() { return myColorIsBlack; }
 
130
        void set_requests(const QString &handicap, const QString &komi, assessType);
 
131
        void check_requests();
 
132
        QString get_reqKomi() { return req_komi; }
 
133
        QString get_currentKomi() { return QString::number(gd.komi); }
 
134
        void dec_mv_counter() { mv_counter--; }
 
135
        int get_mv_counter() { return mv_counter; }
 
136
        bool get_requests_set() { return requests_set; }
 
137
        qGo* get_qgo() { return qgo; }
 
138
        void set_gsName(GSName g) { gsName = g; }
 
139
        void addtime_b(int m);
 
140
        void addtime_w(int m);
 
141
        void set_myName(const QString &n) { myName = n; }
 
142
 
 
143
        // teaching features
 
144
        bool        ExtendedTeachingGame;
 
145
        bool        IamTeacher;
 
146
        bool        IamPupil;
 
147
        bool        havePupil;
 
148
        bool        haveControls;
 
149
        QString     ttOpponent;
 
150
        bool        mark_set;
 
151
        int         mark_counter;
 
152
        GameData    gd;
 
153
 
 
154
signals:
 
155
        // to qGoIF
 
156
//      void signal_closeevent(int);
 
157
        void signal_sendcommand(const QString&, bool);
 
158
        void signal_2passes(const QString&, const QString&);
 
159
*/
 
160
public slots:
 
161
 
 
162
 
 
163
        // Board
 
164
        virtual void slotBoardClicked(bool, int, int , Qt::MouseButton );
 
165
        virtual void slotPassPressed();
 
166
        virtual void slotDonePressed();
 
167
        virtual void slotResignPressed();
 
168
        virtual void slotReviewPressed() {};
 
169
        virtual void slotDrawPressed() {};
 
170
        virtual void slotCountPressed() {};
 
171
        virtual void slotUndoPressed();
 
172
        virtual void slotScoreToggled(bool);
 
173
        virtual void slotUpdateComment();
 
174
        virtual void slotSendComment() {};
 
175
//      virtual void slot_remoteMove(bool ok, const QString &answer);
 
176
protected:
 
177
        BoardWindow *boardwindow;
 
178
        Tree *tree;
 
179
        GameData *gameData;
 
180
        Sound *clickSound;
 
181
        int boardTimerId;
 
182
 
 
183
//      bool        timer_running;
 
184
//      bool        game_paused;
 
185
//      bool    have_gameData;
 
186
        bool    isModified;
 
187
//      bool        sent_movescmd;
 
188
//      bool        adjourned;
 
189
//      bool        myColorIsBlack;
 
190
//      bool        myColorIsWhite;
 
191
//      bool        haveTitle;
 
192
//      GameMode    gameMode;
 
193
        //GameData    gd;
 
194
        int         id;
 
195
//      MainWindow  *win;
 
196
//      qGo         *qgo;
 
197
//      int         mv_counter;
 
198
        int     stated_mv_count;
 
199
        Move * lastMoveInGame;
 
200
        bool    playSound;
 
201
//      int         bt_i, wt_i;
 
202
//      QString     bt, wt;
 
203
//      QString     b_stones, w_stones;
 
204
//      QString     req_handicap;
 
205
//      QString     req_komi;
 
206
//      assessType  req_free;
 
207
//      bool                requests_set;
 
208
//      QString     myName;
 
209
//      int         BY_timer;
 
210
 
 
211
//#ifdef SHOW_INTERNAL_TIME
 
212
//      int chk_b, chk_w;
 
213
//#endif
 
214
 
 
215
        virtual void localMoveRequest(StoneColor c, int x, int y);
 
216
        virtual void localMarkDeadRequest(int x, int y);
 
217
        virtual void sendMoveToInterface(StoneColor ,int, int) {};
 
218
        virtual void sendPassToInterface(StoneColor ) { doPass(); };
 
219
        virtual bool doMove(StoneColor c, int x, int y, bool dontplayyet = false);
 
220
        virtual void doPass(); //TODO check wether it's usefull to pass the color as in doMove
 
221
private:
 
222
        bool dontCheckValidity;
 
223
        QTime lastSound;
 
224
};
 
225
 
 
226
/* We can override the virtuals above with nulls below if the option
 
227
 * isn't supported or needs to be drastically changed */
 
228
 
 
229
 
 
230
class qGoBoardNormalInterface : public qGoBoard 
 
231
{
 
232
 
 
233
public:
 
234
        qGoBoardNormalInterface(BoardWindow *boardWindow, Tree * tree, GameData *gameData);
 
235
        virtual ~qGoBoardNormalInterface() {}
 
236
 
 
237
 
 
238
private:
 
239
        void sendMoveToInterface(StoneColor /*c*/,int /*x*/, int /*y*/ ) {}
 
240
//      bool doMove(StoneColor c, int x, int y);
 
241
//      void enterScoreMode();
 
242
};
 
243
 
 
244
class qGoBoardComputerInterface : public qGoBoard 
 
245
{
 
246
        Q_OBJECT
 
247
 
 
248
public:
 
249
        qGoBoardComputerInterface(BoardWindow *boardWindow, Tree * tree, GameData *gameData);
 
250
        ~qGoBoardComputerInterface();
 
251
        void set_move(StoneColor sc, QString pt, QString mv_nr);
 
252
 
 
253
public slots:
 
254
        void slot_playComputer(bool ok, const QString &computer_answer);
 
255
        virtual void slotDonePressed();
 
256
        virtual void slotUndoPressed();
 
257
 
 
258
private:
 
259
//      bool doMove(StoneColor c, int x, int y);
 
260
        virtual void sendMoveToInterface(StoneColor c,int x, int y);
 
261
        virtual void sendPassToInterface(StoneColor c);
 
262
 
 
263
        void playComputer(StoneColor c);
 
264
        void localPassRequest();
 
265
        void startGame();
 
266
//      void enterScoreMode() {}
 
267
        void leaveScoreMode() {}
 
268
 
 
269
        QGtp *gtp;
 
270
};
 
271
 
 
272
class qGoBoardNetworkInterface : public qGoBoard
 
273
{
 
274
        Q_OBJECT
 
275
public:
 
276
        virtual ~qGoBoardNetworkInterface() {};
 
277
public slots:
 
278
        virtual void slotSendComment(); 
 
279
        virtual void slotUndoPressed();
 
280
        virtual void slotDonePressed();
 
281
        virtual void slotResignPressed();
 
282
        virtual void slotReviewPressed() {};            //should FIXME these two
 
283
        virtual void slotAdjournPressed() {};
 
284
protected:
 
285
        qGoBoardNetworkInterface(BoardWindow *boardWindow, Tree * tree, GameData *gameData);
 
286
        virtual void sendMoveToInterface(StoneColor c,int x, int y);
 
287
        virtual void sendPassToInterface(StoneColor c);
 
288
        virtual void handleMove(MoveRecord * m);
 
289
        virtual void moveControl(QString & player) { controlling_player = player; };
 
290
        virtual void adjournGame(void);
 
291
        virtual void startGame(void) {};
 
292
        virtual void stopTime(void);
 
293
        virtual void onFirstMove(void) {};
 
294
        
 
295
        QString game_Id;
 
296
        bool dontsend;
 
297
        QString controlling_player;
 
298
        Move * reviewCurrent;
 
299
};
 
300
 
 
301
class qGoBoardObserveInterface : public qGoBoardNetworkInterface
 
302
{
 
303
        Q_OBJECT
 
304
 
 
305
public:
 
306
        qGoBoardObserveInterface(BoardWindow *boardWindow, Tree * tree, GameData *gameData);
 
307
        ~qGoBoardObserveInterface() {}
 
308
 
 
309
        void setModified(bool)  {} //we don't modify an observed game
 
310
        
 
311
public slots:
 
312
        void slotUpdateComment() {}             //what is this ?!?!?
 
313
        virtual void slotUndoPressed(void){};
 
314
        virtual void slotDonePressed(void){};
 
315
        virtual void slotResignPressed(void){};
 
316
        virtual void slotAdjournPressed(void){};
 
317
 
 
318
signals:
 
319
        void signal_sendCommandFromBoard(const QString&, bool);
 
320
 
 
321
private:
 
322
//      bool doMove(StoneColor c, int x, int y);
 
323
        virtual void onFirstMove(void);
 
324
 
 
325
        
 
326
 
 
327
};
 
328
 
 
329
class qGoBoardMatchInterface : public qGoBoardNetworkInterface 
 
330
{
 
331
        Q_OBJECT
 
332
 
 
333
public:
 
334
        qGoBoardMatchInterface(BoardWindow *boardWindow, Tree * tree, GameData *gameData);
 
335
        ~qGoBoardMatchInterface() {}
 
336
 
 
337
        void setModified(bool)  {} //we don't modify a match game
 
338
        void setTimerInfo(const QString&, const QString&, const QString&, const QString&);
 
339
        void enterScoreMode();
 
340
        void leaveScoreMode();
 
341
        void timerEvent(QTimerEvent*);
 
342
        virtual void requestAdjournDialog(void);
 
343
        virtual void requestCountDialog(void);
 
344
        virtual void requestMatchModeDialog(void);
 
345
        virtual void requestDrawDialog(void);
 
346
        virtual void recvRefuseAdjourn(void);
 
347
        virtual void recvRefuseCount(void);
 
348
        virtual void recvRefuseMatchMode(void);
 
349
        virtual void recvRefuseDraw(void);
 
350
public slots:
 
351
        void slotUpdateComment() {}
 
352
        virtual void slotReviewPressed();
 
353
        virtual void slotDrawPressed();
 
354
        virtual void slotCountPressed();
 
355
        virtual void slotAdjournPressed();
 
356
 
 
357
signals:
 
358
        void signal_sendCommandFromBoard(const QString&, bool);
 
359
 
 
360
private:
 
361
        void localMoveRequest(StoneColor c, int x, int y);
 
362
        void localMarkDeadRequest(int x, int y);
 
363
        virtual void startGame(void);
 
364
        virtual void onFirstMove(void);
 
365
//      bool warningSound;
 
366
//      int warningSecs;
 
367
 
 
368
};
 
369
 
 
370
class qGoBoardReviewInterface : public qGoBoardNetworkInterface 
 
371
{
 
372
        Q_OBJECT
 
373
 
 
374
public:
 
375
        qGoBoardReviewInterface(BoardWindow *boardWindow, Tree * tree, GameData *gameData);
 
376
        ~qGoBoardReviewInterface() {}
 
377
 
 
378
//      void setModified(bool)  {} //we don't modify an  game
 
379
//      void setResult(QString res, QString xt_res);
 
380
//      void setTimerInfo(const QString&, const QString&, const QString&, const QString&);
 
381
        //void set_move(StoneColor sc, QString pt, QString mv_nr);
 
382
        void setNode(int move_nr, StoneColor c, int x, int y);
 
383
 
 
384
public slots:
 
385
        void slotUpdateComment() {}
 
386
//      void slotDonePressed();
 
387
        void slotUndoPressed() ;
 
388
 
 
389
signals:
 
390
        void signal_sendCommandFromBoard(const QString&, bool);
 
391
 
 
392
private:
 
393
        void localMoveRequest(StoneColor c, int x, int y);
 
394
 
 
395
};
 
396
 
 
397
 
 
398
#endif