1 /* $Id: usedecks.c 5146 2008-12-04 03:11:22Z bkuhn $
2 Example showing how to use different decks and evaluation rule sets.
3
4 * Copyright (C) Apr 2002, Michael Maurer.
5 *
6 * This program gives you software freedom; you can copy, convey,
7 * propagate, redistribute and/or modify this program under the terms of
8 * the GNU General Public License (GPL) as published by the Free Software
9 * Foundation (FSF), either version 3 of the License, or (at your option)
10 * any later version of the GPL published by the FSF.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program in a file in the toplevel directory called "GPLv3".
19 * If not, see <http://www.gnu.org/licenses/>.
20 */
21
22 #include <stdio.h>
23 #include <string.h>
24 #include <stdlib.h>
25
26 #define TEST_STD
27 #define TEST_JOKER
28 #define TEST_ASTUD
29 #define TEST_OMAHA8
30
31 #include "poker_defs.h"
32
33 #ifdef TEST_STD
34 #include "inlines/eval.h"
35 #include "inlines/eval_low.h"
36 #include "inlines/eval_low8.h"
37 #include "deck_std.h"
38 #include "rules_std.h"
39
40 int
testStdDeck(const char * handstr)41 testStdDeck(const char *handstr) {
42 StdDeck_CardMask cards;
43 int ncards = 0;
44 int c = 0;
45 HandVal hival;
46 LowHandVal loval;
47 LowHandVal lo8val;
48 char str[80];
49 char *p;
50
51 printf("\nStandard Deck: %s\n", handstr);
52 StdDeck_CardMask_RESET(cards);
53 strcpy(str, handstr);
54 p = strtok(str, " ");
55 do {
56 if (DstringToCard(StdDeck, p, &c) == 0)
57 goto error;
58 if (!StdDeck_CardMask_CARD_IS_SET(cards, c)) {
59 StdDeck_CardMask_SET(cards, c);
60 ++ncards;
61 };
62 } while ((p = strtok(NULL, " ")) != NULL);
63
64 hival = StdDeck_StdRules_EVAL_N(cards, ncards);
65 printf("%s: %d: ", DmaskString(StdDeck, cards), hival);
66 StdRules_HandVal_print(hival);
67 printf("\n");
68
69 loval = StdDeck_Lowball_EVAL(cards, ncards);
70 printf("%s (lowball): %d: ", DmaskString(StdDeck, cards), loval);
71 LowHandVal_print(loval);
72 printf("\n");
73
74 lo8val = StdDeck_Lowball8_EVAL(cards, ncards);
75 printf("%s (low8): %d: ", DmaskString(StdDeck, cards), lo8val);
76 LowHandVal_print(lo8val);
77 printf("\n");
78
79 return 0;
80
81 error:
82 printf("ERROR\n");
83 return 1;
84 }
85
86 #endif
87
88 #ifdef TEST_JOKER
89 #include "inlines/eval_joker.h"
90 #include "inlines/eval_joker_low.h"
91 #include "inlines/eval_joker_low8.h"
92 #include "deck_joker.h"
93 #include "rules_joker.h"
94
95 int
testJokerDeck(const char * handstr)96 testJokerDeck(const char *handstr) {
97 JokerDeck_CardMask cards;
98 int ncards = 0;
99 int c = 0;
100 HandVal hival;
101 LowHandVal loval;
102 LowHandVal lo8val;
103 char str[80];
104 char *p;
105
106 printf("\nJoker Deck: %s\n", handstr);
107 JokerDeck_CardMask_RESET(cards);
108 strcpy(str, handstr);
109 p = strtok(str, " ");
110 do {
111 if (JokerDeck.stringToCard(p, &c) == 0)
112 goto error;
113 if (!JokerDeck_CardMask_CARD_IS_SET(cards, c)) {
114 JokerDeck_CardMask_SET(cards, c);
115 ++ncards;
116 };
117 } while ((p = strtok(NULL, " ")) != NULL);
118
119 hival = JokerDeck_JokerRules_EVAL_N(cards, ncards);
120 printf("%s: %d: ", DmaskString(JokerDeck, cards), hival);
121 JokerRules_HandVal_print(hival);
122 printf("\n");
123
124 loval = JokerDeck_Lowball_EVAL(cards, ncards);
125 printf("%s (lowball): %d: ", DmaskString(JokerDeck, cards), loval);
126 LowHandVal_print(loval);
127 printf("\n");
128
129 lo8val = JokerDeck_Lowball8_EVAL(cards, ncards);
130 printf("%s (low8): %d: ", DmaskString(JokerDeck, cards), lo8val);
131 LowHandVal_print(lo8val);
132 printf("\n");
133
134 return 0;
135
136 error:
137 printf("ERROR\n");
138 return 1;
139 }
140 #endif
141
142 #ifdef TEST_ASTUD
143
144 #include "deck_astud.h"
145 #include "rules_astud.h"
146 #include "inlines/eval_astud.h" /* must come after above!? */
147
148 int
testAStudDeck(const char * handstr)149 testAStudDeck(const char *handstr) {
150 AStudDeck_CardMask cards;
151 int ncards = 0;
152 int c = 0;
153 HandVal hival;
154 char str[80];
155 char *p;
156
157 printf("\nAsian Stud Deck: %s\n", handstr);
158 AStudDeck_CardMask_RESET(cards);
159 strcpy(str, handstr);
160 p = strtok(str, " ");
161 do {
162 if (AStudDeck.stringToCard(p, &c) == 0)
163 goto error;
164 if (!AStudDeck_CardMask_CARD_IS_SET(cards, c)) {
165 AStudDeck_CardMask_SET(cards, c);
166 ++ncards;
167 };
168 } while ((p = strtok(NULL, " ")) != NULL);
169
170 hival = AStudDeck_AStudRules_EVAL_N(cards, ncards);
171 printf("%s: %d: ", DmaskString(AStudDeck, cards), hival);
172 AStudRules_HandVal_print(hival);
173 printf("\n");
174
175 return 0;
176
177 error:
178 printf("ERROR\n");
179 return 1;
180 }
181 #endif
182
183 #ifdef TEST_OMAHA8
184 #include "inlines/eval_omaha.h"
185 #include "deck_std.h"
186 #include "rules_std.h"
187
188 int
testOmaha8(const char * holestr,const char * boardstr)189 testOmaha8(const char *holestr, const char *boardstr) {
190 StdDeck_CardMask hole;
191 StdDeck_CardMask board;
192 int nhole;
193 int nboard;
194 int c;
195 int ret;
196 HandVal hival = 0;
197 LowHandVal loval = 0;
198 char str[80], hstr[80], bstr[80];
199 char *p;
200
201 printf("\nOmaha Hi/Lo8: %s | %s\n", holestr, boardstr);
202
203 nhole = 0;
204 StdDeck_CardMask_RESET(hole);
205 strcpy(str, holestr);
206 p = strtok(str, " ");
207 do {
208 if (DstringToCard(StdDeck, p, &c) == 0)
209 goto error;
210 if (!StdDeck_CardMask_CARD_IS_SET(hole, c)) {
211 StdDeck_CardMask_SET(hole, c);
212 ++nhole;
213 };
214 } while ((p = strtok(NULL, " ")) != NULL);
215
216 nboard = 0;
217 StdDeck_CardMask_RESET(board);
218 strcpy(str, boardstr);
219 p = strtok(str, " ");
220 do {
221 if (DstringToCard(StdDeck, p, &c) == 0)
222 goto error;
223 if (!StdDeck_CardMask_CARD_IS_SET(board, c)) {
224 StdDeck_CardMask_SET(board, c);
225 ++nboard;
226 };
227 } while ((p = strtok(NULL, " ")) != NULL);
228
229 ret = StdDeck_OmahaHiLow8_EVAL(hole, board, &hival, &loval);
230 strcpy(hstr, DmaskString(StdDeck, hole));
231 strcpy(bstr, DmaskString(StdDeck, board));
232 printf("%s | %s:\n", hstr, bstr);
233 if (ret == 0) {
234 printf(" HI %d: ", hival);
235 StdRules_HandVal_print(hival);
236 printf("\n LO %d: ", loval);
237 LowHandVal_print(loval);
238 printf("\n");
239 } else {
240 printf("ERROR %d\n", ret);
241 }
242 return 0;
243
244 error:
245 printf("ERROR\n");
246 return 1;
247 }
248
249 #endif
250
251 int
main(int argc,char ** argv)252 main(int argc, char **argv) {
253 #ifdef TEST_STD
254 printf("\n================= STANDARD DECK ===================\n");
255 testStdDeck("Ac Ad Kc 9d 8s");
256 testStdDeck("2c 2d Kc 9d 8s");
257 testStdDeck("Ac 7d 8c 9h Ts");
258 testStdDeck("Ac 2s 3d 4h 9c");
259 testStdDeck("4h 5h 6d 7c 8d");
260 testStdDeck("Ac 2s 3d 4h 5s");
261 testStdDeck("Ac 2s 3d 4h 7s 3h 4d");
262 testStdDeck("2s 3d 4h 5s 6d 3h 4d");
263
264 testStdDeck("Ks Kh Kd 7s 7h 2d 3c");
265 testStdDeck("Ks Kh Kd 7s 7h 3h 3c"); /* low eval is wrong */
266 testStdDeck("Ks Kh 7s 7h 7d 3s 3h"); /* low eval is wrong */
267 testStdDeck("Ks Kh 7s 7h 3s 3h 3d"); /* low eval is wrong */
268 testStdDeck("Ks Kh 7s 7h 3s 3h 2c");
269 testStdDeck("Ks Kh Kd Kc 4s 4h 2c");
270 testStdDeck("Ks Kh Kd Kc 4s 4h 4d");
271 testStdDeck("Ks Kh Kd Kc 4s 4h 7c");
272 testStdDeck("4s 4h 4d 4c Ks Kh 2c");
273 testStdDeck("4s 4h 4d 4c Ks Kh 7c");
274 testStdDeck("4s 4h 4d 4c Ks Kh Kd"); /* low eval is wrong */
275 #endif
276
277 #ifdef TEST_JOKER
278 printf("\n================= JOKER DECK ===================\n");
279 testJokerDeck("Ac Ad Kc 9d 8s");
280 testJokerDeck("2c 2d Kc 9d 8s");
281 testJokerDeck("Ac 7d 8c 9h Ts");
282 testJokerDeck("Ac 2s 3d 4h 9c");
283 testJokerDeck("4h 5h 6d 7c 8d");
284 testJokerDeck("Ac 2s 3d 4h 5s");
285 testJokerDeck("xx 2s 3s 4c 5c");
286 testJokerDeck("xx Ac 3c 4c 7c");
287 testJokerDeck("Kc Ac 3c 4c 7c");
288 testJokerDeck("xx Jc 3c 4c 7c");
289 testJokerDeck("xx Ac As 2d 2h");
290 testJokerDeck("xx Ac As Ad Ah");
291 testJokerDeck("Ks Kh Kd As Ah");
292 #endif
293
294 #ifdef TEST_ASTUD
295 printf("\n================= ASIAN STUD DECK ===================\n");
296 testAStudDeck("Ac Ad Kc 9d 8s");
297 testAStudDeck("Ac 7d 8c 9h Ts");
298 testAStudDeck("Ac Qc Tc 8c 7c");
299 testAStudDeck("Ac Ad As Th Td");
300 #endif
301
302 #ifdef TEST_OMAHA8
303 printf("\n================= OMAHA HI/LOW8 ===================\n");
304 testOmaha8("Ac 2c Jd Th", "As Kc Qc 8d 2d");
305 testOmaha8("Ac 2c Jd 8h", "As Kc Qc Jh Td");
306 testOmaha8("3c 2c Jd 8h", "As Kc Qc Jh Td");
307 testOmaha8("Qs 4h 4d 4s", "As Ks 8h 9d 2s");
308 testOmaha8("Qs 4h 4d Qd", "As Ks 8s 9s 2s");
309 testOmaha8("Td Tc Ad 9c", "As Ts 8s 8h 4d");
310 testOmaha8("Td 8c Ad 9c", "As Ts 8s 8h 4d");
311 testOmaha8("Ah 2h 3h 5h", "As Ac 8s 8h 4d");
312 testOmaha8("Ah 2h 3h 4h", "As Ac 8s 8h 4d");
313 testOmaha8("8c Jc Jd Th", "As Kc Qc 8d 2d");
314 testOmaha8("Ac 2c Jd Th", "3d 5h 8d Tc Ts");
315 testOmaha8("Ac 3c 4d Th", "3d 5h 8d Tc Ts");
316 testOmaha8("Ac 3c 5d 8h", "3d 5h 8d Ad Ts");
317 testOmaha8("Ad 2d Th Td", "Ac 2c 3d 4h 5s");
318 testOmaha8("4d 5d Th Td", "Ac 2c 3d 4h 5s");
319 testOmaha8("Ad 2d Th Td", "5h 7h 8d Ac 2c");
320 #endif
321
322 return 0;
323 }
324