Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <stdlib.h>
- #include <time.h>
- using namespace std;
- void DisplayCards(vector<int> &aliveCards, vector<int> &deadCards, int score)
- {
- cout << "Current score: " << score << endl;
- cout << "Dead cards:";
- for (int i = 0; i < deadCards.size(); i++)
- {
- cout << " " << deadCards.at(i);
- }
- cout << endl;
- cout << "Live cards:";
- for (int i = 0; i < aliveCards.size(); i++)
- {
- cout << " " << aliveCards.at(i);
- }
- cout << endl;
- }
- void RemoveCard(vector<int> &aliveCards, vector<int> &deadCards, int location)
- {
- int smallestCard, temp;
- deadCards.push_back(aliveCards.at(location));
- aliveCards.erase(aliveCards.begin() + location);
- for (int i = 0; i < deadCards.size(); i++)
- {
- smallestCard = i;
- for (int j = 0; j < deadCards.size(); j++)
- {
- if (deadCards.at(j) < deadCards.at(smallestCard))
- {
- smallestCard = j;
- }
- }
- temp = deadCards.at(i);
- deadCards.at(i) = deadCards.at(smallestCard);
- deadCards.at(smallestCard) = temp;
- }
- }
- void PickCard(vector<int> &aliveCards, vector<int> &deadCards, int maxCard, int ¤tCard)
- {
- srand(time(NULL));
- if (aliveCards.size() > 1)
- {
- currentCard = rand() % (aliveCards.size() - 1);
- }
- else
- {
- currentCard = 0;
- }
- if (aliveCards.at(currentCard) > maxCard)
- {
- cout << "Next card: " << aliveCards.at(currentCard) << endl;
- cout << endl;
- }
- else
- {
- cout << "Next card: " << aliveCards.at(currentCard) << " dead" << endl;
- RemoveCard(aliveCards, deadCards, currentCard);
- cout << endl;
- }
- }
- int main()
- {
- int maxCard = 0;
- vector<int> aliveCards{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
- vector<int> deadCards;
- int score = 0;
- char choice;
- int currCardE = 0;
- while (aliveCards.size() > 0)
- {
- do
- {
- DisplayCards(aliveCards, deadCards, score);
- PickCard(aliveCards, deadCards, maxCard, currCardE);
- if (aliveCards.size() == 0)
- {
- break;
- }
- } while (aliveCards.at(currCardE) < maxCard);
- cout << endl;
- cout << "Take it [T] or Leave it [L]? ";
- cin >> choice;
- cout << endl;
- choice = toupper(choice);
- switch (choice)
- {
- case 'T':
- maxCard = aliveCards.at(currCardE);
- score += aliveCards.at(currCardE);
- RemoveCard(aliveCards, deadCards, currCardE);
- break;
- case 'L':
- RemoveCard(aliveCards, deadCards, currCardE);
- break;
- default:
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement