summaryrefslogtreecommitdiff
authorcniehaus <cniehaus>2003-08-12 19:06:14 (UTC)
committer cniehaus <cniehaus>2003-08-12 19:06:14 (UTC)
commitdb952faa29fa56602b061ef4faff61cc57f71243 (patch) (unidiff)
tree9b4d36895e0e9a07ff6c66e17c1bb9e0bf9daca0
parent713725e85c03c3bbbc0358301ed84241c6d0dd5b (diff)
downloadopie-db952faa29fa56602b061ef4faff61cc57f71243.zip
opie-db952faa29fa56602b061ef4faff61cc57f71243.tar.gz
opie-db952faa29fa56602b061ef4faff61cc57f71243.tar.bz2
ok, now OYatzee checks for what the user got (Full House and such)
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/games/oyatzee/oyatzee.cpp149
-rw-r--r--noncore/games/oyatzee/oyatzee.h19
2 files changed, 165 insertions, 3 deletions
diff --git a/noncore/games/oyatzee/oyatzee.cpp b/noncore/games/oyatzee/oyatzee.cpp
index 85d9616..5c4d1f7 100644
--- a/noncore/games/oyatzee/oyatzee.cpp
+++ b/noncore/games/oyatzee/oyatzee.cpp
@@ -59,5 +59,8 @@ void OYatzee::detectPosibilities()
59{ 59{
60 posibilities.clear();
61 qDebug( "running detectPosibilities()" );
62
60 Dice *d = dw->diceList.first(); 63 Dice *d = dw->diceList.first();
61 64
62 QValueList<int> numbers; 65 QValueListInt numbers;
63 66
@@ -67,2 +70,142 @@ void OYatzee::detectPosibilities()
67 } 70 }
71
72 //the 6 numbers
73 QValueListInt::Iterator it;
74
75 for ( int i = 1 ; i < 7 ; ++i ) // check for 1-->6
76 {
77 bool cont = false;
78 it = numbers.begin();
79 for ( ; it != numbers.end() ; ++it )
80 {
81 if ( cont )
82 continue;
83
84 if ( numbers.find( i ) != numbers.end() )
85 {
86 posibilities.append( i );
87 cont = true;
88 }
89 }
90 }
91
92
93 //3er, 4er, Yatzee
94 it = numbers.begin();
95 int count;
96 int temp;
97 int countFH = 0; //for the full-house-check
98
99 for ( int i = 1 ; i < 7 ; ++i ) // check for 1-->6 at least 3 times
100 {
101 count = 0;
102 temp = 0;
103 it = numbers.begin();
104 for ( ; it != numbers.end() ; ++it )
105 {
106 if ( *it == i )
107 {
108 count++;
109 temp++;
110 }
111 if ( temp == 2 )
112 countFH = temp;
113 }
114
115 if ( count >= 3 )
116 {
117 posibilities.append( 7 );
118
119 //now we check if it is a full house
120 if ( count == 3 && countFH == 2 ) //aka Full House
121 posibilities.append( 9 );
122 }
123 if ( count >= 4 )
124 posibilities.append( 8 );
125 if ( count == 5 ) //Yatzee
126 posibilities.append( 12 );
127 }
128
129 //S-Straight
130 if ( numbers.find( 3 ) != numbers.end() && numbers.find( 4 ) != numbers.end() )
131 {
132 bool isLong = false;
133 bool isShort = true;
134 //L-Straight
135 if ( numbers.find( 2 ) != numbers.end() && numbers.find( 5 ) != numbers.end() )
136 {
137 isShort = true;
138
139 //12345 or 23456
140 if ( numbers.find( 1 ) != numbers.end() || numbers.find( 6) != numbers.end() )
141 isLong = true;
142 }
143 //1234
144 if ( numbers.find( 1 ) != numbers.end() && numbers.find( 2 ) != numbers.end() )
145 isShort = true;
146 //3456
147 if ( numbers.find( 5 ) != numbers.end() && numbers.find( 6 ) != numbers.end() )
148 isShort = true;
149
150 if ( isShort )
151 posibilities.append( 10 );
152 if ( isLong )
153 posibilities.append( 11 );
154 }
155
156 posibilities.append( 13 ); //Chance, well, this is allways possible
157
158 displayPossibilites();
159}
160
161void OYatzee::displayPossibilites()
162{
163 qDebug( "running displayPossibilites(), %d item", posibilities.count() );
164
165 for ( QValueListInt::Iterator it = posibilities.begin() ; it != posibilities.end(); ++it )
166 {
167 qDebug( QString::number( *it ) );
168 switch ( *it )
169 {
170 case Ones:
171 qDebug( "1er" );
172 break;
173 case Twos:
174 qDebug( "2er" );
175 break;
176 case Threes:
177 qDebug( "3er" );
178 break;
179 case Fours:
180 qDebug( "4er" );
181 break;
182 case Fives:
183 qDebug( "5er" );
184 break;
185 case Sixes:
186 qDebug( "6er" );
187 break;
188 case ThreeOfAKind:
189 qDebug( "3oaK" );
190 break;
191 case FourOfAKind:
192 qDebug( "4oaK" );
193 break;
194 case FullHouse:
195 qDebug( "Full House" );
196 break;
197 case SStraight:
198 qDebug( "Short S" );
199 break;
200 case LStraight:
201 qDebug( "Long S" );
202 break;
203 case Yatzee:
204 qDebug( "Yatzee!" );
205 break;
206 case Chance:
207 qDebug( "Chance" );
208 break;
209 }
210 }
68} 211}
@@ -89,3 +232,4 @@ void OYatzee::slotRollDices()
89 { 232 {
90 d->roll(); 233 if ( !d->isSelected )
234 d->roll();
91 } 235 }
@@ -205,3 +349,2 @@ DiceWidget::DiceWidget( QWidget *parent , const char *name ) : QWidget( parent
205 { 349 {
206 d->roll();
207 hbox->addWidget( d ); 350 hbox->addWidget( d );
diff --git a/noncore/games/oyatzee/oyatzee.h b/noncore/games/oyatzee/oyatzee.h
index 01ab36d..65a18fc 100644
--- a/noncore/games/oyatzee/oyatzee.h
+++ b/noncore/games/oyatzee/oyatzee.h
@@ -16,2 +16,3 @@ class DiceWidget;
16typedef QList<Dice> dicesList; 16typedef QList<Dice> dicesList;
17typedef QValueList<int> QValueListInt;
17 18
@@ -27,2 +28,3 @@ class OYatzee : public QMainWindow {
27 28
29 QValueListInt posibilities;
28 30
@@ -30,2 +32,17 @@ class OYatzee : public QMainWindow {
30 void setRoundsNumber( const int num ); 32 void setRoundsNumber( const int num );
33
34 enum {
35 Ones=1,
36 Twos = 2,
37 Threes = 3,
38 Fours = 4,
39 Fives = 5,
40 Sixes = 6,
41 ThreeOfAKind = 7, //12444
42 FourOfAKind = 8, //14444
43 FullHouse = 9, //22555
44 SStraight = 10, //13456
45 LStraight = 11, //12345
46 Yatzee = 12, //55555
47 Chance = 13};
31 48
@@ -40,2 +57,4 @@ class OYatzee : public QMainWindow {
40 void detectPosibilities(); 57 void detectPosibilities();
58 void displayPossibilites();
59
41}; 60};