diff --git a/assignmentOne/go_fish b/assignmentOne/go_fish index f6ff91b..646be19 100755 Binary files a/assignmentOne/go_fish and b/assignmentOne/go_fish differ diff --git a/assignmentOne/go_fish.cpp b/assignmentOne/go_fish.cpp index 227c8cd..bda2c1d 100644 --- a/assignmentOne/go_fish.cpp +++ b/assignmentOne/go_fish.cpp @@ -90,6 +90,11 @@ class Card // return cardNumericalValue; } + char getCardRawValue() + { + // + return cardValue; + } char getCardSuit() { // @@ -99,6 +104,21 @@ class Card { return fullCard; } + friend bool operator==(const Card &cardOne, const Card &cardTwo) + { + // compare cardOne's value to cardTwo's value. + // THIS WILL ONLY CHECK NUMERICAL VALUE + // If I was doing this for a REAL card game, I would add an + // && (cardOne.cardSuit == cardTwo.cardSuit) + // to make sure that the suit AND value are the same. + return (cardOne.cardNumericalValue == cardTwo.cardNumericalValue); + } + friend bool operator<(const Card &cardOne, const Card &cardTwo) + { + // compare cardOne's value to cardTwo's value with less than function. + // THIS WILL ONLY CHECK NUMERICAL VALUE + return (cardOne.cardNumericalValue < cardTwo.cardNumericalValue); + } private: char cardValue; char cardSuit; @@ -107,8 +127,8 @@ class Card }; // function prototypes -int humanTurn(vector &human, vector &computer); -int computerTurn(vector &human, vector &computer); +int humanTurn(vector &human, vector &computer, vector &cardDeck); +int computerTurn(vector &human, vector &computer, vector &cardDeck); // main program int main(int argc, char **argv) @@ -153,12 +173,22 @@ int main(int argc, char **argv) computerHand.push_back(deck.back()); deck.pop_back(); } + // tell the user the game has started. + cout << "Game Start." << endl; + // output the human's hand to the screen + cout << "Here is your starting hand:" << endl << "| "; + int handSize = humanHand.size(); + for(int handDisplayIterator = 0; handDisplayIterator < handSize; handDisplayIterator++) + { + cout << humanHand[handDisplayIterator].getFullCard() << " | "; + } + cout << endl; // main gameplay loop (while?) while(currentNumSets != 13) { // switch back and forth between human and computer. - currentNumSets = currentNumSets + humanTurn(humanHand, computerHand); - currentNumSets = currentNumSets + computerTurn(humanHand, computerHand); + currentNumSets = currentNumSets + humanTurn(humanHand, computerHand, deck); + currentNumSets = currentNumSets + computerTurn(humanHand, computerHand, deck); } // return 0 return 0; @@ -185,7 +215,7 @@ Device Input/Device: ??? Device Output/Monitor: ??? Dependencies: ??? */ -int humanTurn(vector &human, vector &computer) +int humanTurn(vector &human, vector &computer, vector &cardDeck) { /* Handles the human’s turn. It will prompt the player to ask for a card rank/number and @@ -194,11 +224,53 @@ int humanTurn(vector &human, vector &computer) card. The function should return the number of sets collected during the turn */ + int numSets = 0; + int maxCountCard = 0; + char inputChar; + bool foundCard = false; // ask for card rank/number/value - // if card is in hand, + cout << "Your turn. Ask for a card (2-9, J/Q/K/A): " << endl; + cin.ignore(); + cout << ">"; + cin >> inputChar; + Card valueOnlyCard(inputChar, 'X'); + // if card is in opposite hand, remove from and give to the other. (loop through computer hand looking for card) + for(int checkHandIterator = 0; checkHandIterator < computer.size(); checkHandIterator++) + { + // checking if value of card is equal to any of the other ones. + if(computer[checkHandIterator].getCardRawValue() == inputChar) + { + // copy the card into the human's hand. + human.push_back(computer[checkHandIterator]); + // set the card find to true. + foundCard = true; + } + } + // remove the cards that had been drawn from the other hand (use remove/remove if and erase with the vector iterators) + // NOTE: https://stackoverflow.com/questions/72179264/classes-remove-a-specific-object-from-a-vector-of-objects + if(foundCard) + { + // remove cards if found + computer.erase(remove_if(computer.begin(), computer.end(), [&](Card &remCard){return remCard.getCardValue() == inputChar;}), computer.end()); + } + // if not, draw a card from the top of the deck. + else + { + // draw a card if not found. + human.push_back(cardDeck.back()); + cardDeck.pop_back(); + } + // check to see if sets exist in the vector, aka is there four of a value. + // if there is four of a value, increase the number of sets to return, remove the cards from hand. + // NOTE: https://stackoverflow.com/questions/39906504/how-to-count-duplicates-in-a-vector-c + for (int setCounter = 0; setCounter < human.size(); setCounter++) + { + /* code */ + } + // return the number of sets - return 0; + return numSets; } /* @@ -211,7 +283,7 @@ Device Input/Device: ??? Device Output/Monitor: ??? Dependencies: ??? */ -int computerTurn(vector &human, vector &computer) +int computerTurn(vector &human, vector &computer, vector &cardDeck) { /* Handles the computer’s turn and it should do the same actions as the human but for the diff --git a/assignmentOne/maze b/assignmentOne/maze index 4361153..db96fb6 100755 Binary files a/assignmentOne/maze and b/assignmentOne/maze differ