Exchanging Elements between Class-based Vectors based on Lowest Occurrences of Same Elements

I am trying to make a card game with the following protocol: 1) A group of players (you and then computer generated players) 2) Each player has 7 cards 3) Each player gets a turn where he selects a one card from his hand and passes to next player Goal: The player with all 7 cards of same suit wins

Problem: I am trying to figure our how I can remove a card from my hand and then transfer to the next player Player1 who then selects card of the least occurring suit to pass to next player and so on and so forth...

This is the code I have so far: #include

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <string>
#include <vector>

using namespace std;

class card{//1st Constructors and initializers
	char m_char; // "S" "C" "D" "H"
	int m_num;
public:
	card(const char s = 'S', const int n = 0) : m_char(s), m_num(n){/*2nd*/};
	friend ostream& operator << (ostream& o, const card& c);
};

ostream& operator << (ostream& o, const card& c){
	o << c.m_char;
	switch(c.m_num){
	case 1: o << "A"; break;
	case 11: o << "J"; break;
	case 12: o << "Q"; break;
	case 13: o << "K"; break;
	default: o << c.m_num;
	}
	return o;
}

class player {
	string m_name;
	vector<card> m_deck;
public:
	player(const string& n) : m_name(n) {m_deck.reserve(7);}
	void push_back(const card& c){m_deck.push_back(c); }
	void back(char input){
		card hold; card r;
		if (input == 'a')
		{hold = m_deck.back(); m_deck[6] = m_deck[0]; m_deck[0] = hold; r = m_deck.back();}
		else if (input == 'b')
		{hold = m_deck.back(); m_deck[6] = m_deck[1]; m_deck[1] = hold; r = m_deck.back();}
		else if (input == 'c')
		{hold = m_deck.back(); m_deck[6] = m_deck[2]; m_deck[2] = hold; r = m_deck.back();}
		else if (input == 'd')
		{hold = m_deck.back(); m_deck[6] = m_deck[3]; m_deck[3] = hold; r = m_deck.back();}
		else if (input == 'e')
		{hold = m_deck.back(); m_deck[6] = m_deck[4]; m_deck[4] = hold; r = m_deck.back();}
		else if (input == 'f')
		{hold = m_deck.back(); m_deck[6] = m_deck[5]; m_deck[5] = hold; r = m_deck.back();}
		else if (input == 'g'){hold = m_deck.back(); r = m_deck.back();}
	}

	void remove_best(int hcount, int ccount, int dcount, int scount){
		if (hcount > ccount && hcount > dcount && hcount > scount){}
		if (ccount > hcount && ccount > dcount && ccount > scount){}
		if (dcount > ccount && dcount > hcount && dcount > scount){}
		if (scount > ccount && scount > dcount && scount > hcount){}
	}
//	void count(int hcount, int ccount, int dcount, int scount){
//		hcount = ccount = scount = dcount = 0;
//		for (int i = 0, len = m_deck.size(); i < len; ++i){
//		if (m_deck[i].m_char == 'H') ++ hcount; //gives error
//		else if (m_deck[i].m_char == 'C') ++ccount; //gives error
//		else if (m_deck[i].m_char == 'D' ) ++dcount; //gives error
//		else if (m_deck[i].m_char == 'S' ) ++scount; //gives error
//		}
//	}

	friend ostream& operator<<(ostream& o, const player& p);
};

ostream& operator<<(ostream& o, const player& p){
	o << "Player: " << p.m_name << " has: " <<endl;
	for (int i = 0, len = p.m_deck.size() - 1; i < len; ++i){
		char a = 'a';
		o << (char)('a' + i) << ") " << p.m_deck[i] << " ";
	}
	return o;
}



int main(){
	//Deck Building
	vector<card>deck(52);
	for (int i = 1; i <= 13; ++i) deck.push_back(card('S', i));
	for (int i = 1; i <= 13; ++i) deck.push_back(card('C', i));
	for (int i = 1; i <= 13; ++i) deck.push_back(card('D', i));
	for (int i = 1; i <= 13; ++i) deck.push_back(card('H', i));
	random_shuffle(deck.begin(), deck.end());

	//Creating Players and Thier "Hand" Vectors
	vector<player>players;
	players.push_back(player("You"));
	players.push_back(player("Player1"));
	players.push_back(player("Player2"));
	players.push_back(player("Player3"));
	players.push_back(player("Player4"));

	//Filling Eaching "Hand" Vector with 7 Cards
	for (int i = 0, len = players.size(); i < len; ++i){
		for (int j = 0; j < 8; ++j){
			card c = deck.back();
			players[i].push_back(c);
			deck.pop_back();
		}
	}

	while(true){
		cout << players[0] << endl;
		cout << "What to Do: ";
		char input; cin >> input;
		if (input == '?') {
			for(int i = 1, len = players.size(); i < len; ++i) cout << players[i] << endl;
		}
		if (input == 'q') break;

		if (input == 'a') players[0].back(input);
		if (input == 'b') players[0].back(input);
		if (input == 'c') players[0].back(input);
		if (input == 'd') players[0].back(input);
		if (input == 'e') players[0].back(input);
		if (input == 'f') players[0].back(input);
		if (input == 'g') players[0].back(input);


	}
	return 0;
}
Topic archived. No new replies allowed.