Skip to contents

Return a deck of 52 playing cards represented as integers from 0 to 51.

Usage

new_deck()

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):

CDHS
20123
34567
4891011
512131415
616171819
720212223
824252627
928293031
T32333435
J36373839
Q40414243
K44454647
A48495051

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