Debian Codegraph @

src/ScoreDice.cpp

raw symbols SCIP
1
2 /***************************************************************************
3 * Copyright (C) 2006-2007 by Guy Rutenberg *
4 * [email protected] *
5 * *
6 * This program 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, write to the *
18 * Free Software Foundation, Inc., *
19 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
20 ***************************************************************************/
21
22 #include "ScoreDice.h"cxx . . $ `<file>/src/ScoreDice.h`/
23
24 /**
25 * \brief constructor
26 *
27 * This constructor also sets the values of the dice.
28 */
29 ScoreDicecxx . . $ ScoreDice#::ScoreDicecxx . . $ ScoreDice#ScoreDice(48f4dc425c7fc6aa).(short int dice[5])
30 {
31 SetDicecxx . . $ ScoreDice#SetDice(38b7dc26feddae40).(dice);
32 }
33
34 /**
35 * \brief default constructor
36 * \note if you use this constructor you must call ScoreDice::SetDice before
37 * using the class.
38 * \see ScoreDice::SetDice
39 */
40 ScoreDicecxx . . $ ScoreDice#::ScoreDicecxx . . $ ScoreDice#ScoreDice(49f6e7a06ebc5aa8).()
41 {
42 //nothing to do here
43 }
44 /**
45 * \brief Sets the dice values
46 * \param dice An array of 5 short ints containing the values of the dice.
47 */
48 void ScoreDicecxx . . $ ScoreDice#::SetDicecxx . . $ ScoreDice#SetDice(38b7dc26feddae40).(const short int dice[5])
49 {
50 for (int i=0; i<5; i++)
51 m_dicecxx . . $ ScoreDice#m_dice.[i] = dice[i];
52
53 //fill the dice hash
54 for (int i=0; i<6; i++)
55 m_dicehashcxx . . $ ScoreDice#m_dicehash.[i] = 0;
56 for (int i=0; i<5; i++)
57 m_dicehashcxx . . $ ScoreDice#m_dicehash.[dice[i]-1] += 1;
58
59 m_yahtzee_jokercxx . . $ ScoreDice#m_yahtzee_joker. = false;
60 }
61
62 /**
63 * Tells the scoring class wheter or not we have a Yahtzee Joker.
64 * \param is_yahtzee_joker [bool] true if there is a Yahtzee Joker.
65 * \note checking whether we got a yahtzee joker is done by an outside function,
66 * and it needs the dice set before it can operate.
67 * \see MainFrame::YahtzeeJoker()
68 */
69 void ScoreDicecxx . . $ ScoreDice#::SetYahtzeeJokercxx . . $ ScoreDice#SetYahtzeeJoker(b45ddcbc8423892c).(const bool is_yahtzee_joker)
70 {
71 m_yahtzee_jokercxx . . $ ScoreDice#m_yahtzee_joker. = is_yahtzee_joker;
72 }
73
74 /**
75 * \brief Gets the value of a dice.
76 * \param number the index of the dice wanted.
77 * \return the value of the dice. 0 if wrong input.
78 */
79 short int ScoreDicecxx . . $ ScoreDice#::GetDicecxx . . $ ScoreDice#GetDice(14a1761c3ef4450f).(const short int number)
80 {
81 if (number<=5 && number >=1)
82 return m_dicecxx . . $ ScoreDice#m_dice.[number-1];
83 return 0;
84 }
85 /**
86 * \return the score for the aces box.
87 */
88 short int ScoreDicecxx . . $ ScoreDice#::Acescxx . . $ ScoreDice#Aces(524863554b4a534e).() const
89 {
90 return m_dicehashcxx . . $ ScoreDice#m_dicehash.[0];
91 }
92
93 /**
94 * \return the score for the twos box.
95 */
96 short int ScoreDicecxx . . $ ScoreDice#::Twoscxx . . $ ScoreDice#Twos(524863554b4a534e).() const
97 {
98 return 2*m_dicehashcxx . . $ ScoreDice#m_dicehash.[1];
99 }
100
101
102 /**
103 * \return the score for the threes box.
104 */
105 short int ScoreDicecxx . . $ ScoreDice#::Threescxx . . $ ScoreDice#Threes(524863554b4a534e).() const
106 {
107 return 3*m_dicehashcxx . . $ ScoreDice#m_dicehash.[2];
108 }
109
110 /**
111 * \return the score for the fours box.
112 */
113 short int ScoreDicecxx . . $ ScoreDice#::Fourscxx . . $ ScoreDice#Fours(524863554b4a534e).() const
114 {
115 return 4*m_dicehashcxx . . $ ScoreDice#m_dicehash.[3];
116 }
117
118 /**
119 *
120 * \return the score for the fives box.
121 */
122 short int ScoreDicecxx . . $ ScoreDice#::Fivescxx . . $ ScoreDice#Fives(524863554b4a534e).() const
123 {
124 return 5*m_dicehashcxx . . $ ScoreDice#m_dicehash.[4];
125 }
126
127 /**
128 *
129 * \return the score for the sixes box.
130 */
131 short int ScoreDicecxx . . $ ScoreDice#::Sixescxx . . $ ScoreDice#Sixes(524863554b4a534e).() const
132 {
133 return 6*m_dicehashcxx . . $ ScoreDice#m_dicehash.[5];
134 }
135
136 /**
137 *
138 * \return the score for the "Three of A Kind" box.
139 */
140 short int ScoreDicecxx . . $ ScoreDice#::ThreeOfAKindcxx . . $ ScoreDice#ThreeOfAKind(524863554b4a534e).() const
141 {
142 bool three = false;
143
144 for (int i=0; i<6; i++)
145 if (m_dicehashcxx . . $ ScoreDice#m_dicehash.[i] >= 3)
146 three = true;
147 if (three)
148 return Chancecxx . . $ ScoreDice#Chance(524863554b4a534e).();
149 return 0;
150 }
151
152 /**
153 *
154 * \return the score for the "Four of A Kind" box.
155 */
156 short int ScoreDicecxx . . $ ScoreDice#::FourOfAKindcxx . . $ ScoreDice#FourOfAKind(524863554b4a534e).() const
157 {
158 bool four = false;
159
160 for (int i=0; i<6; i++)
161 if (m_dicehashcxx . . $ ScoreDice#m_dicehash.[i] >= 4)
162 four = true;
163 if (four)
164 return Chancecxx . . $ ScoreDice#Chance(524863554b4a534e).();
165 return 0;
166 }
167
168 /**
169 *
170 * \return the score for the "Full House" box.
171 */
172 short int ScoreDicecxx . . $ ScoreDice#::FullHousecxx . . $ ScoreDice#FullHouse(524863554b4a534e).() const
173 {
174 bool two = false;
175 bool three = false;
176
177 for (int i=0; i<6; i++)
178 if (m_dicehashcxx . . $ ScoreDice#m_dicehash.[i] == 2)
179 two = true;
180 for (int i=0; i<6; i++)
181 if (m_dicehashcxx . . $ ScoreDice#m_dicehash.[i] == 3)
182 three = true;
183 if ((two && three) || m_yahtzee_jokercxx . . $ ScoreDice#m_yahtzee_joker.)
184 return 25;
185 return 0;
186 }
187
188 /**
189 *
190 * \return the score for the small sequence box.
191 */
192 short int ScoreDicecxx . . $ ScoreDice#::SmallSequencecxx . . $ ScoreDice#SmallSequence(524863554b4a534e).() const
193 {
194 if ( (m_dicehashcxx . . $ ScoreDice#m_dicehash.[0]>=1 && m_dicehashcxx . . $ ScoreDice#m_dicehash.[1]>=1 && m_dicehashcxx . . $ ScoreDice#m_dicehash.[2]>=1 &&
195 m_dicehashcxx . . $ ScoreDice#m_dicehash.[3]>=1) || (m_dicehashcxx . . $ ScoreDice#m_dicehash.[1]>=1 && m_dicehashcxx . . $ ScoreDice#m_dicehash.[2]>=1 &&
196 m_dicehashcxx . . $ ScoreDice#m_dicehash.[3]>=1 && m_dicehashcxx . . $ ScoreDice#m_dicehash.[4]>=1) || (m_dicehashcxx . . $ ScoreDice#m_dicehash.[2]>=1 &&
197 m_dicehashcxx . . $ ScoreDice#m_dicehash.[3]>=1 && m_dicehashcxx . . $ ScoreDice#m_dicehash.[4]>=1 && m_dicehashcxx . . $ ScoreDice#m_dicehash.[5]>=1))
198 return 30;
199 else if (m_yahtzee_jokercxx . . $ ScoreDice#m_yahtzee_joker.)
200 return 30;
201 return 0;
202 }
203
204 /**
205 *
206 * \return the score for the large sequence box.
207 */
208 short int ScoreDicecxx . . $ ScoreDice#::LargeSequencecxx . . $ ScoreDice#LargeSequence(524863554b4a534e).() const
209 {
210 if ( (m_dicehashcxx . . $ ScoreDice#m_dicehash.[0]==1 && m_dicehashcxx . . $ ScoreDice#m_dicehash.[1]==1 && m_dicehashcxx . . $ ScoreDice#m_dicehash.[2]==1 &&
211 m_dicehashcxx . . $ ScoreDice#m_dicehash.[3]==1 && m_dicehashcxx . . $ ScoreDice#m_dicehash.[4]==1) || (m_dicehashcxx . . $ ScoreDice#m_dicehash.[1]==1 &&
212 m_dicehashcxx . . $ ScoreDice#m_dicehash.[2]==1 && m_dicehashcxx . . $ ScoreDice#m_dicehash.[3]==1 && m_dicehashcxx . . $ ScoreDice#m_dicehash.[4]==1 &&
213 m_dicehashcxx . . $ ScoreDice#m_dicehash.[5]==1))
214 return 40;
215 else if (m_yahtzee_jokercxx . . $ ScoreDice#m_yahtzee_joker.)
216 return 40;
217 return 0;
218 }
219 /**
220 *
221 * \return the score for the Yahtzee box.
222 */
223 short int ScoreDicecxx . . $ ScoreDice#::Yahtzeecxx . . $ ScoreDice#Yahtzee(524863554b4a534e).() const
224 {
225 if (IsYahtzeecxx . . $ ScoreDice#IsYahtzee(50ce9a9e25b4a850).())
226 return 50;
227 return 0;
228 }
229
230
231 /**
232 *
233 * \return the score for the chance box.
234 */
235 short int ScoreDicecxx . . $ ScoreDice#::Chancecxx . . $ ScoreDice#Chance(524863554b4a534e).() const
236 {
237 short int temp = 0;
238 for(int i = 0; i<5; i++)
239 temp += m_dicecxx . . $ ScoreDice#m_dice.[i];
240
241 return temp;
242 }
243
244 /**
245 * \brief determines wheter the current dice hold a Yahtzee or not.
246 * \return true or false depending on whether there is a Yahtzee or not.
247 */
248 bool ScoreDicecxx . . $ ScoreDice#::IsYahtzeecxx . . $ ScoreDice#IsYahtzee(50ce9a9e25b4a850).() const
249 {
250 if ((m_dicecxx . . $ ScoreDice#m_dice.[0]==m_dicecxx . . $ ScoreDice#m_dice.[1]) && (m_dicecxx . . $ ScoreDice#m_dice.[1]==m_dicecxx . . $ ScoreDice#m_dice.[2]) && \
251 (m_dicecxx . . $ ScoreDice#m_dice.[1]==m_dicecxx . . $ ScoreDice#m_dice.[3]) && (m_dicecxx . . $ ScoreDice#m_dice.[1]==m_dicecxx . . $ ScoreDice#m_dice.[4]))
252 return true;
253 return false;
254 }