Card game and simulation library and tools. Part of the OneJoker project.

Project maintained by Lee Daniel Crocker
Lee's blog is etceterology.

onejoker
CC-0: To the extent possible under law, I, Lee Daniel Crocker waive all copyright and related or neighboring rights to all creative works original to me.

Using the library in your C code

Text functions

char *ojt_card(oj_card c)

Returns a pointer to a string constant which is the 2-character common name of the card passed in by value. E.g., ojt_card(6) returns "3d".

char *ojt_rank(oj_rank r)

Returns a pointer to a string constant for the common English name (in lowercase) of the given card rank value. E.g., ojt_rank(OJR_QUEEN) returns "queen".

char *ojt_suit(oj_suit s)

Returns a pointer to a string constant for the common English name (singular, lowercase) of the given card suit value. E.g., ojt_suit(OJS_SPADE) returns "spade".

char *ojt_fullname(oj_card c, char *buf, int size)

Constructs into the given buffer the common English name of the given card. E.g, ojt_fullname(52, buf, sizeof(buf)) puts the string "ace of spades" into the given buffer (but in no case exceeding the given buffer size). Buffer size should be at least 18 characters to accommodate the longest string “seven of diamonds”.

oj_card ojt_val(char *str)

Returns the value of the card whose standard 2-character representation begins the given string (after ignoring non-alphanumeric characters). E.g., ojt_val("5h") returns (oj_card) 15. It should be pointed out that it is probably a mistake to pass a string constant to this function, since this will compile into an actual function call that is unnecessary. To make card constants, use the macros: OJ_CARD(OJR_FIVE, OJS_HEART) will reduce to a compile-time constant.

int ojt_vals(char *str, oj_card *arr, int size)

Fills the given array of card values with the cards named in the given string, returning the actual number of cards converted. E.g., ojt_vals("Ac Td 6c", arr, 10) will fill the first three elements of the array arr with the card values 49, 34, 17, and will return 3. It will never write more than size elements into the array, so if the array is smaller than the number of cards encoded in the string, the string will not be fully converted.

Next: Card list functions