summaryrefslogtreecommitdiffstats
path: root/game.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'game.cpp')
-rw-r--r--game.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/game.cpp b/game.cpp
index 2bfedcd..7e6e866 100644
--- a/game.cpp
+++ b/game.cpp
@@ -256,6 +256,36 @@ bool Game::doWeHaveAnAce(Card **cards)
return false;
}
+void Game::discardAndDraw(Card **cards, int amount, int offset)
+{
+ if (offset + amount > 5)
+ {
+ PRINT_COLOR(ANSI_COLOR_RED, "amount of cards to be discarded is out of bounds!\n");
+ return;
+ }
+
+ int i;
+ /* discard cards starting from offset */
+ for (i = 0; i < amount; i++)
+ {
+#ifdef DEBUG
+ cout << "debug: discarding card " << i+1 << ": " << cards[offset+i]->getType()
+ << " at cards[" << offset << "]" << endl;
+#endif
+ putCardToDiscardPile(cards[offset+i]);
+ }
+
+ /* draw cards from the deck into starting at cards[offset] */
+ for (i = 0; i < amount; i++)
+ {
+ cards[offset+i] = PopCardFromDeck();
+#ifdef DEBUG
+ cout << "debug: drawing card " << i+1 << ": " << cards[offset+i]->getType()
+ << " at cards[" << offset << "]" << endl;
+#endif
+ }
+}
+
void Game::opponentAI(Card **cards)
{
struct countAndSuit tmp;
@@ -275,5 +305,13 @@ void Game::opponentAI(Card **cards)
/* keep 4 cards of the same suit and discard 1 of different suit */
return;
}
+ else if (doWeHaveAnAce(cards))
+ {
+ /* discard 4 cards */
+ }
+ else
+ {
+ /* discard 3 cards */
+ }
}