diff options
author | Kyle K <kylek389@gmail.com> | 2011-01-29 16:12:55 -0600 |
---|---|---|
committer | Kamil Kaminski <kamilkss@gmail.com> | 2011-01-29 16:12:55 -0600 |
commit | 62cf7e0d2fdd07fa87e7dd2fd4c969af7ce0ef54 (patch) | |
tree | 63de4d26514e50c94d3726a180655102214ac712 /game.cpp | |
parent | dcfd43f8f48072754b9d952b621bac1cddbb7103 (diff) | |
download | poker-62cf7e0d2fdd07fa87e7dd2fd4c969af7ce0ef54.tar.gz poker-62cf7e0d2fdd07fa87e7dd2fd4c969af7ce0ef54.tar.bz2 poker-62cf7e0d2fdd07fa87e7dd2fd4c969af7ce0ef54.zip |
nuke all of DOS control keys, also I made some progress
Diffstat (limited to 'game.cpp')
-rw-r--r-- | game.cpp | 88 |
1 files changed, 86 insertions, 2 deletions
@@ -9,6 +9,7 @@ /* forward declaration of hands array, very interesting, I didn't know C++ needs this */ string *Game::hands[10]; +string *Game::suits[5]; Game::Game(void) { @@ -21,7 +22,13 @@ Game::Game(void) hands[6] = new string("Three of a Kind"); hands[7] = new string("Two Pair"); hands[8] = new string("One Pair"); - hands[9] = new string("High Card"); + hands[9] = new string("High Card"); + + suits[0] = new string("Undefined"); + suits[1] = new string("Clubs"); + suits[2] = new string("Diamonds"); + suits[3] = new string("Hearts"); + suits[4] = new string("Spades"); } void Game::shufflePile(void) @@ -95,7 +102,7 @@ void Game::repeatGame(bool *quit) cout << endl; while (continueAsking) { - cout << "Play again? (y/n) "; + PRINT_COLOR(ANSI_COLOR_GREEN, "Play again? (y/n) "); cin >> play_again; play_again = tolower(play_again); @@ -184,12 +191,89 @@ int Game::numOfSameCards(Card **cards) return max; } +struct countAndSuit Game::numOfSameSuit(Card **cards) +{ + int max = 0; + enum Suit tmpSuit = Undef; + + struct countAndSuit same[4] = + { + { Clubs, 0}, + { Diamond, 0 }, + { Hearts, 0 }, + { Spades, 0 }, + }; + + /* go through all cards and count how many there is of each suit */ + int i; + for (i = 0; i < 5; i++) + { + tmpSuit = cards[i]->getSuit(); + + switch (tmpSuit) + { + case Clubs: + same[0].count += 1; + break; + case Diamond: + same[1].count += 1; + break; + case Hearts: + same[2].count += 1; + break; + case Spades: + same[3].count += 1; + break; + default: + cout << "could not determine the suit of the card" << endl; + } + } + + int whereMaxWasFound = 0; + /* look for the max number of cards of the same suit */ + for (i = 0; i < 4; i++) + if (same[i].count > max) + { + max = same[i].count; + whereMaxWasFound = i; + } + + return same[whereMaxWasFound]; +} + +bool Game::doWeHaveAnAce(Card **cards) +{ + char c; + + int i; + for (i = 0; i < 5; i++) + { + c = cards[i]->getType()[0]; + if (c == 'A') + return true; + } + + return false; +} + void Game::opponentAI(Card **cards) { + struct countAndSuit tmp; + if (pairOrBetter(cards)) { /* discard 4 other cards*/ return; } + else if ( (tmp = numOfSameSuit(cards)).count == 5) + { + /* keep 5 cards of the same suit */ + return; + } + else if (tmp.count == 4) + { + /* keep 4 cards of the same suit and discard 1 of different suit */ + return; + } } |