Created
October 3, 2024 06:48
-
-
Save sidsbrmnn/19c171c220440ecbc2935e6b0a36d651 to your computer and use it in GitHub Desktop.
Go Fish Boilerplate for CS 396
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <algorithm> | |
| #include <cstdlib> | |
| #include <ctime> | |
| #include <iostream> | |
| #include <map> | |
| #include <random> | |
| #include <string> | |
| #include <vector> | |
| using namespace std; | |
| enum Rank { | |
| TWO = 2, | |
| THREE, | |
| FOUR, | |
| FIVE, | |
| SIX, | |
| SEVEN, | |
| EIGHT, | |
| NINE, | |
| TEN, | |
| JACK, | |
| QUEEN, | |
| KING, | |
| ACE | |
| }; | |
| enum Suit { HEARTS, DIAMONDS, CLUBS, SPADES }; | |
| struct Card { | |
| Rank rank; | |
| Suit suit; | |
| // Print out a card (e.g., "5H" for Five of Hearts) | |
| friend ostream &operator<<(ostream &os, const Card &card) { | |
| const string ranks[] = {"2", "3", "4", "5", "6", "7", "8", | |
| "9", "10", "J", "Q", "K", "A"}; | |
| const string suits[] = {"H", "D", "C", "S"}; | |
| // This will format the card nicely when printing. | |
| } | |
| }; | |
| class Deck { | |
| private: | |
| vector<Card> cards; | |
| // Function to shuffle the deck | |
| void shuffle() { | |
| // Shuffle the deck randomly using std::shuffle. | |
| } | |
| public: | |
| // Constructor to initialize the deck with all cards and shuffle them | |
| Deck() { | |
| // Fill the deck with all 52 cards and shuffle them. | |
| } | |
| // Function to draw a card from the deck | |
| Card draw() { | |
| // Draw a card from the back of the deck and return it. | |
| } | |
| // Check if the deck is empty | |
| bool empty() const { | |
| // Return true if the deck is empty, false otherwise. | |
| } | |
| }; | |
| class Player { | |
| public: | |
| vector<Card> hand; | |
| map<Rank, int> rank_count; | |
| // Function for the player to draw a card from the deck | |
| void draw_card(Deck &deck) { | |
| // Draw a card from the deck and add it to the player's hand. | |
| } | |
| // Function to check if the player has cards of a specific rank | |
| bool has_rank(Rank rank) const { | |
| // Check if the player has any cards of the given rank. | |
| } | |
| // Function to remove all cards of a specific rank from the player's hand | |
| vector<Card> remove_rank(Rank rank) { | |
| // Remove all cards of the specified rank from the hand and return | |
| // them. | |
| } | |
| // Function to check if the player has a set of four cards of the same rank | |
| bool check_for_set() { | |
| // Check if the player has collected a set of four cards of the | |
| // same rank. | |
| } | |
| // Function to add cards to the player's hand | |
| void add_cards(const vector<Card> &cards) { | |
| // Add a group of cards to the player's hand. | |
| } | |
| }; | |
| class Game { | |
| private: | |
| Deck deck; | |
| Player human; | |
| Player computer; | |
| int human_score; | |
| int computer_score; | |
| // Function to deal the initial cards to players | |
| void deal_initial_cards() { | |
| // Draw 7 cards for both human and computer at the start of the | |
| // game. | |
| } | |
| // Function to handle the human's turn | |
| void human_turn() { | |
| // Get the human's request, check if the computer has the rank, | |
| // transfer cards if available, or go fish if not. | |
| // Call human.check_for_set() to check if the human made a set and update | |
| // the score. | |
| } | |
| // Function to handle the computer's turn | |
| void computer_turn() { | |
| // Randomly select a rank the computer has and request it from the | |
| // human, transfer cards if available, or go fish if not. Call | |
| // computer.check_for_set() to check if the computer made a set and update | |
| // the score. | |
| } | |
| // Function to get the rank the human requests | |
| Rank get_human_request() { | |
| // Prompt the user to input a rank and return it. | |
| } | |
| // Function to randomly pick a rank the computer requests | |
| Rank get_computer_request() { | |
| // Randomly pick a rank from the computer's hand to request from | |
| // the human. | |
| } | |
| // Function to display the player's hand | |
| void show_hand(const vector<Card> &hand) const { | |
| // Loop through the hand and print the cards. | |
| } | |
| public: | |
| // Constructor to initialize the game | |
| Game() : human_score(0), computer_score(0) { deal_initial_cards(); } | |
| // Main game loop | |
| void play() { | |
| // Run the game loop until the deck is empty and both players have | |
| // no cards. Alternate between human_turn() and computer_turn(), and display | |
| // the scores at the end. | |
| } | |
| }; | |
| int main(void) { | |
| srand(static_cast<unsigned>(time(nullptr))); | |
| // Create the game object and start the game | |
| Game game; | |
| game.play(); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment