@Flimshady - Sorry, I got a little mixed up on those formulas. They should be
((card mod 13) + 1) for the value and
(card div 13) for the suit.
Values:
Cards 0, 13, 26, and 39 should be 1
Cards 1, 14, 27, and 40 should be 2
Cards 2, 15, 28, and 41 should be 3
Cards 3, 16, 29, and 42 should be 4
Cards 4, 17, 30, and 43 should be 5
Cards 5, 18, 31, and 44 should be 6
Cards 6, 19, 32, and 45 should be 7
Cards 7, 20, 33, and 46 should be 8
Cards 8, 21, 34, and 47 should be 9
Cards 9, 22, 35, and 48 should be 10
Cards 10, 23, 36, and 49 should be 11
Cards 11, 24, 37, and 50 should be 12
Cards 12, 25, 38, and 51 should be 13
The 'modulus operator' gets the "remainder" of the division, and can be used to "wrap" the numbers and keep them all within the range of 0 through whatever... in this case, we want all number to remain within the range of 0 through 12. We do that by doing
card mod 13. The following sequence
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, 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, 50, 51
then becomes
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12
But we want the range to be 1 through 13, not 0 through 12. So we add 1:
((card mod 13)+1).
Suits:
Any card 0 through 12 is a SPADE (0)
Any card 13 through 25 is a HEART (1)
Any card 26 through 38 is a CLUB (2)
Any card 39 through 52 is a DIAMOND (3)
Basically, we want to scale the numbers down such as to force the range of 0 through 51 to fit into the range of 0 through 3. i.e. We want to change the sequence:
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, 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, 50, 51
into
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3
To do this, we use
div, which is the 'integer division' operator. It's basically the same thing as division but it throws away the "remainder".
So the formula would need to be
(card div 13)
0 div 13 is 0,
1 div 13 is 0,
2 div 13 is 0,
. . .,
13 div 13 is 1
14 div 13 is 1,
15 div 13 is 1,
. . .,
26 div 13 is 2,
27 div 13 is 2,
28 div 13 is 2,
. . .,
39 div 13 is 3,
40 div 13 is 3,
. . .,
51 div 13 is 3.
Macros:
Macros are just a kind of constant. All they do is make the code more legible and easier to remember...
e.g. card_suit==CLUB makes a lot more sense than card_suit==2
e.g. card_value==QUEEN is a little easier to work with than card_value==12