|
#pragma once
|
|
#include "card.hpp"
|
|
#include <list>
|
|
#include <algorithm>
|
|
#include <iostream>
|
|
#include <iterator>
|
|
#include <random>
|
|
#include <vector>
|
|
#include <sstream>
|
|
#include <string>
|
|
|
|
class Deck
|
|
{
|
|
|
|
public:
|
|
std::list<std::string> kinds = {"C", "D", "S", "H"};
|
|
std::list<std::string> values = {"2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"};
|
|
|
|
std::vector<Card> cards;
|
|
size_t length = 0;
|
|
Deck(std::string cardString = "", bool shuffle=true)
|
|
{
|
|
for (auto &kind : kinds)
|
|
{
|
|
for (auto &value : values)
|
|
{
|
|
std::string key = kind + value;
|
|
Card card(key);
|
|
this->cards.push_back(card);
|
|
}
|
|
}
|
|
|
|
if(shuffle == true)
|
|
{
|
|
std::random_device rd;
|
|
std::mt19937 g(rd());
|
|
std::shuffle(this->cards.begin(), this->cards.end(), g);
|
|
}
|
|
|
|
std::string key;
|
|
std::stringstream ss(cardString);
|
|
while (std::getline(ss, key, ','))
|
|
{
|
|
if (this->deleteCard(key))
|
|
{
|
|
this->putCard(key);
|
|
}
|
|
}
|
|
|
|
this->length = this->cards.size();
|
|
}
|
|
bool deleteCard(std::string key)
|
|
{
|
|
for (int i = 0; i < this->cards.size(); i++)
|
|
{
|
|
if (this->cards[i].key == key)
|
|
{
|
|
this->cards.erase(this->cards.begin() + i);
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
void putCard(std::string key)
|
|
{
|
|
this->deleteCard(key);
|
|
Card card = Card(key);
|
|
this->cards.insert(this->cards.begin(), card);
|
|
}
|
|
Card getCard()
|
|
{
|
|
Card card = this->cards[0];
|
|
this->cards.erase(this->cards.begin(), this->cards.begin() + 1);
|
|
this->length = this->cards.size();
|
|
return card;
|
|
}
|
|
void print()
|
|
{
|
|
for (auto &card : this->cards)
|
|
{
|
|
std::cout << card.key << std::endl;
|
|
}
|
|
}
|
|
};
|