1 /**********************************************************************
2 *
3 * freedoko a Doppelkopf-Game
4 *
5 * Copyright (C) 2001 – 2018 by Diether Knof and Borg Enders
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of
10 * the License, or (at your option) any later version.
11 *
12 * This program 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 * You can find this license in the file 'gpl.txt'.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
22 *
23 * Contact:
24 * Diether Knof dknof@posteo.de
25 *
26 ********************************************************************/
27
28 #include "constants.h"
29
30 #include "game_type.h"
31
32 /** -> result
33 **
34 ** @param game_type game_type
35 **
36 ** @return name of the game type
37 **/
38 string
to_string(GameType const game_type)39 to_string(GameType const game_type) noexcept
40 {
41 switch(game_type) {
42 case GameType::normal:
43 (void)_("GameType::normal");
44 return "normal";
45 case GameType::thrown_nines:
46 (void)_("GameType::thrown nines");
47 return "thrown nines";
48 case GameType::thrown_kings:
49 (void)_("GameType::thrown kings");
50 return "thrown kings";
51 case GameType::thrown_nines_and_kings:
52 (void)_("GameType::thrown nines and kings");
53 return "thrown nines and kings";
54 case GameType::thrown_richness:
55 (void)_("GameType::thrown richness");
56 return "thrown richness";
57 case GameType::fox_highest_trump:
58 (void)_("GameType::fox highest trump");
59 return "fox highest trump";
60 case GameType::redistribute:
61 (void)_("GameType::redistribute");
62 return "redistribute";
63 case GameType::poverty:
64 (void)_("GameType::poverty");
65 return "poverty";
66 case GameType::genscher:
67 (void)_("GameType::genscher");
68 return "genscher";
69 case GameType::marriage:
70 (void)_("GameType::marriage");
71 return "marriage";
72 case GameType::marriage_solo:
73 (void)_("GameType::marriage solo");
74 return "marriage solo";
75 case GameType::marriage_silent:
76 (void)_("GameType::marriage silent");
77 return "marriage silent";
78 case GameType::solo_jack:
79 (void)_("GameType::solo jack");
80 return "solo jack";
81 case GameType::solo_queen:
82 (void)_("GameType::solo queen");
83 return "solo queen";
84 case GameType::solo_king:
85 (void)_("GameType::solo king");
86 return "solo king";
87 case GameType::solo_queen_jack:
88 (void)_("GameType::solo queen-jack");
89 return "solo queen-jack";
90 case GameType::solo_king_jack:
91 (void)_("GameType::solo king-jack");
92 return "solo king-jack";
93 case GameType::solo_king_queen:
94 (void)_("GameType::solo king-queen");
95 return "solo king-queen";
96 case GameType::solo_koehler:
97 (void)_("GameType::solo koehler");
98 return "solo koehler";
99 case GameType::solo_club:
100 (void)_("GameType::solo club");
101 return "solo club";
102 case GameType::solo_spade:
103 (void)_("GameType::solo spade");
104 return "solo spade";
105 case GameType::solo_heart:
106 (void)_("GameType::solo heart");
107 return "solo heart";
108 case GameType::solo_diamond:
109 (void)_("GameType::solo diamond");
110 return "solo diamond";
111 case GameType::solo_meatless:
112 (void)_("GameType::solo meatless");
113 return "solo meatless";
114 } // switch(gametype)
115
116 DEBUG_ASSERTION(false,
117 "to_string(GameType):\n"
118 " game type not found: " << static_cast<int>(game_type));
119
120 return "";
121 } // string to_string(GameType game_type)
122
123 /** -> result
124 **
125 ** @param game_type game type
126 **
127 ** @return translation of the game type
128 **/
129 string
gettext(GameType const game_type)130 gettext(GameType const game_type)
131 {
132 return gettext("GameType::" + to_string(game_type));
133 }
134
135 /** writes the gametype into the stream
136 **
137 ** @param ostr output stream
138 ** @param game_type game type
139 **
140 ** @return output stream
141 **/
142 ostream&
operator <<(ostream & ostr,GameType const game_type)143 operator<<(ostream& ostr, GameType const game_type)
144 { return (ostr << to_string(game_type)); }
145
146 /** -> result
147 **
148 ** @param name gametype name
149 **
150 ** @return the gametype with name 'name'
151 **/
152 GameType
game_type_from_string(string const & name)153 game_type_from_string(string const& name)
154 {
155 for (auto const g : game_type_list)
156 if (name == to_string(g))
157 return g;
158
159 throw ReadException("unknown game type '" + name + "'");
160 return GameType::normal;
161 } // GameType game_type_from_string(string name)
162
163 /** -> return
164 **
165 ** @param game_type the game type
166 **
167 ** @return whether 'game_type' is a game where the teams are not known in the beginning
168 **/
169 bool
is_with_unknown_teams(GameType const game_type)170 is_with_unknown_teams(GameType const game_type) noexcept
171 {
172 switch (game_type) {
173 case GameType::normal:
174 case GameType::marriage_silent:
175 case GameType::genscher:
176 return true;
177 default:
178 return false;
179 } // switch(game_type)
180 } // bool GameType::is_normal(GameType game_type)
181
182 /** -> return
183 **
184 ** @param game_type the game type
185 **
186 ** @return whether 'game_type' is a 'normal' game
187 **/
188 bool
is_normal(GameType const game_type)189 is_normal(GameType const game_type) noexcept
190 {
191 switch (game_type) {
192 case GameType::normal:
193 case GameType::poverty:
194 case GameType::marriage:
195 case GameType::genscher:
196 return true;
197 default:
198 return false;
199 } // switch(game_type)
200 } // bool GameType::is_normal(GameType game_type)
201
202 /** -> return
203 **
204 ** @param game_type the game type
205 **
206 ** @return whether 'game_type' is a marriage
207 **/
208 bool
is_marriage(GameType const game_type)209 is_marriage(GameType const game_type) noexcept
210 {
211 switch (game_type) {
212 case GameType::marriage:
213 case GameType::marriage_solo:
214 case GameType::marriage_silent:
215 return true;
216 default:
217 return false;
218 } // switch(game_type)
219 } // bool GameType::is_marriage(GameType game_type)
220
221 /** -> return
222 **
223 ** @param game_type the game type
224 **
225 ** @return whether 'game_type' is a poverty
226 **/
227 bool
is_poverty(GameType const game_type)228 is_poverty(GameType const game_type) noexcept
229 {
230 switch (game_type) {
231 case GameType::thrown_nines:
232 case GameType::thrown_kings:
233 case GameType::thrown_nines_and_kings:
234 case GameType::fox_highest_trump:
235 case GameType::redistribute:
236 case GameType::poverty:
237 return true;
238 default:
239 return false;
240 } // switch(game_type)
241 } // bool GameType::is_poverty(GameType game_type)
242
243 /** -> return
244 **
245 ** @param game_type the game type
246 **
247 ** @return whether 'game_type' is a real solo (t.i. no marriage solo)
248 **/
249 bool
is_real_solo(GameType const game_type)250 is_real_solo(GameType const game_type) noexcept
251 {
252 return ( is_color_solo(game_type)
253 || is_picture_solo(game_type)
254 || (game_type == GameType::solo_meatless) );
255 } // bool is_real_solo(GameType game_type)
256
257 /** -> return
258 **
259 ** @param game_type the game type
260 **
261 ** @return whether 'game_type' is a solo
262 **/
263 bool
is_solo(GameType const game_type)264 is_solo(GameType const game_type) noexcept
265 {
266 return ( is_real_solo(game_type)
267 || (game_type == GameType::marriage_solo)
268 || (game_type == GameType::marriage_silent) );
269 } // bool is_solo(GameType game_type)
270
271 /** -> return
272 **
273 ** @param game_type the game type
274 **
275 ** @return whether 'game_type' is a color solo
276 **/
277 bool
is_color_solo(GameType const game_type)278 is_color_solo(GameType const game_type) noexcept
279 {
280 switch (game_type) {
281 case GameType::solo_club:
282 case GameType::solo_spade:
283 case GameType::solo_heart:
284 case GameType::solo_diamond:
285 return true;
286 default:
287 return false;
288 } // switch(game_type)
289 } // bool is_color_solo(GameType game_type)
290
291 /** -> return
292 **
293 ** @param game_type the game type
294 **
295 ** @return whether 'game_type' is a picture solo
296 **/
297 bool
is_picture_solo(GameType const game_type)298 is_picture_solo(GameType const game_type) noexcept
299 {
300 return ( is_single_picture_solo(game_type)
301 || is_double_picture_solo(game_type)
302 || game_type == GameType::solo_koehler);
303 }
304
305 /** -> return
306 **
307 ** @param game_type the game type
308 **
309 ** @return whether 'game_type' is a picture solo
310 **/
311 bool
is_picture_solo_or_meatless(GameType const game_type)312 is_picture_solo_or_meatless(GameType const game_type) noexcept
313 {
314 return ( is_picture_solo(game_type)
315 || game_type == GameType::solo_meatless);
316 }
317
318 /** -> return
319 **
320 ** @param game_type the game type
321 **
322 ** @return whether 'game_type' is a single picture solo
323 **/
324 bool
is_single_picture_solo(GameType const game_type)325 is_single_picture_solo(GameType const game_type) noexcept
326 {
327 switch (game_type) {
328 case GameType::solo_jack:
329 case GameType::solo_queen:
330 case GameType::solo_king:
331 return true;
332 default:
333 return false;
334 } // switch(game_type)
335 } // bool is_single_picture_solo(GameType game_type)
336
337 /** -> return
338 **
339 ** @param game_type the game type
340 **
341 ** @return whether 'game_type' is a double picture solo
342 **/
343 bool
is_double_picture_solo(GameType const game_type)344 is_double_picture_solo(GameType const game_type) noexcept
345 {
346 switch (game_type) {
347 case GameType::solo_queen_jack:
348 case GameType::solo_king_jack:
349 case GameType::solo_king_queen:
350 return true;
351 default:
352 return false;
353 } // switch(game_type)
354 } // bool is_double_picture_solo(GameType game_type)
355