Module card

Source
Expand description

§Card

A card is an integer is made up of four bytes. The high-order bytes are used to hold the rank bit pattern, whereas the low-order bytes hold the suit/rank/prime value of the card.

xxxAKQJT98765432cdhsrrrrsspppppp
xxxbbbbbbbbbbbbbcdhsrrrrsspppppp

Where

KeyDefinition
pPrime number of rank
sSuit of card (clubs=00, diamonds=01, hearts=10, spades=11)
rRank of card
cdhsbit turned on depending on suit of card (spades=0001,…,clubs=1000)
bbit turned on depending on rank of card

As an example, the Five of Hearts would be represented as

xxxAKQJT98765432cdhsrrrrsspppppp
00000000000010000010001101000111= 0x00082347 = 533319

More information about the card is presented in a table below

2345678910JQKA
Ranks0123456789101112
Primes2357111317192329313741

Functions§

create
Create the card from given rank and suit
get_primes
Extract the primes from the card
get_rank
Extract the rank value from the card
get_rank_string
Convert the card to readable rank
get_suit
Extract the suit value from the card
get_suit_string
Convert the card to readable suit
is_black
Check if the card’s current suit is black
is_clubs
Check if the card’s current suit is clubs
is_diamonds
Check if the card’s current suit is diamonds
is_hearts
Check if the card’s current suit is hearts
is_red
Check if the card’s current suit is red
is_spades
Check if the card’s current suit is spades
rank_of
Check if the card’s current suit matches the given value
to_string
Convert the card to readable string