February 6, 2002 Reading assignment: Deitel and Deitel Chapter 6.1-6.5 -or- Wang 51-56, 175 Issues with programming assignment 3. - Answer these issues about your program before you begin coding 1. How should I represent a card? (What kind of data is a card?) 2. How should I store a hand? 3. How should I store the shuffled deck? 4. How should I search the shuffled deck for the next card? In other words, how will I deal the cards? 5. When I have to display the hands, how will I turn my internal representation for a card into words the user understands? 6. I'll need functions for each hand-type (e.g., straight_flush, full_house, etc) that tells me whether or not I have that hand. How should these functions deal with ties? 7. How will I represent the hand-types? I'll need to store them so I can compare after each hand is evaluated. 8. How will I turn my internal representation of hand-types into words the user understands? 9. How will I deal with ties? It seems like the functions for each hand-type will have to give me some information back to help me break ties. 10. How will I evaluate a hand? 11. How will each of these functions that checks for a specific hand-type work? 12. How will I keep track of how many hands have been played/won? 13. How will I figure out how to quit? 14. How do I figure out when to shuffle? 15. How do I test it so that I'm sure all of the functions work - even the ones that execute rarely? - You have several choices for how to represent a card a. struct Card { int rank; // between 0 and 12, or 1 to 13 if you prefer int suit; // between 0 and 3, or 1 to 4 if you prefer }; b. struct Card { char *rank; // gives index into the character arrays storing the words char *suit; }; c. typedef int Card; // between 0 and 51, in order of card's value - You have several choices for how to store the shuffled deck. Here are two a. As in text, int deck[4][13]. In this array, each row represents a suit and each column represents a rank. The spots in the array correspond to a specific card in the deck, such as the Ace of Spades. The number stored at that spot tells me how deep in the shuffled deck that card is located. To deal, I keep track of which card I'm dealing (I'll be on 11 when I start replacing the user's discards), and search for that number in the array. the row and column locations where I find it tell me what card I'm dealing. Initialize the array so it's in order. If unshuffled, you'll deal the 2 of clubs, then 3 of Clubs, then 4 of Clubs, etc. To shuffle, go through the card array one card at a time. Pick another card at random and swap their locations in the deck. Continue until the end of the deck - each card has been swapped at least once. b. Sort of upside-down and backwards from the other idea. Instead of having a double-indexed array of cards containing the integer locations in the deck, have an single-subscripted array of locations, each one containing a Card. Initialize it as before to be in order, then one by one go through each location, pick another random location, and swap the two cards located there. Structs - Precursor to classes, defines a new type that holds several variables in one chunk. - Example struct Card { int rank; int suit; }; Card c; c.rank = KING; c.suit = SPADES; Card hand[5]; cout << hand[4].suit; Card *Cardptr; Cardptr = &c; Cardptr->rank = DEUCE; Cardptr->suit = HEARTS;