From 63a098d36fcf53b2cad48d042f6efd3174d93717 Mon Sep 17 00:00:00 2001 From: Kyle K Date: Sat, 29 Jan 2011 19:09:57 -0600 Subject: begun opponentAI --- game.cpp | 26 +++++++++++++++++++++++++- main.cpp | 2 ++ opponent.cpp | 5 +++++ opponent.h | 1 + 4 files changed, 33 insertions(+), 1 deletion(-) diff --git a/game.cpp b/game.cpp index 7e6e866..385ff2f 100644 --- a/game.cpp +++ b/game.cpp @@ -288,30 +288,54 @@ void Game::discardAndDraw(Card **cards, int amount, int offset) void Game::opponentAI(Card **cards) { - struct countAndSuit tmp; + struct countAndSuit tmp = numOfSameSuit(cards); if (pairOrBetter(cards)) { + PRINT_COLOR(ANSI_COLOR_CYAN, "\ndebug: opponentAI, there's a pair or better\n"); /* discard 4 other cards*/ return; } + else if ( (tmp = numOfSameSuit(cards)).count == 5) { + PRINT_COLOR(ANSI_COLOR_CYAN, "\ndebug: opponentAI, 5 cards are of the same suit!\n"); /* keep 5 cards of the same suit */ return; } + else if (tmp.count == 4) { + PRINT_COLOR(ANSI_COLOR_CYAN, "\ndebug: opponentAI, 4 cards are of the same suit\n"); /* keep 4 cards of the same suit and discard 1 of different suit */ + + /* we need to loop through cards[] and find a card with different suit */ + int i; + for (i = 0; i < 5; i++) + { + if (cards[i]->getSuit() != tmp.whatSuit) + break; + } + /* no i should be the index of card that we want to discard */ + + discardAndDraw(cards, 1, i); + return; } + else if (doWeHaveAnAce(cards)) { + PRINT_COLOR(ANSI_COLOR_CYAN, "\ndebug: opponentAI, High Hand with Ace detected\n"); /* discard 4 cards */ + discardAndDraw(cards, 4, 1); + return; } + else { + PRINT_COLOR(ANSI_COLOR_CYAN, "\ndebug: opponentAI, High Hand detected\n"); /* discard 3 cards */ + discardAndDraw(cards, 3, 2); } } diff --git a/main.cpp b/main.cpp index 9fa9d51..a01b1fb 100644 --- a/main.cpp +++ b/main.cpp @@ -62,6 +62,8 @@ int main(int argc, char *argv[]) cout << "Opponents' cards:" << endl; pokerGame->printOpponentCards(pokerGame->numOfOpponents); + //pokerGame->opponentAI + #ifdef DEBUG PRINT_COLOR(ANSI_COLOR_CYAN, "\ndebug: deck after being delt to opponents and user\n"); pokerGame->printPile(); diff --git a/opponent.cpp b/opponent.cpp index 82f297a..8c23478 100644 --- a/opponent.cpp +++ b/opponent.cpp @@ -42,3 +42,8 @@ void Opponent::sortOpponentCards(int opponentsAmount) sortCards(opponentCards[j]); } +Card **Opponent::getOpponentsCards(int whichOpponent) +{ + return opponentCards[whichOpponent]; +} + diff --git a/opponent.h b/opponent.h index f754561..71dc792 100644 --- a/opponent.h +++ b/opponent.h @@ -16,6 +16,7 @@ class Opponent : virtual public CardPile void dealOpponentCards(int); void printOpponentCards(int); void sortOpponentCards(int); + Card **getOpponentsCards(int); }; #endif -- cgit v1.2.3