1
/***************************************************************************
2
* Copyright (C) 2009 by The qGo Project *
4
* This file is part of qGo. *
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. *
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. *
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
***************************************************************************/
23
/***************************************************************************
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
31
***************************************************************************/
36
#include "boardwindow.h"
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 */
45
class qGoBoard : public QObject //, public Misc<QString>
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);
56
virtual void addMark( int x, int y, MarkType t );
57
virtual void removeMark( int x, int y);
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; }
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);
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; }
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);
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); }
122
// QString secToTime(int);
123
/* void set_stopTimer();
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; }
144
bool ExtendedTeachingGame;
156
// void signal_closeevent(int);
157
void signal_sendcommand(const QString&, bool);
158
void signal_2passes(const QString&, const QString&);
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);
177
BoardWindow *boardwindow;
183
// bool timer_running;
185
// bool have_gameData;
187
// bool sent_movescmd;
189
// bool myColorIsBlack;
190
// bool myColorIsWhite;
192
// GameMode gameMode;
199
Move * lastMoveInGame;
203
// QString b_stones, w_stones;
204
// QString req_handicap;
206
// assessType req_free;
207
// bool requests_set;
211
//#ifdef SHOW_INTERNAL_TIME
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
222
bool dontCheckValidity;
226
/* We can override the virtuals above with nulls below if the option
227
* isn't supported or needs to be drastically changed */
230
class qGoBoardNormalInterface : public qGoBoard
234
qGoBoardNormalInterface(BoardWindow *boardWindow, Tree * tree, GameData *gameData);
235
virtual ~qGoBoardNormalInterface() {}
239
void sendMoveToInterface(StoneColor /*c*/,int /*x*/, int /*y*/ ) {}
240
// bool doMove(StoneColor c, int x, int y);
241
// void enterScoreMode();
244
class qGoBoardComputerInterface : public qGoBoard
249
qGoBoardComputerInterface(BoardWindow *boardWindow, Tree * tree, GameData *gameData);
250
~qGoBoardComputerInterface();
251
void set_move(StoneColor sc, QString pt, QString mv_nr);
254
void slot_playComputer(bool ok, const QString &computer_answer);
255
virtual void slotDonePressed();
256
virtual void slotUndoPressed();
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);
263
void playComputer(StoneColor c);
264
void localPassRequest();
266
// void enterScoreMode() {}
267
void leaveScoreMode() {}
272
class qGoBoardNetworkInterface : public qGoBoard
276
virtual ~qGoBoardNetworkInterface() {};
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() {};
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) {};
297
QString controlling_player;
298
Move * reviewCurrent;
301
class qGoBoardObserveInterface : public qGoBoardNetworkInterface
306
qGoBoardObserveInterface(BoardWindow *boardWindow, Tree * tree, GameData *gameData);
307
~qGoBoardObserveInterface() {}
309
void setModified(bool) {} //we don't modify an observed game
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){};
319
void signal_sendCommandFromBoard(const QString&, bool);
322
// bool doMove(StoneColor c, int x, int y);
323
virtual void onFirstMove(void);
329
class qGoBoardMatchInterface : public qGoBoardNetworkInterface
334
qGoBoardMatchInterface(BoardWindow *boardWindow, Tree * tree, GameData *gameData);
335
~qGoBoardMatchInterface() {}
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);
351
void slotUpdateComment() {}
352
virtual void slotReviewPressed();
353
virtual void slotDrawPressed();
354
virtual void slotCountPressed();
355
virtual void slotAdjournPressed();
358
void signal_sendCommandFromBoard(const QString&, bool);
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;
370
class qGoBoardReviewInterface : public qGoBoardNetworkInterface
375
qGoBoardReviewInterface(BoardWindow *boardWindow, Tree * tree, GameData *gameData);
376
~qGoBoardReviewInterface() {}
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);
385
void slotUpdateComment() {}
386
// void slotDonePressed();
387
void slotUndoPressed() ;
390
void signal_sendCommandFromBoard(const QString&, bool);
393
void localMoveRequest(StoneColor c, int x, int y);