Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- enum SUIT { HEART, CLUB, DIAMOND, SPADE };
- string suit_string[] = {"HEART", "CLUB", "DIAMOND", "SPADE"};
- enum VALUE { ACE, TWO, THREE, FOUR, FIVE, SIX,
- SEVEN, EIGHT, NINE, TEN, JACK, QUEEN, KING};
- string value_string[] = {"ACE", "TWO", "THREE", "FOUR", "FIVE",
- "SIX", "SEVEN", "EIGHT","NINE", "TEN", "JACK", "QUEEN", "KING"};
- class Card {
- public:
- Card(SUIT s, VALUE v);
- SUIT suit;
- VALUE value;
- string toString();
- };
- Card::Card(SUIT s, VALUE v){
- suit=s;
- value=v;
- }
- string Card::toString(){
- return value_string[(int)this->value]+" of "+suit_string[(int)this->suit];
- }
- int main() {
- vector<Card*> deck;
- for (int i=0; i<4; i++) {
- for (int j=0; j<13; j++) {
- deck.push_back(new Card((SUIT)i,(VALUE)j));
- }
- }
- int removed_count, runs = 0;
- do{
- random_shuffle(deck.begin(),deck.end());
- removed_count=0;
- cout<<"--- Run number: "<<++runs<<"n";
- cout<<"--- still "<<deck.size()<<" cards in the deckn";
- for (int i=0; i<4; i++) {
- for (int j=0; j<13; j++) {
- //cout<<i*13+j<<"n";
- int position=i*13+j; //from 0 to 51
- cout<<"'"+value_string[j]+"'"<<" <-> ";
- Card card=*(deck.at(position));
- cout<<card.toString()<<" ";
- if(card.value == j){
- removed_count++;
- deck.erase(deck.begin()+position); //problems here!
- cout<<"removedn";
- }else{
- cout<<"not removedn";
- }
- }
- }
- if(deck.empty()) break;
- }while(removed_count>0);
- if(deck.empty()){
- cout<<"You win!n";
- }else{
- cout<<"You lose!n";
- }
- return 0;
- }
- 'KING' <-> terminate called after throwing an instance of 'std::out_of_range'
- what(): vector::_M_range_check
- deck.erase(deck.begin()+position);
- int position=i*13+j; //from 0 to 51
- Card card=*(deck.at(position));
Add Comment
Please, Sign In to add comment