libcards(3)
This commit is contained in:
parent
d231f7f234
commit
e54dae0a8f
13
bin/cat
13
bin/cat
@ -1,13 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
alias dd="dd bs=1 2>/dev/null"
|
||||
|
||||
if [ -z "$1" ]; then
|
||||
dd </dev/stdin
|
||||
exit 0
|
||||
fi
|
||||
|
||||
while [ -n "$1" ]; do
|
||||
dd <"$1"
|
||||
shift 1
|
||||
done
|
16
lib/libcards.c
Normal file
16
lib/libcards.c
Normal file
@ -0,0 +1,16 @@
|
||||
#include "libcards.h"
|
||||
|
||||
int
|
||||
card_color(int card){
|
||||
|
||||
return card < CARD_HEART_A ? -1 : card_rank(card) < CARD_SUIT_CLOVER;
|
||||
}
|
||||
|
||||
int
|
||||
card_rank(int card){ return card < CARD_HEART_A ? -1 : card % 0x10; }
|
||||
|
||||
int
|
||||
card_suit(int card){
|
||||
|
||||
return card < CARD_HEART_A ? -1 : card / CARD_SUIT_HEART;
|
||||
}
|
45
lib/libcards.h
Normal file
45
lib/libcards.h
Normal file
@ -0,0 +1,45 @@
|
||||
enum{
|
||||
CARD_SUIT_HEART = 0x1,
|
||||
CARD_SUIT_TILE = 0x2,
|
||||
CARD_SUIT_CLOVER = 0x3,
|
||||
CARD_SUIT_PIKE = 0x4,
|
||||
|
||||
CARD_RANK_A = 0x00,
|
||||
CARD_RANK_2, CARD_RANK_3, CARD_RANK_4,
|
||||
CARD_RANK_5, CARD_RANK_6, CARD_RANK_7,
|
||||
CARD_RANK_8, CARD_RANK_9, CARD_RANK_10,
|
||||
CARD_RANK_J, CARD_RANK_Q, CARD_RANK_K,
|
||||
CARD_RANK_JOKER /* = 0x0D */
|
||||
|
||||
CARD_HEART_A = 0x10,
|
||||
CARD_HEART_2, CARD_HEART_3, CARD_HEART_4,
|
||||
CARD_HEART_5, CARD_HEART_6, CARD_HEART_7,
|
||||
CARD_HEART_8, CARD_HEART_9, CARD_HEART_10,
|
||||
CARD_HEART_J, CARD_HEART_Q, CARD_HEART_K,
|
||||
CARD_HEART_JOKER /* = 0x1D */,
|
||||
|
||||
CARD_TILE_A = 0x20,
|
||||
CARD_TILE_2, CARD_TILE_3, CARD_TILE_4,
|
||||
CARD_TILE_5, CARD_TILE_6, CARD_TILE_7,
|
||||
CARD_TILE_8, CARD_TILE_9, CARD_TILE_10,
|
||||
CARD_TILE_J, CARD_TILE_Q, CARD_TILE_K,
|
||||
CARD_TILE_JOKER /* = 0x2D */
|
||||
|
||||
CARD_CLOVER_A = 0x30,
|
||||
CARD_CLOVER_2, CARD_CLOVER_3, CARD_CLOVER_4,
|
||||
CARD_CLOVER_5, CARD_CLOVER_6, CARD_CLOVER_7,
|
||||
CARD_CLOVER_8, CARD_CLOVER_9, CARD_CLOVER_10,
|
||||
CARD_CLOVER_J, CARD_CLOVER_Q, CARD_CLOVER_K,
|
||||
CARD_CLOVER_JOKER /* = 0x3D */,
|
||||
|
||||
CARD_PIKE_A = 0x40,
|
||||
CARD_PIKE_2, CARD_PIKE_3, CARD_PIKE_4,
|
||||
CARD_PIKE_5, CARD_PIKE_6, CARD_PIKE_7,
|
||||
CARD_PIKE_8, CARD_PIKE_9, CARD_PIKE_10,
|
||||
CARD_PIKE_J, CARD_PIKE_Q, CARD_PIKE_K,
|
||||
CARD_PIKE_JOKER /* = 0x4D */
|
||||
}
|
||||
|
||||
int card_color(int card);
|
||||
int card_rank(int card);
|
||||
int card_suit(int card);
|
Loading…
Reference in New Issue
Block a user