int main() { setbuf( stdout, 0); init(); dealer(); return 0; }
void process_player_input(node *player, stats *status){ u8 decision; u16 rise; if(player->state != FOLD){ //decision = get_player_decision1(player->number); decision = get_input(win.commands); u8 number_of_tries = 0; // number of tries while( decision < 1 || decision > 3 ){ if(number_of_tries <10){ display_message(player->number, "Try again!\n"); //decision = get_player_decision1(player->number); decision = get_input(win.commands); } else{ // If input was incorrect too many times default to FOLD decision = FOLD; break; } } if(decision == FOLD){ player->state = FOLD; status->folded--; } else if(decision == CALL){ dealer(player, status->money_to_play); player->state = CALL; } else if(decision == RISE){ rise = get_player_decision2(player->number, "Player raised\n"); while(rise <= 0){ // Make sure rise is not equal or less than 0 rise = get_player_decision2(player->number, "Invalid value, must be above 0\n"); } status->money_to_play += rise; dealer(player, status->money_to_play); status->last = player; // Update last player to the one that rised! player->state = RISE; } } }
void BJPlayer::computeDealer(BJRules & rules, BJProgress & progress) { BJDealer dealer(rules.getHitSoft17()); for (int i = 0; i < numHands; i++) { progress.indicate(100*i/numHands); PlayerHand & hand = playerHands[i]; currentHand.reset(hand.cards); shoe.reset(currentHand); dealer.computeProbabilities(shoe); for (int upCard = Card::Ace; upCard <= Card::Ten; ++upCard) { hand.probabilityBust[upCard - 1] = dealer. getProbabilityBust(upCard); for (int count = 17; count <= 21; count++) { hand.probabilityCount[count - 17][upCard - 1] = dealer. getProbabilityCount(count, upCard); } hand.probabilityBlackjack[upCard - 1] = dealer. getProbabilityBlackjack(upCard); } } }
void stay() //Function for when user selects 'Stay' { dealer(); //If stay selected, dealer continues going if(dealer_total>=17) { if(player_total>=dealer_total) //If player's total is more than dealer's total, win { printf("\nUnbelievable! You Win!\n"); won = won+1; cash = cash+bet; printf("\nYou have %d Wins and %d Losses. Awesome!\n", won, loss); dealer_total=0; askover(); } if(player_total<dealer_total) //If player's total is less than dealer's total, loss { printf("\nDealer Has the Better Hand. You Lose.\n"); loss = loss+1; cash = cash - bet; printf("\nYou have %d Wins and %d Losses. Awesome!\n", won, loss); dealer_total=0; askover(); } if(dealer_total>21) //If dealer's total is more than 21, win { printf("\nUnbelievable! You Win!\n"); won = won+1; cash = cash+bet; printf("\nYou have %d Wins and %d Losses. Awesome!\n", won, loss); dealer_total=0; askover(); } } else { stay(); } } // End Function
int main(int argc, char* argv[]){ int check = 0; DeckOfCards deck; Player player(0); Player dealer(1); deck.shuffle(); // deck.printDeck(); for (int i = 0; i < 5; ++i){ player.addCard(deck.dealCard()); dealer.addCard(deck.dealCard()); } player.sortHand(); dealer.sortHand(); player.printHand(); findWinner(player, dealer); return 0; }
int main(int argc, const char* argv[]) { std::cout << "ZMQ version = " << zmq_utils::get_zmq_version() << "\n"; if (argc < 2) { std::cout << "missing dealer_id\n"; return 1; } const char* dealer_id = argv[1]; //dealer id std::cout << "dealer_id = " << dealer_id << "\n"; zmq::context_t context; zmq::socket_t dealer(context, ZMQ_DEALER); dealer.setsockopt(ZMQ_IDENTITY, dealer_id, strlen(dealer_id)); dealer.connect("tcp://127.0.0.1:60000"); socket_monitor m(dealer); while (true) { try { if (m.is_connected()) { zmq_utils::send_string(dealer, "SOME DATA"); zmq::message_t msg; size_t size = 0; while (m.is_connected() && size == 0) size = dealer.recv(&msg, ZMQ_DONTWAIT); if (size > 0) std::cout << zmq_utils::to_string(msg) << "\n"; } } catch (const zmq::error_t& err) { std::cout << "[ERROR] " << err.what() << "\n"; } } //dealer.close(); //context.close(); return 0; }
void play() //Plays game { int p=0; // holds value of player_total int i=1; // counter for asking user to hold or stay (aka game turns) char choice3; cash = cash; cash_test(); printf("\nCash: $%d\n",cash); //Prints amount of cash user has randcard(); //Generates random card player_total = p + l; //Computes player total p = player_total; printf("\nYour Total is %d\n", p); //Prints player total dealer(); //Computes and prints dealer total betting(); //Prompts user to enter bet amount while(i<=21) //While loop used to keep asking user to hit or stay at most twenty-one times // because there is a chance user can generate twenty-one consecutive 1's { if(p==21) //If user total is 21, win { printf("\nUnbelievable! You Win!\n"); won = won+1; cash = cash+bet; printf("\nYou have %d Wins and %d Losses. Awesome!\n", won, loss); dealer_total=0; askover(); } if(p>21) //If player total is over 21, loss { printf("\nWoah Buddy, You Went WAY over.\n"); loss = loss+1; cash = cash - bet; printf("\nYou have %d Wins and %d Losses. Awesome!\n", won, loss); dealer_total=0; askover(); } if(p<=21) //If player total is less than 21, ask to hit or stay { printf("\n\nWould You Like to Hit or Stay?"); scanf("%c", &choice3); while((choice3!='H') && (choice3!='h') && (choice3!='S') && (choice3!='s')) // If invalid choice entered { printf("\n"); printf("Please Enter H to Hit or S to Stay.\n"); scanf("%c",&choice3); } if((choice3=='H') || (choice3=='h')) // If Hit, continues { randcard(); player_total = p + l; p = player_total; printf("\nYour Total is %d\n", p); dealer(); if(dealer_total==21) //Is dealer total is 21, loss { printf("\nDealer Has the Better Hand. You Lose.\n"); loss = loss+1; cash = cash - bet; printf("\nYou have %d Wins and %d Losses. Awesome!\n", won, loss); dealer_total=0; askover(); } if(dealer_total>21) //If dealer total is over 21, win { printf("\nDealer Has Went Over!. You Win!\n"); won = won+1; cash = cash+bet; printf("\nYou have %d Wins and %d Losses. Awesome!\n", won, loss); dealer_total=0; askover(); } } if((choice3=='S') || (choice3=='s')) // If Stay, does not continue { printf("\nYou Have Chosen to Stay at %d. Wise Decision!\n", player_total); stay(); } } i++; //While player total and dealer total are less than 21, re-do while loop } // End While Loop } // End Function