Algorithm for shuffling cards in Microsoft's card games
This algorithm is written in C ++ programming language and implemented in the Microsoft Visual C ++ programming environment.
_____________________________
#define BLACK 0 // COLOR (card)
#define RED 1
#define ACE 0 // VALUE (card)
#define DEUCE 1
#define CLUB 0 // SUIT (card)
#define DIAMOND 1
#define HEART 2
#define SPADE 3
#define SUIT (card) ((card)% 4)
#define VALUE (card) ((card) / 4)
#define COLOR (card) (SUIT (card) == DIAMOND || SUIT (card) == HEART)
#define MAXPOS 21
#define MAXCOL 9 // includes top row as column 0
CARD card [MAXCOL] [MAXPOS];
// current layout of cards, CARDs are
Ints
{
Int i, j;
// generic counters
Int col, pos;
Int wLeft = 52;
// cards left to be selected in shuffle
CARD deck [52];
// deck of 52 unique cards
For (col = 0; col <MAXCOL; col ++) // clear the deck
For (pos = 0; pos <MAXPOS; pos ++)
Card [col] [pos] = EMPTY;
/ * Shuffle cards * /
For (i = 0; i <52; i ++) // put unique card in each deck loc.
Deck [i] = i;
Srand (gamenumber);
// gamenumber is seed for rand ()
For (i = 0; i <52; i ++)
{
J = rand ()% wLeft;
Card [(i% 8) +1] [i / 8] = deck [j];
Deck [j] = deck [- wLeft];
}
}
___________________________
Comments
Commenting on, remember that the content and tone of your message can hurt the feelings of real people, show respect and tolerance to your interlocutors even if you do not share their opinion, your behavior in the conditions of freedom of expression and anonymity provided by the Internet, changes Not only virtual, but also the real world. All comments are hidden from the index, spam is controlled.