1 /*
2  *  Copyright 2006 Loic Dachary <loic@dachary.org>
3  *
4  * This program gives you software freedom; you can copy, convey,
5  * propagate, redistribute and/or modify this program under the terms of
6  * the GNU General Public License (GPL) as published by the Free Software
7  * Foundation (FSF), either version 3 of the License, or (at your option)
8  * any later version of the GPL published by the FSF.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program in a file in the toplevel directory called "GPLv3".
17  * If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif /* HAVE_CONFIG_H */
23 
24 #include <assert.h>
25 
26 #include <poker_defs.h>
27 #include <enumdefs.h>
28 
29 static int verbose = 1;
30 
Strings2CardMask(int strings_count,char * strings[])31 static CardMask Strings2CardMask(int strings_count, char* strings[])
32 {
33   CardMask cards;
34   CardMask dead;
35 
36   CardMask_RESET(cards);
37   CardMask_RESET(dead);
38 
39   int card;
40   int i;
41   for(i = 0; i < strings_count; i++) {
42     card = -1;
43     assert(Deck_stringToCard(strings[i], &card) != 0);
44     assert(StdDeck_CardMask_CARD_IS_SET(dead, card) == 0);
45     StdDeck_CardMask_SET(cards, card);
46   }
47 
48   return cards;
49 }
50 
main(int argc,char * argv[])51 int main(int argc, char* argv[]) {
52   enum_game_t game = game_razz;
53   {
54     enum_result_t result;
55     StdDeck_CardMask board;
56     StdDeck_CardMask dead;
57     StdDeck_CardMask pockets[2];
58     char* hand0[] = { "Ad", "2d", "3d", "4d", "5d", "Tc", "Th" };
59     //char* hand1[] = { "Ac", "2c", "3c", "4c", "5c", "Tc", "Th" };
60     char* hand1[] = { "4d", "4c", "8d", "8c", "9d", "9c", "9h" };
61 
62     enumResultClear(&result);
63     CardMask_RESET(board);
64     CardMask_RESET(dead);
65     pockets[0] = Strings2CardMask(7, hand0);
66     pockets[1] = Strings2CardMask(7, hand1);
67 
68     assert(enumExhaustive(game, pockets, board, dead, 2, 0 /* nboard */,
69                           0 /* orderflag */, &result) == 0);
70 
71     if(verbose) enumResultPrint(&result, pockets, board);
72 
73     assert(result.ev[0] == 1.0);
74     assert(result.ev[1] == 0.0);
75   }
76 
77   {
78     /* http://shipitfish.livejournal.com/59671.html
79 
80         If after removing straights and flushes, if hand X beats hand
81         Y under normal poker rules, the hand Y beats hand X under
82         razz.
83 
84         There should *never* be a case where one hand wins over
85         another in both normal poker rules and razz (after removing
86         straights and flushes).
87 
88         Therefore, 6s full of 5s loses 4s full of 8s in razz and
89         likewise by the same logic 6s and 5s beat 4s and 8s in razz.
90 
91         4s and 8s should definately *NOT* beat 6s and 5s in both
92         7-card stud and razz. If one hand wins in 7-card stud, the
93         other hand wins in razz. It is that simple.
94 
95      */
96 
97     enum_result_t result;
98     StdDeck_CardMask board;
99     StdDeck_CardMask dead;
100     StdDeck_CardMask pockets[2];
101     char* hand0[] = { "5d", "5c", "6d", "6c", "7d", "7c", "7h" };
102     char* hand1[] = { "4d", "4c", "8d", "8c", "9d", "9c", "9h" };
103 
104     enumResultClear(&result);
105     CardMask_RESET(board);
106     CardMask_RESET(dead);
107     pockets[0] = Strings2CardMask(7, hand0);
108     pockets[1] = Strings2CardMask(7, hand1);
109 
110     assert(enumExhaustive(game, pockets, board, dead, 2, 0 /* nboard */,
111                           0 /* orderflag */, &result) == 0);
112 
113     if(verbose) enumResultPrint(&result, pockets, board);
114 
115     assert(result.ev[0] == 1.0);
116     assert(result.ev[1] == 0.0);
117   }
118 
119   return 0;
120 }
121