// MAR 3/19/00 Main for Assignment 6 in Data Structures // Written by Michael Redmond 3/19/00 // La Salle University # include //# include #include #include #include "card.h" #include "deck.h" using namespace std; void Show(vector & all) { // show the cards for (int j = 0; j < all.size(); j++ ){ cout << endl << " " << all[j]; } cout << endl; return; } bool aFace(const Card & currCard) { if (currCard.isFace() ) { return true; } else { return false; } } int main () { Deck theDeck; // create and shuffle the deck theDeck.shuffle(); cout << "Deck is shown for debugging and checking " << endl; theDeck.Show(); // show it for checking out vector hand1; // create the two vector hand2; // hands // deal them 5 cards for (int cnt = 0; cnt < 5; cnt++) { Card newOne = theDeck.draw(); hand1.push_back(newOne); newOne = theDeck.draw(); hand2.push_back(newOne); } // show the hands cout << endl << "Hand1: " << endl; Show(hand1); cout << endl << "Hand2: " << endl; Show(hand2); // reverse the hands reverse(hand1.begin(),hand1.end()); reverse(hand2.begin(),hand2.end()); // show the hands cout << endl << "Hand1 reversed: " << endl; Show(hand1); cout << endl << "Hand2 reversed: " << endl; Show(hand2); // report the number of face cards in each hand int numFace1 = count_if(hand1.begin(),hand1.end(),aFace); int numFace2 = count_if(hand2.begin(),hand2.end(),aFace); cout << "Hand 1 has " << numFace1 << " face cards " << endl; cout << "Hand 2 has " << numFace2 << " face cards " << endl; // report the high and low cards in each hand //Card hiCard1 = max_element(hand1.begin(),hand1.end()); //Card hiCard1 = max_element(hand1,hand1+hand1.size()); //Card hiCard2 = max_element(hand2.front(),hand2.back()); //Card loCard1 = min_element(hand1.front(),hand1.back()); //Card loCard2 = min_element(hand2.front(),hand2.back()); //cout << "Hand 1 has high card: " << hiCard1 << " and low card: " << loCard1 << endl; //cout << "Hand 2 has high card: " << hiCard2 << " and low card: " << loCard2 << endl; // sort the two hands sort(hand1.begin(),hand1.end()); // sorts from high to low sort(hand2.begin(),hand2.end()); // sorts from high to low // reverse the hands so that high is last //reverse(hand1.begin(),hand1.end()); // reverse so high card last //reverse(hand2.begin(),hand2.end()); // reverse so high card last // show the hands cout << endl << "Hand1: " << endl; Show(hand1); cout << endl << "Hand2: " << endl; Show(hand2); ///////////////////// // get cards to play ///////////////////// Card card1 = hand1.back(); // get last card cout << "Hand 1 played: " << card1 << endl; //"( " << *(hand1.end()) << " )" << endl; if (! theDeck.isEmpty() ) { // replace the card if the deck has any more cards Card newCard = theDeck.draw(); cout << "replaced with: " << newCard << endl; // hand1.push_back(newCard); replace(hand1.begin(),hand1.end(),card1,newCard); } Card card2 = hand2.back(); // get last card cout << "Hand 2 played: " << card2 << endl; if (! theDeck.isEmpty() ) { // replace the card if the deck has any more cards Card newCard = theDeck.draw(); cout << "replaced with: " << newCard << endl; hand2.pop_back(); hand2.push_back(newCard); } // show the hands cout << endl << "Hand1: " << endl; Show(hand1); cout << endl << "Hand2: " << endl; Show(hand2); return 0; } /* skipped to keep assignment short while ((! hand1.empty() ) && (! hand2.empty() ) ) { // sort the two hands sort(hand1.begin(),hand1.end()); // sorts from high to low sort(hand2.begin(),hand2.end()); // sorts from high to low // reverse the hands so that high is last reverse(hand1.begin(),hand1.end()); // reverse so high card last reverse(hand2.begin(),hand2.end()); // reverse so high card last ///////////////////// // get cards to play ///////////////////// Card card1 = hand1.pop_back(); // take last card off if (! theDeck.isEmpty() ) { // replace the card if the deck has any more cards Card newCard = theDeck.Draw(); hand1.push_back(newCard); } Card card2 = hand2.pop_back(); // take last card off if (! theDeck.isEmpty() ) { // replace the card if the deck has any more cards Card newCard = theDeck.Draw(); hand2.push_back(newCard); } // check cards against each other // wait they found this hairy before } return 0; } */