Skip to content

Instantly share code, notes, and snippets.

@gomathi
Created May 11, 2020 02:01
Show Gist options
  • Save gomathi/61c084a2156bcb4a744b8cc47e94f55e to your computer and use it in GitHub Desktop.
Save gomathi/61c084a2156bcb4a744b8cc47e94f55e to your computer and use it in GitHub Desktop.
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include <random>
using namespace std;
#define SUITS_NO 4
#define CARDS_NO 13
#define DECK_NO 52
vector<string> generateDeck()
{
vector<string> c;
string suit[4] = {"club", "diamonds", "heart", "spade"};
string cards[13] = {"Ace", "Two", "Three", "Four", "Five", "Six","Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King"};
for (int i = 0; i < 52; i++){
int j = i / 13;
int k = i % 13;
c.push_back(suit[j]+cards[k]);
}
return c;
}
vector<string> Shuffle_cards(vector<string> cards)
{
vector<string> result;
std::random_shuffle(cards.begin(), cards.end());
for(int i=0; i<52; i++){
result.push_back(cards[i]);
}
return result;
}
vector<string> generate_subset(vector<string> card, int n)
{
vector<string> subset;
int i;
for(i = 0; i < 51; i++ ){
string inner_value = card[i]+card[i+1];
subset.push_back(inner_value);
}
return subset;
}
bool compare_decks(vector<string> card, vector<string> card1)
{
vector<string> subset = generate_subset(card, 2);
vector<string> subset1 = generate_subset(card1, 2);
for(int i = 0; i < subset.size(); i++ )
{
for(int j=0; j < subset1.size(); j++)
{
if(subset.at(i) == subset1.at(j))
{
cout << subset.at(i) << '\n';
cout << subset1.at(j) << '\n';
return true;
}
}
}
return false;
}
void printCards(vector<string> cards){
for(int i=0; i<cards.size(); i++)
cout << cards.at(i) << " ";
cout << "\n\n";
}
int main()
{
vector<string> Deckcards = generateDeck();
for (int i = 0; i < 52; i++){
cout << Deckcards[i] <<endl;
}
cout << "Finished" << "\n";
bool succedded = false;
while(!succedded) {
vector<string> SDeckcards1 = Shuffle_cards(Deckcards);
cout << "Itreation" << "\n\n";
printCards(Deckcards);
printCards(SDeckcards1);
succedded = compare_decks(Deckcards, SDeckcards1);
cout << succedded << "\n";
Deckcards = SDeckcards1;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment