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 "handval_low.h"
26
27 #define CARD_TO_RANK(c) ((c) == StdDeck_Rank_2 ? StdDeck_Rank_ACE : (c-1))
28
29 int
LowHandVal_toString(LowHandVal hv,char * outString)30 LowHandVal_toString(LowHandVal hv, char *outString) {
31 char *p = outString;
32 int htype = HandVal_HANDTYPE(hv);
33
34 if (hv == LowHandVal_NOTHING)
35 p += sprintf(outString, "NoLow");
36 else {
37 p += sprintf(outString, "%s (", StdRules_handTypeNames[htype]);
38 if (StdRules_nSigCards[htype] >= 1)
39 p += sprintf(p, "%c",
40 StdDeck_rankChars[CARD_TO_RANK(HandVal_TOP_CARD(hv))]);
41 if (StdRules_nSigCards[htype] >= 2)
42 p += sprintf(p, " %c",
43 StdDeck_rankChars[CARD_TO_RANK(HandVal_SECOND_CARD(hv))]);
44 if (StdRules_nSigCards[htype] >= 3)
45 p += sprintf(p, " %c",
46 StdDeck_rankChars[CARD_TO_RANK(HandVal_THIRD_CARD(hv))]);
47 if (StdRules_nSigCards[htype] >= 4)
48 p += sprintf(p, " %c",
49 StdDeck_rankChars[CARD_TO_RANK(HandVal_FOURTH_CARD(hv))]);
50 if (StdRules_nSigCards[htype] >= 5)
51 p += sprintf(p, " %c",
52 StdDeck_rankChars[CARD_TO_RANK(HandVal_FIFTH_CARD(hv))]);
53 p += sprintf(p, ")");
54 };
55
56 return p - outString;
57 }
58
59 int
LowHandVal_print(LowHandVal handval)60 LowHandVal_print(LowHandVal handval) {
61 char buf[80];
62 int n;
63
64 n = LowHandVal_toString(handval, buf);
65 printf("%s", buf);
66 return n;
67 }
68