#include <iostream> #include <vector> #include <algorithm> #include <ctime> using namespace std; // ANSI color codes #define RED "\033[31m" #define GREEN "\033[32m" #define YELLOW "\033[33m" #define BLUE "\033[34m" #define MAGENTA "\033[35m" #define RESET "\033[0m" vector<string> generateDeck() { vector<string> deck; char types[] = {'A', 'B', 'C', 'D', 'E'}; for (char type : types) { for (int i = 1; i <= 12; i++) { deck.push_back(string(1, type) + to_string(i)); } } return deck; } int getCardValue(string card) { } char getCardType(string card) { return card[0]; } string getColoredCard(string card) { char type = getCardType(card); string color; switch (type) { case 'A': color = RED; break; case 'B': color = GREEN; break; case 'C': color = YELLOW; break; case 'D': color = BLUE; break; case 'E': color = MAGENTA; break; default: } } bool hasType(const vector<string> &player, char type) { for (const auto &card : player) { if (getCardType(card) == type) return true; } return false; } int main() { vector<string> deck = generateDeck(); vector<string> player(deck.begin(), deck.begin() + 6); vector<string> ai(deck.begin() + 6, deck.begin() + 12); int playerPoints = 0, aiPoints = 0; for (int i = 0; i < 6; i++) { cout << "\nYour remaining cards: "; for (auto card : player) cout << getColoredCard(card) << " "; cout << "\n"; cout << "\nRound " << i + 1 << "\n"; cout << "AI plays: " << getColoredCard(ai[i]) << "\n"; char aiType = getCardType(ai[i]); int aiValue = getCardValue(ai[i]); cout << "Choose a card to play"; if (hasType(player, aiType)) cout << " of type " << aiType; cout << ": "; string chosenCard; bool validChoice = false; while (!validChoice) { cin >> chosenCard; { if (getCardType(chosenCard) == aiType || !hasType(player, aiType)) { validChoice = true; if (getCardValue(chosenCard) > aiValue) { cout << "You win this round!\n"; playerPoints++; } else { cout << "AI wins this round!\n"; aiPoints++; } player.erase(it); } else { cout << "Invalid choice. Pick a valid " << aiType << " card: "; } } else { cout << "Invalid choice. Choose a card from your deck: "; } } } cout << "\nGame Over!\n"; cout << "Your Points: " << playerPoints << "\n"; cout << "AI Points: " << aiPoints << "\n"; if (playerPoints > aiPoints) cout << "You Win!\n"; else if (playerPoints < aiPoints) cout << "AI Wins!\n"; else cout << "It's a Tie!\n"; return 0; }
Standard input is empty
#include <iostream> #include <vector> #include <algorithm> #include <ctime> using namespace std; // ANSI color codes #define RED "\033[31m" #define GREEN "\033[32m" #define YELLOW "\033[33m" #define BLUE "\033[34m" #define MAGENTA "\033[35m" #define RESET "\033[0m" vector<string> generateDeck() { vector<string> deck; char types[] = {'A', 'B', 'C', 'D', 'E'}; for (char type : types) { for (int i = 1; i <= 12; i++) { deck.push_back(string(1, type) + to_string(i)); } } random_shuffle(deck.begin(), deck.end()); return deck; } int getCardValue(string card) { return stoi(card.substr(1)); } char getCardType(string card) { return card[0]; } string getColoredCard(string card) { char type = getCardType(card); string color; switch (type) { case 'A': color = RED; break; case 'B': color = GREEN; break; case 'C': color = YELLOW; break; case 'D': color = BLUE; break; case 'E': color = MAGENTA; break; default: color = RESET; } return color + card + RESET; } bool hasType(const vector<string> &player, char type) { for (const auto &card : player) { if (getCardType(card) == type) return true; } return false; } int main() { srand(time(0)); vector<string> deck = generateDeck(); vector<string> player(deck.begin(), deck.begin() + 6); vector<string> ai(deck.begin() + 6, deck.begin() + 12); int playerPoints = 0, aiPoints = 0; for (int i = 0; i < 6; i++) { cout << "\nYour remaining cards: "; for (auto card : player) cout << getColoredCard(card) << " "; cout << "\n"; cout << "\nRound " << i + 1 << "\n"; cout << "AI plays: " << getColoredCard(ai[i]) << "\n"; char aiType = getCardType(ai[i]); int aiValue = getCardValue(ai[i]); cout << "Choose a card to play"; if (hasType(player, aiType)) cout << " of type " << aiType; cout << ": "; string chosenCard; bool validChoice = false; while (!validChoice) { cin >> chosenCard; auto it = find(player.begin(), player.end(), chosenCard); if (it != player.end()) { if (getCardType(chosenCard) == aiType || !hasType(player, aiType)) { validChoice = true; if (getCardValue(chosenCard) > aiValue) { cout << "You win this round!\n"; playerPoints++; } else { cout << "AI wins this round!\n"; aiPoints++; } player.erase(it); } else { cout << "Invalid choice. Pick a valid " << aiType << " card: "; } } else { cout << "Invalid choice. Choose a card from your deck: "; } } } cout << "\nGame Over!\n"; cout << "Your Points: " << playerPoints << "\n"; cout << "AI Points: " << aiPoints << "\n"; if (playerPoints > aiPoints) cout << "You Win!\n"; else if (playerPoints < aiPoints) cout << "AI Wins!\n"; else cout << "It's a Tie!\n"; return 0; }