void PrintScoresAndHands(int houseHand[], const int houseCardCount, int playerHand[], const int playerCardCount) { cout << "House's Hand: Score = " << ScoreHand(houseHand, houseCardCount) << endl; PrintHand(houseHand, houseCardCount); cout << "Player's Hand: Score = " << ScoreHand(playerHand, playerCardCount) << endl; PrintHand(playerHand, playerCardCount); cout << endl; }
int main(void) { fillDeck(); shuffleDeck(); passCard(playerHand, Player); passCard(playerHand, Player); PrintHand(); printf("You score is (%i). ", scorePlayerHand); do { CheckHand(); Ask(); Choice(); PrintHand(); printf("You score is (%i). ", scorePlayerHand); } while ((userAnswer == 'y' || userAnswer == 'Y')); getWinner(); return 0; }
int main() { ddTableDeal tableDeal; ddTableResults table; int res; char line[80]; bool match; #if defined(__linux) || defined(__APPLE__) SetMaxThreads(0); #endif for (int handno = 0; handno < 3; handno++) { for (int h = 0; h < DDS_HANDS; h++) for (int s = 0; s < DDS_SUITS; s++) tableDeal.cards[h][s] = holdings[handno][s][h]; res = CalcDDtable(tableDeal, &table); if (res != RETURN_NO_FAULT) { ErrorMessage(res, line); printf("DDS error: %s\n", line); } match = CompareTable(&table, handno); sprintf(line, "CalcDDtable, hand %d: %s\n", handno + 1, (match ? "OK" : "ERROR")); PrintHand(line, tableDeal.cards); PrintTable(&table); } }
void PlayBlackjack(int sock) { int done = 0; char buf[100]; int bet; char dealer[21]; int dealer_hand_value; char player[21]; int player_hand_value; int player_cards; int dealer_cards; while (!done) { // start with empty hands bzero(dealer, 21); bzero(player, 21); // print out current cash snprintf(buf, 99, "You have $%d\n", cash); sendit(sock, buf); // take bets bet = -1; while (bet < 0 || bet > MAX_BET) { sendit(sock, "How much would you like to bet (-1 to exit)? "); read_until(sock, buf, 99); bet = atoi(buf); if (bet == -1) { return; } if (bet < 0 || bet > MAX_BET) { snprintf(buf, 99, "Table limit is $%d. Bet again.\n", MAX_BET); sendit(sock, buf); } if (bet == 0) { sendit(sock, "Well, I suppose we can let a noob blackjack player learn the ropes without risking any money. Don't tell my pit boss.\n"); } if (bet > cash) { snprintf(buf, 99, "No lines of credit in this casino. Bet again.\n", MAX_BET); sendit(sock, buf); bet = -1; } } // deal inital hand player[0] = (rand() % 13)+1; dealer[0] = (rand() % 13)+1; player[1] = (rand() % 13)+1; dealer[1] = (rand() % 13)+1; // calc inital hand values player_hand_value = CalculateHandValue(player); dealer_hand_value = CalculateHandValue(dealer); // print out the hands sendit(sock, "Dealer: "); PrintHand(sock, dealer, 1); sendit(sock, "\n"); sendit(sock, "Player: "); PrintHand(sock, player, 0); sendit(sock, "\n"); player_cards = 2; while (player_cards <= 21) { // hit or stand sendit(sock, "Hit or Stand (H/S)? "); read_until(sock, buf, 99); if (buf[0] == 'H') { player[player_cards++] = (rand() % 13)+1; // print out the hand sendit(sock, "Player: "); PrintHand(sock, player, 0); sendit(sock, "\n"); } else if (buf[0] == 'S') { break; } // see if busted or win player_hand_value = CalculateHandValue(player); if (player_hand_value > 21) { break; } //else if (player_hand_value == 21) { // break; // } } dealer_cards = 2; while (player_hand_value <= 21 && dealer_cards < 21) { // dealer hit or stand if (dealer_hand_value < 17) { sendit(sock, "Dealer hits\n"); dealer[dealer_cards++] = (rand() % 13)+1; // print out the hand sendit(sock, "Dealer: "); PrintHand(sock, dealer, 0); sendit(sock, "\n"); } else { sendit(sock, "Dealer stands\n"); sendit(sock, "Dealer: "); PrintHand(sock, dealer, 0); sendit(sock, "\n"); break; } // see if busted dealer_hand_value = CalculateHandValue(dealer); if (dealer_hand_value > 21) { break; } else if (dealer_hand_value == 21) { break; } } // see who won if (player_hand_value == 21 && dealer_hand_value != 21) { sendit(sock, "You win!\n\n"); cash += bet; winnings[total_bets++] = bet; } else if (dealer_hand_value == 21 && player_hand_value != 21) { sendit(sock, "You lose!\n"); if (bet == 127 && TipWaitress(sock)) { bet++; } cash -= bet; winnings[total_bets++] = 0-bet; } else if (player_hand_value > 21) { sendit(sock, "You lose!\n\n"); if (bet == 127 && TipWaitress(sock)) { bet++; } cash -= bet; winnings[total_bets++] = 0-bet; } else if (dealer_hand_value > 21) { sendit(sock, "You win!\n\n"); cash += bet; winnings[total_bets++] = bet; } else if (player_hand_value > dealer_hand_value) { sendit(sock, "You win!\n\n"); cash += bet; winnings[total_bets++] = bet; } else if (player_hand_value == dealer_hand_value) { sendit(sock, "It's a draw.\n\n"); } else if (player_hand_value < dealer_hand_value) { sendit(sock, "You lose!\n\n"); if (bet == 127 && TipWaitress(sock)) { bet++; } cash -= bet; winnings[total_bets++] = 0-bet; } //PrintWinnings(sock); if (total_bets == MAX_WINNINGS) { sendit(sock, "The pit boss is tired of you flirting with the waitresses...you're outta here\n"); break; } if (cash <= 0) { break; } } }
int main() { boards bo; playTracesBin DDplays; solvedPlays solved; int chunkSize = 1, res; char line[80]; bool match; #if defined(__linux) || defined(__APPLE__) SetMaxThreads(0); #endif bo.noOfBoards = 3; DDplays.noOfBoards = 3; for (int handno = 0; handno < 3; handno++) { bo.deals[handno].trump = trump[handno]; bo.deals[handno].first = first[handno]; bo.deals[handno].currentTrickSuit[0] = 0; bo.deals[handno].currentTrickSuit[1] = 0; bo.deals[handno].currentTrickSuit[2] = 0; bo.deals[handno].currentTrickRank[0] = 0; bo.deals[handno].currentTrickRank[1] = 0; bo.deals[handno].currentTrickRank[2] = 0; for (int h = 0; h < DDS_HANDS; h++) for (int s = 0; s < DDS_SUITS; s++) bo.deals[handno].remainCards[h][s] = holdings[handno][s][h]; DDplays.plays[handno].number = playNo[handno]; for (int i = 0; i < playNo[handno]; i++) { DDplays.plays[handno].suit[i] = playSuit[handno][i]; DDplays.plays[handno].rank[i] = playRank[handno][i]; } } res = AnalyseAllPlaysBin(&bo, &DDplays, &solved, chunkSize); if (res != RETURN_NO_FAULT) { ErrorMessage(res, line); printf("DDS error: %s\n", line); } for (int handno = 0; handno < 3; handno++) { match = ComparePlay(&solved.solved[handno], handno); sprintf(line, "AnalyseAllPlaysBin, hand %d: %s\n", handno + 1, (match ? "OK" : "ERROR")); PrintHand(line, bo.deals[handno].remainCards); PrintBinPlay(&DDplays.plays[handno], &solved.solved[handno]); } }