diff options
-rw-r--r-- | game.cpp | 43 | ||||
-rw-r--r-- | main.cpp | 30 |
2 files changed, 26 insertions, 47 deletions
@@ -558,7 +558,7 @@ void Game::userAI(Card **cards) cout << "You have a pair or better and can discard " << howManyUserCanDiscard << " card(s)" << endl; - userDiscardCards(cards, howManyUserCanDiscard); + userDiscardCards(cards, 3); return; } @@ -579,8 +579,7 @@ void Game::userAI(Card **cards) howManyUserCanDiscard = 3; cout << "You have 4 cards of the same suit, you should\n" - << "discard card of the different suit" - << howManyUserCanDiscard << " card(s)" << endl; + << "discard card of the different suit" << endl; userDiscardCards(cards, howManyUserCanDiscard); return; @@ -668,38 +667,16 @@ bool Game::hasTwoPairs(Card **cards) return false; } - char c1, c2; - int ret = 0; - int whitelist[4]; - whitelist[0] = 0; - whitelist[1] = 0; - whitelist[2] = 0; - whitelist[3] = 0; + int *cardsToDiscard = whichCardsToDiscard(cards); + int cnt = 0; - int i, j; + int i; + /* if there are 2 pairs, they should be 1 index that contains 1 */ for (i = 0; i < 5; i++) - { - if (whitelist[i] == 1) - continue; - - c1 = cards[i]->getType()[0]; + if (cardsToDiscard[i] == 1) + cnt++; - for (j = i+1; j < 5; j++) - { - if (whitelist[j] == 1) - continue; - - c2 = cards[j]->getType()[0]; - if (c1 == c2) - { - ret++; - whitelist[j] = 1; - whitelist[i] = 1; - } - } - } - - return (ret != 0); + return (cnt == 1); } /* second param, 0 = user, 1~3 designate opponent */ @@ -771,7 +748,7 @@ void Game::evaluateHand(Card **cards, int who) void Game::showHands(void) { - cout << "User has: " << *hands[getUserHand()] << " " << endl; + cout << "\nUser has: " << *hands[getUserHand()] << " " << endl; int i; for (i = 0; i < numOfOpponents; i++) @@ -38,16 +38,15 @@ int main(int argc, char *argv[]) cout << "\n> Dealing cards to the user" << endl; pokerGame->dealUserCards(); pokerGame->sortUserCards(); - cout << "Cards in your hand: "; - pokerGame->printUserCards(); - pokerGame->userAI(pokerGame->getUserCards()); - cout << "\nFinal cards in your hand: "; - pokerGame->sortUserCards(); - pokerGame->printUserCards(); - cout << "> Dealing cards to opponent(s)" << endl; + cout << "> Dealing cards to opponent(s)" << endl << endl; pokerGame->dealOpponentCards(); pokerGame->sortOpponentCards(); + + cout << "Cards in your hand: "; + pokerGame->printUserCards(); + + pokerGame->userAI(pokerGame->getUserCards()); #ifdef DEBUG PRINT_COLOR(ANSI_COLOR_CYAN, "\ndebug: opponents' cards:\n"); pokerGame->printOpponentCards(); @@ -58,10 +57,16 @@ int main(int argc, char *argv[]) int i; for (i = 0; i < pokerGame->numOfOpponents; i++) pokerGame->opponentAI(i+1); - /* resort the cards after the AI */ pokerGame->sortOpponentCards(); + cout << "\nFinal cards in your hand: "; + pokerGame->sortUserCards(); + pokerGame->printUserCards(); + + cout << "Final opponents' cards:" << endl; + pokerGame->printOpponentCards(); + #ifdef DEBUG PRINT_COLOR(ANSI_COLOR_CYAN, "\ndebug: resorted opponents' cards:\n"); pokerGame->printOpponentCards(); @@ -69,12 +74,9 @@ int main(int argc, char *argv[]) pokerGame->printPile(); #endif - pokerGame->evaluateHand(pokerGame->getUserCards(), i); - - /* evaluate */ - for (i = 0; i < pokerGame->numOfOpponents; i++) - pokerGame->evaluateHand( pokerGame->getOpponentsCards(i+1), i+1 ); - + pokerGame->evaluateHand(pokerGame->getUserCards(), 0); /* user hand */ + for (i = 0; i < pokerGame->numOfOpponents; i++) /* opponents hands */ + pokerGame->evaluateHand(pokerGame->getOpponentsCards(i+1), i+1); pokerGame->showHands(); /* ask to repeat the game and reset the deck of cards */ |