FiveCardDraw.cpp
//
// FiveCardDraw:: before_turn(Player & player)
// after dealing the cards to the players, print the names of the players and their hands
// then ask each player if they want to discard any card in their hand, if so, discard the 
// cards requested
//

: before_turn(Player & player)
after dealing the cards to the players, print the names of the players and their hands
then ask each player if they want to discard any card in their hand, if so, discard the
cards requested
: before_turn ( Player & player ) after dealing the cards to the players print the names of the players and their hands then ask each player if they want to discard any card in their hand if so discard the cards requested
int FiveCardDraw::before_turn(Player & player){
	cout << endl;
	cout << "CURRENT PLAYER: " << player.name << endl;
	cout << "YOUR HAND: " << endl << player.hand << endl;
	const vector<size_t> validIndex = { 0, 1, 2, 3, 4 };
	set<size_t> removeIndex; 
	string response;
	bool validResponse = false;
	while (!validResponse) {
		removeIndex.clear();
		cout << "Which cards do you want to discard?" << endl;
		getline(cin, response);
		validResponse = true;
		if (response == "") {
		}
		else {
			istringstream iss(response);
			string word;
			while (iss >> word && validResponse) {
				if (word.size() == 1 && isdigit(word[0])){
					size_t num = std::stoul(word, nullptr, 0);
					validResponse = false;
					for (auto it = validIndex.begin(); it != validIndex.end(); ++it) {
						if (num == *it) {
							validResponse = true;
							removeIndex.insert(num);
							break;
						}
					}
				}
				else{
					validResponse = false;
				}
			}
			if (validResponse) {
				size_t offset = 0;
				for (auto it = removeIndex.begin(); it != removeIndex.end(); ++it) {
					size_t ri = *it - offset;
					discard_deck.addCard(player.hand[ri]);
					player.hand.remove_card(ri);
					offset++;
				}
			}
		}
	}
	return errors::noError;
}
int FiveCardDraw :: before_turn ( Player & player ) { cout << endl ; cout << " " << player . name << endl ; cout << " " << endl << player . hand << endl ; const vector < size_t > validIndex = { 0 , 1 , 2 , 3 , 4 } ; set < size_t > removeIndex ; string response ; bool validResponse = false ; while ( ! validResponse ) { removeIndex . clear ( ) ; cout << " " << endl ; getline ( cin , response ) ; validResponse = true ; if ( response == " " ) { } else { istringstream iss ( response ) ; string word ; while ( iss >> word && validResponse ) { if ( word . size ( ) == 1 && isdigit ( word [ 0 ] ) ) { size_t num = std :: stoul ( word , nullptr , 0 ) ; validResponse = false ; for ( auto it = validIndex . begin ( ) ; it != validIndex . end ( ) ; ++ it ) { if ( num == * it ) { validResponse = true ; removeIndex . insert ( num ) ; break ; } } } else { validResponse = false ; } } if ( validResponse ) { size_t offset = 0 ; for ( auto it = removeIndex . begin ( ) ; it != removeIndex . end ( ) ; ++ it ) { size_t ri = * it - offset ; discard_deck . addCard ( player . hand [ ri ] ) ; player . hand . remove_card ( ri ) ; offset ++ ; } } } } return errors :: noError ; }
FiveCardDraw:: before_turn(Player & player)
after dealing the cards to the players, print the names of the players and their hands
then ask each player if they want to discard any card in their hand, if so, discard the
cards requested
FiveCardDraw :: before_turn ( Player & player ) after dealing the cards to the players print the names of the players and their hands then ask each player if they want to discard any card in their hand if so discard the cards requested
// removeIndex contains the indecies of the cards the current player want to discard
 //so it stays sorted and not duplicated
 //player doesn't want to change cards, do nothing
 //going through the response to see if it is valid or not
 // player gives a valid response, discard the card requested and deal them more card
