bump up
[mancala] / src / GameInfo.h
1 /*
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
5
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.
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 */
19
20 #ifndef GAMEINFO_H
21 #define GAMEINFO_H
22
23 #include <QXmlStreamReader>
24 #include <QList>
25 #include <QPair>
26
27 //Store the necessary info of game. For example, num of rows, cup per row, num of stone
28 //initially etc.
29
30 class GameInfo : public QXmlStreamReader{
31     public:
32         GameInfo();
33         ~GameInfo();
34 //enums
35         enum Rotation{ CLOCKWISE,ANTICLOCKWISE,COMPLICATED };
36         //PUlll Across - captured pieces statrs from player's side(omweso)
37         enum Capture{ CROSS,COUNT,SERIES,PULL_ACCROSS };
38         enum Side{ NONE,OWN,OPPONENT,BOTH };
39         enum Lap{ SINGLE, MULTIPLE, PUSSA_KANAWA};
40         enum GameType{TRADITIONAL,MODERN,CUSTOM};
41         enum CountCapture{NUMBER,PATTERN};
42         enum SeriesCapture{ FOLLOWING,PRECEDING};
43         enum GrandSlam{ INVALID,NO_CAPTURE,CAPTURE,PENALTY };
44         enum WinCondition{ TOTAL_STONE,DISABLING_OPPONENT,GOING_EMPTY };
45         enum Pattern{EVEN,ODD};
46         enum Direction{LEFT,RIGHT};
47
48 //functions
49         void initializeAll();
50
51         int numCupsPerRow() const{ return m_cups_per_row; }
52         int numRows() const{ return m_num_rows; }
53         int numKalahs() const{ return m_num_kalahs; }
54         int initialStonesPerCup() const{ return m_initial_stones_per_cup; }
55         int stones() const{ return m_initial_stones_per_cup * m_num_rows * m_cups_per_row;}
56         Rotation rotationType() const{ return m_rotation_type;}
57         int stonesToKalah() const{ return m_stones_to_kalah;}
58         int leftToCup() const{ return m_left_stone_to_cup;}
59         bool omitCup() const{return m_omit_initial_cup;}
60         int lapStyle() const{ return m_lap_style;}
61         int stonesToEndLap() const{ return m_stones_to_end_lap;}
62         bool isBonusTurn() const{ return m_bonus_turn;}
63         int specialFlag() const{ return m_special_flags;}
64
65         void setGameInfo(QString file);
66         void parseXmlFile( QIODevice *device );
67         void setLogicalBoard();
68
69         int captureType(){return m_capture_types;}
70         QList< QPair<Side,QList<int> > > captureInfo(){ return m_capture_info;}
71
72         int rotationInfo(int cupIndex){ return m_rotation_cup[cupIndex];}
73
74     protected:
75
76     private:
77
78         GameType m_type;//modern,traditional(default-traditional)
79         QString m_region;
80
81         //Board Info
82         int m_num_rows;
83         int m_cups_per_row;
84         int m_initial_stones_per_cup;
85         int m_num_kalahs; //In kalah,oware 2
86
87         //Game Info
88
89         //sowing
90         Lap m_lap_style;              //which lap style the game follows(default-single)
91         //If game has multiple lap, then it ends if the last stone put in kalah(m_stones_to_kalah is not none)
92         //or it ends in a cup which has some number of stone
93         int m_stones_to_end_lap;      //only for multiple lap
94         Side m_side_to_end_lap;         //on which side the cup should be
95
96         Rotation m_rotation_type;    // In kalah,oware anticlockwise(default-anitclockwise)
97         QList<Rotation>m_rotation_cup; //For Every cup, there will be a rotation type(bechi)
98
99         Side m_sowing_side;     //from whose side sowing starts for a player(default-own)
100         int m_min_stones_to_sow;  //In kalah,oware 1(default-1)
101         bool m_omit_initial_cup;   //Is it necessary to omit cup when sowing(default-false)
102                                     //it may happen when a cup has more than 2*n-1 stones
103                                     //in oware(n->numofcups)
104         int m_left_stone_to_cup;    // 0->empty cup, 1->keep 1 stone at house when sowing and so on(default-0)
105         bool m_bonus_turn;          //Is bonus turn allowed(default-false)
106         Side m_stones_to_kalah;   //default - none
107
108
109         //capture
110         int m_capture_types;  //0th bit-cross, 1st-count, 2nd-series, 3rd-GrandSlam, 4th-PullAcross
111         QList< QPair<Side,QList<int> > > m_capture_info; //For every capture, the stone info in cup
112         //For example in cross capture(kalah) both,1(the stonenumber in the cup where last stone
113         //is put), for count capture(oware) opponent,(GameInfo::NUMBER,2,3)(opponent cup should have 2 or 3 stones to capture)
114         //For series capture(oware) opponent,GameInfo::FOLLOWING
115         //GrandSlam m_grandslam_option;//If a series capture empties the opponent it is called
116         //GrandSlam
117
118         bool m_cup_movement_previously; //needed for bechi when count/series capture (default-false)
119
120
121         //special rules
122         int m_special_flags; // 0th-empty opponent, 1st-turn passing, 2nd-compulsory move
123         //Can you keep your opponent empty(default-true)
124         //Is Turn passing allowed,if no move(default-true)
125         /*Is it must to move, if possible to your opponents pits whe
126         he has no stones to move, so that he can continue(default-false)*/
127
128         //end rules
129         WinCondition m_win_condition;    //1->by total stones in kalah, 2->by disabling opponent to move,
130         //3->by going empty(if he runs out of seeds) default-total
131
132         //Functions
133         void parseGame();
134         void parseBoard();
135         void parseRules();
136         void parseSowing();
137         void parseCapture();
138         void parseSpecialRules();
139         void parseEndRules();
140
141         void parseRotation();
142         void parseLap();
143         void parseLapEnd();
144
145         void parseCrossCapture();
146         void parseCountCapture();
147         void parseSeriesCapture();
148         void parsePullAcrossCapture();
149
150     };
151
152 #endif // GAMEINFO_H