/** * Determines wether players will be asked for insurance. If the dealers up card is and Ace, then insurance will be asked * @param std::vector<GamePlayer*>& A const reference of all GamePlayers * @param Hand A dealersHand */ bool Game::isInsuranceRequired(const std::vector<GamePlayer*> &gPlayers, Hand dealersHand) { bool askForInsurance = false; if (DEBUGGING) { std::cout << "DEBUG: game.isInsuranceRequired" << std::endl; } std::cout << "DEALERS HAND: " << dealersHand << std::endl; Card dealersUpCard = dealersHand.getIndividualCard(0); //LEARN HOW TO PROGRAM WITH CONSTS!!! Card dealersHoleCard = dealersHand.getIndividualCard(1); //LEARN HOW TO PROGRAM WITH CONSTS!!! //removed because of rule clarification const int TEN_CARD = 10; const int ACE = 1; if (DEBUGGING) { std::cout << "DEBUG: \nDealers up card is " << dealersUpCard << ". And the number is " << dealersUpCard.getCardValue() << std::endl; std::cout << "Dealers hole card is " << dealersHoleCard << ". And its value is " << dealersHoleCard.getCardValue() << std::endl; } if (dealersUpCard.getCardValue() == ACE) { //if dealer has ACE as UP card std::cout << "Dealer might have a BlackJack! Dealer will ask for insurance." << std::endl; askForInsurance = true; } else askForInsurance = false; if (DEBUGGING) { std::cout << "DEBUG: insurance required?: " << ((askForInsurance) ? "yes" : "no") << std::endl; std::cout << "END DEBUG: game.isInsuranceRequired" << std::endl; } return askForInsurance; }
bool Card::equalsValue(Card card, QString compareStr) { if(card.getCardValue().startsWith(compareStr)) { qDebug() << "True"; return true; } else return false; }
void Casino::startDealing() { cout<<"Dealing"<<endl; vector<Player>::iterator i; int playersCount = dealer.players.size(); for(i = dealer.players.begin(); i != dealer.players.end(); i++) { std::stringstream ss; ss << playersCount; Card c = dealer.dealCard(); cout<<"value: "<<c.getCardValue()<<endl; GameMessage gm(i->getSocket(), ss.str(), i->getName(), Message::GameMessageType::CARD, Message::ActionType::NONE, c); comm.sendMessage(gm); } for(i = dealer.players.begin(); i != dealer.players.end(); i++) { Card c = dealer.dealCard(); cout<<"value: "<<c.getCardValue()<<endl; GameMessage gm(i->getSocket(), string("Dealer"), i->getName(), Message::GameMessageType::CARD, Message::ActionType::NONE, c); comm.sendMessage(gm); } }
// displays the information of the card passed void printCard(Card toPrint) { if(toPrint.getCardDisplay() == 'X') cout << "JOKER!\n"; // Used in debugging, should never occur else if(toPrint.getCardDisplay() == '!') { cout << toPrint.getCardValue() << " of "; printCardSuit(toPrint); cout << endl;// 2 of Hearts format } else { cout << toPrint.getCardDisplay() << " of "; printCardSuit(toPrint); cout << endl; // A of Hearts format; } }
void Util::determineDuplicateCards(std::vector<Card*>& p_cards) { uint numberOfDuplicates = 0; Card * toAdd = NULL; for (size_t i = 0; i < p_cards.size() - 1; ++i) { Card * currentCard = p_cards.at(i); Card * nextCard = p_cards.at(i+1); if (currentCard->getCardValue() == nextCard->getCardValue()) { ++numberOfDuplicates; toAdd = currentCard; } else { if (numberOfDuplicates != 0) { m_occurences.insert(std::pair<uint,uint>(toAdd->getCardValue(), numberOfDuplicates)); numberOfDuplicates = 0; } } } if (numberOfDuplicates != 0 && toAdd != NULL) { m_occurences.insert(std::pair<uint,uint>(toAdd->getCardValue(), numberOfDuplicates)); } for(std::map<uint,uint>::iterator it = m_occurences.begin(); it != m_occurences.end(); ++it ) { m_occurencesVector.push_back(it->second); } std::sort(m_occurencesVector.begin(), m_occurencesVector.end()); }
void Casino::readMgt() { string msg; vector<Player>::iterator i; fd_set readset; FD_ZERO(&readset); int count = 0; cout<<"readmgt "<<endl; while((dealer.players.empty())||(dealer.players.size() <= 1)) { } cout<<"starting Dealing"<<endl; startDealing(); cout<<"starting Dealing finished"<<endl; for(i = dealer.players.begin(); i!= dealer.players.end(); i++) { //i = dealer.players.begin(); do{ /*FD_SET(i->getSocket(), &readset); int r=select(i->getSocket(), &readset, NULL, NULL, NULL); if(r > 0) {*/ cout<<"Waiting for Player one"<<endl; comm.readMessage(i->getSocket(), msg); //} cout<<msg; string err; json11::Json a = json11::Json::parse(msg.c_str(), err); msg = a["actionType"].dump(); if(msg.size() > 0) { msg.erase(0, 1); msg.erase(msg.find('"')); } if(!strcmp(msg.c_str(), "hit")) { cout<<"hit clicked"<<endl; Card c = dealer.dealCard(); cout<<"value: "<<c.getCardValue()<<endl; GameMessage gm(i->getSocket(), string("Dealer"), i->getName(), Message::GameMessageType::CARD, Message::ActionType::NONE, c); comm.sendMessage(gm); } else if(!strcmp(msg.c_str(), "stand")) { cout<<"stand clicked"; i->setStand(true); } } while(!i->getStand()); } }