1 /*
2 * Copyright 2006 Michael Maurer <mjmaurer@yahoo.com>,
3 * Brian Goetz <brian@quiotix.com>,
4 * Loic Dachary <loic@dachary.org>,
5 * Tim Showalter <tjs@psaux.com>
6 *
7 * This program gives you software freedom; you can copy, convey,
8 * propagate, redistribute and/or modify this program under the terms of
9 * the GNU General Public License (GPL) as published by the Free Software
10 * Foundation (FSF), either version 3 of the License, or (at your option)
11 * any later version of the GPL published by the FSF.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program in a file in the toplevel directory called "GPLv3".
20 * If not, see <http://www.gnu.org/licenses/>.
21 */
22 #include <stdio.h>
23
24 #include "poker_defs.h"
25 #include "deck_astud.h"
26 #include "rules_astud.h"
27
28 const char *AStudRules_handTypeNames[AStudRules_HandType_LAST+1] = {
29 "NoPair",
30 "OnePair",
31 "TwoPair",
32 "Trips",
33 "Straight",
34 "FlHouse",
35 "Flush",
36 "Quads",
37 "StFlush"
38 };
39
40 const char *AStudRules_handTypeNamesPadded[AStudRules_HandType_LAST+1] = {
41 "NoPair ",
42 "OnePair ",
43 "TwoPair ",
44 "Trips ",
45 "Straight",
46 "FlHouse ",
47 "Flush ",
48 "Quads ",
49 "StFlush "
50 };
51
52 int AStudRules_nSigCards[AStudRules_HandType_LAST+1] = {
53 5,
54 4,
55 3,
56 3,
57 1,
58 2,
59 5,
60 2,
61 1
62 };
63
64
65 int
AStudRules_HandVal_toString(HandVal handval,char * outString)66 AStudRules_HandVal_toString(HandVal handval, char *outString) {
67 char *p = outString;
68 int htype = HandVal_HANDTYPE(handval);
69
70 p += sprintf(outString, "%s (", AStudRules_handTypeNames[htype]);
71 if (AStudRules_nSigCards[htype] >= 1)
72 p += sprintf(p, "%c",
73 AStudDeck_rankChars[HandVal_TOP_CARD(handval)]);
74 if (AStudRules_nSigCards[htype] >= 2)
75 p += sprintf(p, " %c",
76 AStudDeck_rankChars[HandVal_SECOND_CARD(handval)]);
77 if (AStudRules_nSigCards[htype] >= 3)
78 p += sprintf(p, " %c",
79 AStudDeck_rankChars[HandVal_THIRD_CARD(handval)]);
80 if (AStudRules_nSigCards[htype] >= 4)
81 p += sprintf(p, " %c",
82 AStudDeck_rankChars[HandVal_FOURTH_CARD(handval)]);
83 if (AStudRules_nSigCards[htype] >= 5)
84 p += sprintf(p, " %c",
85 AStudDeck_rankChars[HandVal_FIFTH_CARD(handval)]);
86 p += sprintf(p, ")");
87
88 return p - outString;
89 }
90
91 int
AStudRules_HandVal_print(HandVal handval)92 AStudRules_HandVal_print(HandVal handval) {
93 char buf[80];
94 int n;
95
96 n = AStudRules_HandVal_toString(handval, buf);
97 printf("%s", buf);
98 return n;
99 }
100
101