1 /*
2 * Copyright (C) 1999-2002
3 * Michael Maurer <mjmaurer@yahoo.com>
4 * Brian Goetz <brian@quiotix.com>
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 #ifndef __EVAL_JOKER_LOW_H__
22 #define __EVAL_JOKER_LOW_H__
23
24 #include <assert.h>
25 #include "handval_low.h"
26 #include "deck_joker.h"
27 #include "inlines/eval_low.h"
28
29 /*
30 * Lowball evaluator with joker. Assumes that n_cards >= 5.
31 * Performance could be improved by expanding the standard lowball evaluator,
32 * rather than trying to manipulate the card mask so we can reuse the standard
33 * lowball evaluator. This would save a lot of bit extractions and redundant
34 * bit operations (like computing ranks.)
35 */
36
37 static inline LowHandVal
JokerDeck_Lowball_EVAL(JokerDeck_CardMask cards,int n_cards)38 JokerDeck_Lowball_EVAL(JokerDeck_CardMask cards, int n_cards) {
39 uint32 ranks, rank, ss, sh, sd, sc;
40 StdDeck_CardMask sCards;
41
42 JokerDeck_CardMask_toStd(cards, sCards);
43 if (!JokerDeck_CardMask_JOKER(cards))
44 return StdDeck_Lowball_EVAL(sCards, n_cards);
45
46 ss = JokerDeck_CardMask_SPADES(cards);
47 sc = JokerDeck_CardMask_CLUBS(cards);
48 sd = JokerDeck_CardMask_DIAMONDS(cards);
49 sh = JokerDeck_CardMask_HEARTS(cards);
50
51 ranks = sc | ss | sd | sh;
52 if (!(ranks & (1 << JokerDeck_Rank_ACE)))
53 rank = 1 << JokerDeck_Rank_ACE;
54 else
55 for (rank= (1 << JokerDeck_Rank_2);
56 rank <= (1 << JokerDeck_Rank_KING);
57 rank <<= 1)
58 if (!(ranks & rank))
59 break;
60
61 if (!(sc & rank))
62 StdDeck_CardMask_SET_CLUBS(sCards, sc | rank);
63 else if (!(sd & rank))
64 StdDeck_CardMask_SET_DIAMONDS(sCards, sc | rank);
65 else if (!(sh & rank))
66 StdDeck_CardMask_SET_HEARTS(sCards, sh | rank);
67 else if (!(ss & rank))
68 StdDeck_CardMask_SET_SPADES(sCards, ss | rank);
69
70 return StdDeck_Lowball_EVAL(sCards, n_cards);
71 }
72
73 #endif
74