Virtuelle Zockhalle 0.05 beta
|
00001 /* -*- coding: utf-8 -*- */ 00002 /*********************************************************************** 00003 * 00004 * $Id: cardreel.h,v 1.1 2010/12/21 21:38:31 elias Exp elias $ 00005 * Diese Datei gehört zur Virtuellen Zockhalle 00006 * 00007 * Virtuelle Zockhalle 00008 * (c) 2010 Elias Schwerdtfeger 00009 * http://www.tamagothi.de/ 00010 * 00011 * Dieses Programm ist freie Software, lizenziert unter den sinngemäß 00012 * anzuwendenden Bedingungen meiner Lizenz für freie Musik, 00013 * http://www.tamagothi.de/alben/lizenz.html 00014 * 00015 ***********************************************************************/ 00016 00017 #ifndef _CARDREEL_H 00018 #define _CARDREEL_H 00019 00025 #include "elements.h" 00026 00027 00028 00032 #define _CARD_SUIT_BITS (3) 00033 00036 #define _CARD_VALUE_BITS (4) 00037 00043 typedef unsigned short int card_t; 00044 00048 enum card_suit 00049 { 00056 SUIT_INVALID, 00058 SUIT_DIAMONDS, 00060 SUIT_HEARTS, 00062 SUIT_SPADES, 00064 SUIT_CLUBS, 00069 SUIT_JOKER 00070 }; 00071 00075 enum card_value 00076 { 00083 VAL_INVALID, 00085 VAL_ACE, 00087 VAL_2, 00089 VAL_3, 00091 VAL_4, 00093 VAL_5, 00095 VAL_6, 00097 VAL_7, 00099 VAL_8, 00101 VAL_9, 00103 VAL_10, 00105 VAL_JACK, 00107 VAL_QUEEN, 00109 VAL_KING, 00114 VAL_JOKER 00115 }; 00116 00123 #define _mkcard(SUIT, VALUE) \ 00124 (((SUIT) & ((1 << _CARD_SUIT_BITS) - 1)) | ((VALUE) << _CARD_SUIT_BITS)) 00125 00128 #define CARD_INVALID \ 00129 _mkcard (SUIT_INVALID, VAL_INVALID) 00130 00133 #define CARD_JOKER \ 00134 _mkcard (SUIT_JOKER, VAL_JOKER) 00135 00140 #define card_suit(CARD) \ 00141 ((enum card_suit) ((CARD) & ((1 << _CARD_SUIT_BITS) - 1))) 00142 00147 #define card_value(CARD) \ 00148 ((enum card_value) ((CARD) >> _CARD_SUIT_BITS)) 00149 00154 #define card_is_joker(CARD) \ 00155 ((CARD) == CARD_JOKER) 00156 00162 #define card_is_valid(CARD) \ 00163 (card_suit (CARD) != SUIT_INVALID && card_value (CARD) != VAL_INVALID) 00164 00170 #define card_is_invalid(CARD) \ 00171 (!card_is_valid ((CARD))) 00172 00176 enum pokerhand 00177 { 00179 PHND_NO_HAND, 00181 PHND_ONE_PAIR, 00183 PHND_TWO_PAIRS, 00185 PHND_THREE_OF_A_KIND, 00187 PHND_STRAIGHT, 00189 PHND_FLUSH, 00191 PHND_FULL_HOUSE, 00193 PHND_FOUR_OF_A_KIND, 00195 PHND_STRAIGHT_FLUSH, 00197 PHND_ROYAL_FLUSH, 00202 PHND_FIVE_OF_A_KIND 00203 }; 00204 00205 00206 00213 struct poker_result 00214 { 00216 enum pokerhand hand; 00240 int hold[5]; 00242 int draw_hold; 00249 enum card_value pair_1_value; 00255 enum card_value pair_2_value; 00262 enum card_value value; 00268 enum card_suit suit; 00269 }; 00270 00281 void cards_init (unsigned njokers); 00285 void cards_shuffle (void); 00292 card_t cards_draw (void); 00306 void cards_peek (unsigned n, card_t *peek_ar); 00314 int get_poker_combination (const card_t c[5], struct poker_result *r); 00321 const char *get_card_suit_name (card_t c); 00328 const char *get_card_value_name (card_t c); 00348 const char *get_card_name (card_t c, char *buf, size_t bufsz); 00355 const char *get_hand_name (enum pokerhand hand); 00356 00357 #endif /* _CARDREEL_H */