Skip to content

Instantly share code, notes, and snippets.

@mattatcha
Forked from ConatserCA/gist:c85917f5318f9d39423c
Created October 29, 2014 23:51
Show Gist options
  • Save mattatcha/4bec0ed81de1832b5512 to your computer and use it in GitHub Desktop.
Save mattatcha/4bec0ed81de1832b5512 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
// http://stackoverflow.com/a/20735198/688275
void shuffle(int *arr, size_t n)
{
if (n > 1)
{
size_t i;
srand(time(NULL));
for (i = 0; i < n - 1; i++)
{
size_t j = i + rand() / (RAND_MAX / (n - i) + 1);
int t = arr[j];
arr[j] = arr[i];
arr[i] = t;
}
}
}
// deck = initial deck
// Create two arrays
// array of numbers 1-13
// array of numbers 1-52
// shuffled array
//
void fill(int *arr, size_t n)
{
for (i=0; i<10; i++)
{
arr[i] = i;
}
}
int main()
{
//variable initialization & labeling the randomizer
static const int nSuit = 4;
static const int nCard = 13;
static const int nHand = 5;
int suit(0), card(0), suitpos(0), cardpos(0), count(1), place(1), buffer(0), initialpos(1);
srand(time(0));
//Setting array values
int placeCard[nCard][nSuit];
string hand1[nHand];
string hand2[nHand];
string deck[nSuit][nCard] = { { "Ace of Hearts", "Two of Hearts", "Three of Hearts", "Four of Hearts", "Five of Hearts", "Six of Hearts", "Seven of Hearts", "Eight of Hearts", "Nine of Hearts", "Ten of Hearts", "Jack of Hearts", "Queen of Hearts", "King of Hearts" }, { "Ace of Spades", "Two of Spades", "Three of Spades", "Four of Spades", "Five of Spades", "Six of Spades", "Seven of Spades", "Eight of Spades", "Nine of Spades", "Ten of Spades", "Jack of Spades", "Queen of Spades", "King of Spades" }, { "Ace of Clubs", "Two of Clubs", "Three of Clubs", "Four of Clubs", "Five of Clubs", "Six of Clubs", "Seven of Clubs", "Eight of Clubs", "Nine of Clubs", "Ten of Clubs", "Jack of Clubs", "Queen of Clubs", "King of Clubs" }, { "Ace of Diamonds", "Two of Diamonds", "Three of Diamonds", "Four of Diamonds", "Five of Diamonds", "Six of Diamonds", "Seven of Diamonds", "Eight of Diamonds", "Nine of Diamonds", "Ten of Diamonds", "Jack of Diamonds", "Queen of Diamonds", "King of Diamonds" } };
string shuffledDeck[nSuit][nCard];
int shuffledNumbers[nSuit][nCard];
// Initial Deck = UnShuffled Deck
// Shuffle deck
// shuffleDeck[suit][card] = deck[suitpos][cardpos]
// Shuffled Deck = ^
// Shuffling and Init
for (suit = 0; suit < nSuit; suit++)
{
// Suits
shuffledNumbers[suit][0] = rand() % nSuit;
for (card = 0; card < nCard; card++)
{
// cards
// Suits =
cardpos = (rand() % nCard);
suitpos = (rand() % nSuit);
cout << cardpos << " : " << suitpos << endl;
shuffledDeck[suit][card] = deck[suitArray[suit]][cardArray[card]];
}
}
// cout << shuffledDeck << endl;
// Display
for (suit = 0; suit < nSuit; suit++)
{
for (card = 0; card < nCard; card++)
{
cout << shuffledDeck[suit][card] << endl;
// cout << place << " " << deck[(placeCard[card][suit] - 1)] << endl;
// place++;
}
}
// cout << endl;
system("pause");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment