Return a deck of 52 playing cards represented as integers from 0 to 51.
Details
Following the example of PH Evaluator,
integers are used to represent a card id
, with the two least significant bits representing
the 4 suits (0-3), and the rest representing the 13 ranks (0-12):
C | D | H | S | |
2 | 0 | 1 | 2 | 3 |
3 | 4 | 5 | 6 | 7 |
4 | 8 | 9 | 10 | 11 |
5 | 12 | 13 | 14 | 15 |
6 | 16 | 17 | 18 | 19 |
7 | 20 | 21 | 22 | 23 |
8 | 24 | 25 | 26 | 27 |
9 | 28 | 29 | 30 | 31 |
T | 32 | 33 | 34 | 35 |
J | 36 | 37 | 38 | 39 |
Q | 40 | 41 | 42 | 43 |
K | 44 | 45 | 46 | 47 |
A | 48 | 49 | 50 | 51 |
For each card, the rank is id %/% 4
, and the suit is id %% 4
.
Examples
new_deck()
#> [1] 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
#> [26] 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
#> [51] 50 51
new_deck() %/% 4
#> [1] 0 0 0 0 1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4 5 5 5 5 6
#> [26] 6 6 6 7 7 7 7 8 8 8 8 9 9 9 9 10 10 10 10 11 11 11 11 12 12
#> [51] 12 12
new_deck() %% 4
#> [1] 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3 0 1
#> [39] 2 3 0 1 2 3 0 1 2 3 0 1 2 3