2 Mancala - A Historical Board Game
3 Copyright (C) 2009-2010 A.H.M.Mahfuzur Rahman 65mahfuz90@gmail.com
4 Copyright (c) 2010 Reto Zingg g.d0b3rm4n@gmail.com
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License as
8 published by the Free Software Foundation; either version 2 of
9 the License, or (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/>.
20 #ifndef GAMECONTROLLER_H
21 #define GAMECONTROLLER_H
26 // #include <kxmlguiwindow.h>
28 #include <QSignalMapper>
38 class GameController : public QThread{
42 enum Side{UPPER,LOWER};
43 enum Difficulty{EASY,MEDIUM,HARD};
45 GameController(GameInfo*);
47 void setBoardItem(Board* board);
48 void initializeGameController();
49 int humanKalahIndex(){ return m_humanKalah; }
50 QPair< bool,QList<int> > logicalMoveController(QList<int>board,int cupIndex,bool turn);
53 void signalShowScore(int,bool); //score,whose
54 void signalShowTurn(bool);
55 void signalMessage(const QString);
56 void signalGameOver();
58 void timeout(const QString&);
59 void signalSowMaker(int index);
60 void signalAfterSow(int index);
61 void signalComputerMove();
63 void signalNewGame(int);
64 void signalRestartGame();
67 void slotMouseClicked(int);
68 void slotGameOverForNewGame(int );
69 void slotGameOverForRestartGame();
70 void newGameEmitter(int);
71 void restartGameEmitter();
73 void makeHumanMove(int);
74 void makeComputerMove();
75 void crossCapture(const QString&);
76 void countCapture(const QString&);
77 void slotGameDifficulty(GameController::Difficulty difficulty);
78 void sowMaker(int index);
80 void afterSow(int index);
83 QSignalMapper *signalMapper;
87 bool m_multipleLapDelay;
89 Difficulty m_gameDifficulty;
93 Score* m_computerScore;
95 MoveGenerator *m_moveGenerator;
101 bool m_physicalMoveAllowed; //Will be used to check invalid move
102 int m_cupIndexClicked;
104 //totalStone - first 2*cupPerRow(0,..) will be cupInfo, next 2 KalahInfo(left,right)
105 QList<int> m_logicalBoard;
106 QList<int> m_physicalBoard;
107 QList<QPair< GameInfo::Side,QList<int> > > m_captureInfo;
108 QList<int>m_humanSideCups;
110 void setPhysicalBoard(QList<int> board);
111 void setLogicalBoard(QList<int> board);
112 QList<int> physicalBoard();
113 QList<int> logicalBoard();
115 void initializeBoard();
116 void setHumanSideCups();
118 bool isHumanCup(int index);
119 bool isHumanKalah(int index);
120 bool isGameOver(QList<int>& board);
122 void handleCrossCapture(int,QList<int>& board);
123 int handleCountNSeriesCapture(int,QList<int>& board);
124 int nextIndex(int index,int seriesCaptureIndex);
125 bool stoneNumberMatched(int index,int countCaptureIndex,QList<int>& board);
128 void showBoard(QList<int>&);
129 void changeScore(int amount,bool human);
131 bool isHumanSideEmpty(QList<int>& board);
132 bool isComputerSideEmpty(QList<int>& board);
133 void computerHasNoMove();
134 void humanHasNoMove();
135 void finalCapture(QList<int>& board);
136 void sowingAnimation(int index,int multiplier);
137 int singleSow(int index);
139 bool physicalMoveController(int index);
140 bool isEndOfLap(int index,QList<int>& board);
145 #endif // GAMECONTROLLER_H