Game.cpp
//
// Game:: bet()
// this is the betting mechanism used in every poker game
// players will keep betting until an agreed bet is made or players run out of chips
//

: bet()
this is the betting mechanism used in every poker game
players will keep betting until an agreed bet is made or players run out of chips
: bet () this is the betting mechanism used in every poker game players will keep betting until an agreed bet is made or players run out of chips
void Game::bet(){
	unsigned int currentBet = 0;
	unsigned int roundPot = 0;
	for (auto it = players.begin(); it < players.end(); it++){
		(*it)->cBet = 0;
	}
	auto it = players.begin();
	auto lastPlayer = players.end();
	for (auto it = players.begin(); it != lastPlayer ; it++) {
		if (it == players.end()) {
			it = players.begin();
		}
		cout << endl;
		printPlayerCards((*it)->name);
		cout << "total chips= " << (*it)->chips << " current bet: " << currentBet << " to call: " << currentBet - (*it)->cBet << endl;
		bool validResponse = false;
		int nothing = 0;
		int oneChip = 1;
		int twoChips = 2;
		int foldIndex = 7;
		if (!(*it)->folded && (*it)->chips != nothing && currentBet == nothing) {
			while (!validResponse) {
				cout << "Bet 1/2 Check 0?" << endl;
				string response;
				getline(cin, response);
				istringstream iss(response);
				string word;
				iss >> word;
				int singleChar = 1;
				int firstIndex = 0;
				if (word.size() == singleChar && isdigit(word[firstIndex])){
					size_t num = std::stoul(word, nullptr, 0);
					if (num == oneChip || num == twoChips) {
						if (num <= (*it)->chips) {
							(*it)->deductChips(num);
							roundPot += num;
							if (it == players.begin()){
								lastPlayer = players.end();
							}
							else{
								lastPlayer = it;
							}
							currentBet = num;
							(*it)->cBet = num;
							validResponse = true;
						}
					}
					else if (num == nothing) {
						validResponse = true;
					}
				}
			}
		}
		else if (!(*it)->folded && (*it)->chips != nothing) {
			while (!validResponse) {
				cout << "Raise 1/2 Call 0 Fold 7?" << endl;
				string response;
				getline(cin, response);
				istringstream iss(response);
				string word;
				iss >> word;
				int singleChar = 1;
				int firstIndex = 0;
				if (word.size() == singleChar && isdigit(word[firstIndex])){
					size_t num = std::stoul(word, nullptr, 0);
					if (num == oneChip || num == twoChips) {
						unsigned int raiseAmount = num + currentBet - (*it)->cBet;
						if (raiseAmount <= (*it)->chips) {
							(*it)->deductChips(raiseAmount);
							roundPot += raiseAmount;
							if (it == players.begin()){
								lastPlayer = players.end();
							}
							else{
								lastPlayer = it;
							}							
							(*it)->cBet += raiseAmount;
							currentBet += num;
							validResponse = true;
						}
						else {
							validResponse = false;
							cout << "You don't have enough chips to raise" << endl;
						}
					}
					else if (num == nothing) {
						unsigned int callAmount = currentBet - (*it)->cBet;
						if (callAmount <= (*it)->chips) {
							(*it)->deductChips(callAmount);
							roundPot += callAmount;
							(*it)->cBet += callAmount;
							validResponse = true;
						}
						else{
							unsigned int numChips = (*it)->chips;
							(*it)->deductChips(numChips);
							roundPot += numChips;
							(*it)->cBet += (*it)->chips;
							validResponse = true;
						}
					}
					else if (num == foldIndex){
						(*it)->folded = true;
						validResponse = true;
					}
				}
			}
		}
		else if (!(*it)->folded){
			cout << "you no longer have enough chips to bet, enjoy watching :)" << endl;
		}
	}
	totalPot += roundPot;
}
void Game :: bet ( ) { unsigned int currentBet = 0 ; unsigned int roundPot = 0 ; for ( auto it = players . begin ( ) ; it < players . end ( ) ; it ++ ) { ( * it ) -> cBet = 0 ; } auto it = players . begin ( ) ; auto lastPlayer = players . end ( ) ; for ( auto it = players . begin ( ) ; it != lastPlayer ; it ++ ) { if ( it == players . end ( ) ) { it = players . begin ( ) ; } cout << endl ; printPlayerCards ( ( * it ) -> name ) ; cout << " " << ( * it ) -> chips << " " << currentBet << " " << currentBet - ( * it ) -> cBet << endl ; bool validResponse = false ; int nothing = 0 ; int oneChip = 1 ; int twoChips = 2 ; int foldIndex = 7 ; if ( ! ( * it ) -> folded && ( * it ) -> chips != nothing && currentBet == nothing ) { while ( ! validResponse ) { cout << " " << endl ; string response ; getline ( cin , response ) ; istringstream iss ( response ) ; string word ; iss >> word ; int singleChar = 1 ; int firstIndex = 0 ; if ( word . size ( ) == singleChar && isdigit ( word [ firstIndex ] ) ) { size_t num = std :: stoul ( word , nullptr , 0 ) ; if ( num == oneChip || num == twoChips ) { if ( num <= ( * it ) -> chips ) { ( * it ) -> deductChips ( num ) ; roundPot += num ; if ( it == players . begin ( ) ) { lastPlayer = players . end ( ) ; } else { lastPlayer = it ; } currentBet = num ; ( * it ) -> cBet = num ; validResponse = true ; } } else if ( num == nothing ) { validResponse = true ; } } } } else if ( ! ( * it ) -> folded && ( * it ) -> chips != nothing ) { while ( ! validResponse ) { cout << " " << endl ; string response ; getline ( cin , response ) ; istringstream iss ( response ) ; string word ; iss >> word ; int singleChar = 1 ; int firstIndex = 0 ; if ( word . size ( ) == singleChar && isdigit ( word [ firstIndex ] ) ) { size_t num = std :: stoul ( word , nullptr , 0 ) ; if ( num == oneChip || num == twoChips ) { unsigned int raiseAmount = num + currentBet - ( * it ) -> cBet ; if ( raiseAmount <= ( * it ) -> chips ) { ( * it ) -> deductChips ( raiseAmount ) ; roundPot += raiseAmount ; if ( it == players . begin ( ) ) { lastPlayer = players . end ( ) ; } else { lastPlayer = it ; } ( * it ) -> cBet += raiseAmount ; currentBet += num ; validResponse = true ; } else { validResponse = false ; cout << " " << endl ; } } else if ( num == nothing ) { unsigned int callAmount = currentBet - ( * it ) -> cBet ; if ( callAmount <= ( * it ) -> chips ) { ( * it ) -> deductChips ( callAmount ) ; roundPot += callAmount ; ( * it ) -> cBet += callAmount ; validResponse = true ; } else { unsigned int numChips = ( * it ) -> chips ; ( * it ) -> deductChips ( numChips ) ; roundPot += numChips ; ( * it ) -> cBet += ( * it ) -> chips ; validResponse = true ; } } else if ( num == foldIndex ) { ( * it ) -> folded = true ; validResponse = true ; } } } } else if ( ! ( * it ) -> folded ) { cout << " " << endl ; } } totalPot += roundPot ; }
Game:: bet()
this is the betting mechanism used in every poker game
players will keep betting until an agreed bet is made or players run out of chips
Game :: bet () this is the betting mechanism used in every poker game players will keep betting until an agreed bet is made or players run out of chips