From 62cf7e0d2fdd07fa87e7dd2fd4c969af7ce0ef54 Mon Sep 17 00:00:00 2001 From: Kyle K Date: Sat, 29 Jan 2011 16:12:55 -0600 Subject: nuke all of DOS control keys, also I made some progress --- game.cpp | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 86 insertions(+), 2 deletions(-) (limited to 'game.cpp') diff --git a/game.cpp b/game.cpp index 390fd82..2bfedcd 100644 --- a/game.cpp +++ b/game.cpp @@ -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; + } } -- cgit v1.2.3