Unicode card deck
Exerpt from wikipedia;
Playing Cards[1][2] Official Unicode Consortium code chart |
||||||||||||||||
0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | A | B | C | D | E | ||
U+1F0Ax | ๐ | ๐ก | ๐ข | ๐ฃ | ๐ค | ๐ฅ | ๐ฆ | ๐ง | ๐จ | ๐ฉ | ๐ช | ๐ซ | ๐ฌ | ๐ญ | ๐ฎ | |
U+1F0Bx | ๐ฑ | ๐ฒ | ๐ณ | ๐ด | ๐ต | ๐ถ | ๐ท | ๐ธ | ๐น | ๐บ | ๐ป | ๐ผ | ๐ฝ | ๐พ | ||
U+1F0Cx | ๐ | ๐ | ๐ | ๐ | ๐ | ๐ | ๐ | ๐ | ๐ | ๐ | ๐ | ๐ | ๐ | ๐ | ||
U+1F0Dx | ๐ | ๐ | ๐ | ๐ | ๐ | ๐ | ๐ | ๐ | ๐ | ๐ | ๐ | ๐ | ๐ | ๐ |
/*
* I recently wrote a short example program on how to generate
* unicode characters.
*
* I'll try to contain the whole post in the source of this file for
* the sake of keeping it short.
*/
#include <locale.h>
#include <stdio.h>
#define CLEAN(X) (((((X ^ CARD) & ~SPADES) & ~HEARTS) & ~DIAMONDS) & ~CLUBS)
enum {
CARD = 0x1f000,
SPADES = 0xa0,
HEARTS = 0xb0,
DIAMONDS = 0xc0,
CLUBS = 0xd0,
ACE = 0x1,
JACK = 0xb,
KNIGHT = 0xc,
QUEEN = 0xd,
KING = 0xe,
};
int
new_card(void) {
int rnd;
int ret = CARD;
/* replace this with whichever way you usually get a random int */
rnd = arc4random();
/* randomly select suit */
switch (abs(rnd % 4)) {
case 0:
ret |= SPADES;
break;
case 1:
ret |= HEARTS;
break;
case 2:
ret |= DIAMONDS;
break;
case 3:
ret |= CLUBS;
break;
}
/* add a random number between 1-15 to return */
ret += abs(rnd % 14) + 1;
/* if return is a knight, recursively run until it isn't */
if (CLEAN(ret) == KNIGHT)
ret = new_card();
return ret;
}
int
main(int argc, char **argv) {
setlocale(LC_ALL, "");
printf("%lc\n", new_card());
/*
* CARD = 0x1f000 == 0b11111000000000000 | (OR)
* HEARTS = 0x000b0 == 0b00000000010110000 | (OR)
* QUEEN = 0x0000d == 0b00000000000001101 | (OR)
* = 0x1f0bd == 0b11111000010111101 == U+1F0BD == ๐ฝ
*/
printf("%lc\n", CARD | HEARTS | QUEEN);
return 0;
}