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.
xxxAKQJT | 98765432 | cdhsrrrr | sspppppp |
---|---|---|---|
xxxbbbbb | bbbbbbbb | cdhsrrrr | sspppppp |
Where
Key | Definition |
---|---|
p | Prime number of rank |
s | Suit of card (clubs=00, diamonds=01, hearts=10, spades=11) |
r | Rank of card |
cdhs | bit turned on depending on suit of card (spades=0001,…,clubs=1000) |
b | bit turned on depending on rank of card |
As an example, the Five of Hearts would be represented as
xxxAKQJT | 98765432 | cdhsrrrr | sspppppp | |
---|---|---|---|---|
00000000 | 00001000 | 00100011 | 01000111 | = 0x00082347 = 533319 |
More information about the card is presented in a table below
2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | J | Q | K | A | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Ranks | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
Primes | 2 | 3 | 5 | 7 | 11 | 13 | 17 | 19 | 23 | 29 | 31 | 37 | 41 |
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