#ifndef WH_CARDS_H_35f23eab_ #define WH_CARDS_H_35f23eab_ #include #define CARD_SUIT(c) ((c)/13) #define CARD_SUIT_C 0 #define CARD_SUIT_D 1 #define CARD_SUIT_H 2 #define CARD_SUIT_S 3 #define CARD_SUIT_R 4 #define CARD_SUIT_B 5 #define CARD_NSUIT 6 #define CARD_RANK(c) ((c)%13) #define CARD_RANK_A 0 #define CARD_RANK_2 1 #define CARD_RANK_3 2 #define CARD_RANK_4 3 #define CARD_RANK_5 4 #define CARD_RANK_6 5 #define CARD_RANK_7 6 #define CARD_RANK_8 7 #define CARD_RANK_9 8 #define CARD_RANK_10 9 #define CARD_RANK_T 9 #define CARD_RANK_J 10 #define CARD_RANK_Q 11 #define CARD_RANK_K 12 #define CARD_NRANK 13 #define CARD_DECK (CARD_NSUIT*CARD_NRANK) #define CARD_URED CARD_DECK #define CARD_UBLACK (CARD_DECK+1) #define CARD_JOKER (CARD_DECK+2) #define CARD_XDECK (CARD_DECK+3) #define CARD_MAKE(s,r) (((s)*13)+(r)) #define CARD_MAX_XSIZE 255 #define CARD_MAX_YSIZE 255 #define CARD_MAX_NCOL 255 #define CARD_MAX_NBACKS 255 typedef struct deck DECK; /* * face_c points to CARD_XDECK*ysize*xsize unsigned chars holding the * card face pixels; back_c to nbacks*ysize*xsize unsigned chars * holding the card back pixels. In each case, they are arranged as * if for an array dimensioned [CARD_XDECK or nbacks][ysize][xsize]. * * face_bw and back_bw are similar, but instead of xsize each row size * is ceil(xsize/8), or, in C terms, (xsize+7)>>3; bits are arranged * here with the leftmost bit of a row in the 0x80 bit of the [0] * byte, the second-leftmost in the 0x40 bit, etc. If xsize is not a * multiple of 8, the low 8-(xsize&7) bits of the last byte are * meaningless and should be ignored. * * As a convenience, CARD_BW_INDEX and CARD_C_INDEX compute the offset * into the _bw or _c arrays, given a DECK pointer (for the sizes) and * the index into the card or back array. * * Backs are indexed from 0 upwards, with the ordering being the * ordering in the deck file. Cards are index from 0 through * CARD_XDECK-1, with the order being * - 0 through CARD_DECK-1: the subscript is the CARD_VALUE() * return value for suit from CARD_MINSUIT thorugh * CARD_MAXCSUIT and rank from CARD_MINRANK through * CARD_MAXRANK. * - the remaining subscripts are the CARD_* values above * CARD_DECK-1 (CARD_URED, CARD_UBLACK, and CARD_JOKER). */ struct deck { unsigned int xsize; unsigned int ysize; unsigned int ncol; unsigned int nbacks; unsigned short int (*cmap)[3]; unsigned char *face_c; unsigned char *back_c; unsigned char *face_bw; unsigned char *back_bw; } ; #define CARD_BW_INDEX(deck,inx) ((deck)->ysize*(((deck)->xsize+7)>>3)*(inx)) #define CARD_C_INDEX(deck,inx) ((deck)->ysize*(deck)->xsize*(inx)) extern void card_allocdeck(DECK *); extern void card_freedeck(DECK *); extern const char *card_loaddeck(FILE *, DECK *); extern const char *card_savedeck(FILE *, const DECK *); #endif