int actDealer(struct player anyone, struct card *aDeck, int *counter, int pullLimit){ // char choice = 'h'; int stay = 1; printf("%s TURN:\n", anyone.name); printCards(anyone.playerHand, anyone.startCards); checkHand(anyone.playerHand, anyone.startCards, &anyone.cardValue); /* Players */ if(pullLimit == 21){ if(anyone.cardValue == 21 && anyone.startCards == 2){ // check if Black Jack printf("BLACK JACK!\n"); stay = 0; } while(choice == 'h' && stay == 1){ // gives,prints and updates card values while player types 'h' printf("Hit or stay? (h/s)\n"); scanf("%c",&choice); getchar(); if(choice == 'h' && anyone.cardValue <= 20){ dealCards(&anyone, aDeck, counter); printCards(anyone.playerHand, anyone.startCards); checkHand(anyone.playerHand, anyone.startCards, &anyone.cardValue); if(anyone.cardValue > 20 || anyone.cardValue == -1)// if player is busted leave loop stay = 0; } } } /* Dealer */ while(pullLimit < 18 && stay){ while(anyone.cardValue < 16){ // dealer has to pull until cardvalue > 16 printf("Press enter to see next card\n"); getchar(); dealCards(&anyone, aDeck, counter); printCards(anyone.playerHand, anyone.startCards); checkHand(anyone.playerHand, anyone.startCards, &anyone.cardValue); } stay = 0; } return anyone.cardValue; // update cardvalue }
void simGame (FILE *f, int numPlayers, int numGames) { cardType deck[NUM_CARDS]; handType players[numPlayers]; createDeck(deck); int winners[numPlayers]; int numWinners; char *type[] = {"Bust", "Pair", "Two Pair", "Three of a Kind", "Straight", "Flush", "Full House", "Four of a Kind", "Straight Flush", "Royal Flush"}; char suitSym [] = {'H', 'D', 'S', 'C'}; for (int i = 0; i < numGames; i++) { shuffleDeck (deck); numWinners = 0; fprintf (f, "GAME %i", i + 1); for (int j = 0; j < numPlayers; j++) { fprintf (f, "\nPlayer %i's hand: ", j + 1); for (int k = 0; k < HAND_SIZE; k++) { players[j].cards[k] = deck[j * HAND_SIZE + k]; fprintf (f, "%i%c ", players[j].cards[k].rank + 1, suitSym[players[j].cards[k].suit]); } checkHand (&players[j]); fprintf (f, "(%s)", type[players[j].type]); if (j == 0) { winners[0] = j; numWinners = 1; } else if (players[j].type > players[winners[numWinners - 1]].type || (players[j].type == players[winners[numWinners - 1]].type && players[j].value > players [winners[numWinners - 1]].value)) { winners[0] = j; numWinners = 1; } else if (players[j].type == players [winners[numWinners - 1]].type && players[j].value == players [winners[numWinners - 1]].value) { winners [numWinners++] = j; } } fprintf (f, "\nThe %s ", (numWinners == 1)? "winner is" : "winners are"); for (int j = 0; j < numWinners; j++) { fprintf (f, "%splayer %i", j == 0? "" : " and ", winners[j] + 1); } fprintf (f, "!\n\n"); } }
void GuideManager::nextStep(int step) { CCLOG("step = %d",step); const StepInfo& stepInfo = m_vecStep.at(step); if (getWait()) { return; } if (isLimit(stepInfo)) { return; } m_guideLayer->removeFromParent(); getParent()->addChild(m_guideLayer, GUIDE_LAYER_ZORDER); if (stepInfo.getNextStepId() == END) { endGuide(); return; } else if (stepInfo.getNextStepId() == WAIT) { setWait(true); } else if (stepInfo.getNextStepId() == SLEEP) { getGuideLayer()->sleep(); } else if (stepInfo.getNextStepId() == WAKE) { getGuideLayer()->wake(); } // by order checkDialog(stepInfo); checkRect(stepInfo); checkTalk(stepInfo); checkHand(stepInfo); checkEvent(stepInfo); setNextStepId(step + 1); }
// evalALlHands generates and evaluates all possible hand combinations, stores the results in the results array, and then returns the total number of hands (combinations) int evalAllHandsHelper (cardType *deck, handType *hand, int*results, int place, int numChosen) { if (numChosen == HAND_SIZE) { checkHand (hand); results[hand->type]++; return 1; } else { int total = 0; for (int i = place; i < NUM_CARDS; i++) { hand->cards[numChosen] = deck[i]; total += evalAllHandsHelper (deck, hand, results, i + 1, numChosen + 1); } return total; } }