Go fish deck initialization in C++

This is a discussion on Go fish deck initialization in C++ within the C++ Programming forums, part of the General Programming Boards category; I am new and not sure how to post but I am trying to build a go fish program and ...

  1. #1
    Registered User
    Join Date
    Nov 2012
    Location
    Lorain Ohio
    Posts
    3

    Go fish deck initialization in C++

    I am new and not sure how to post but I am trying to build a go fish program and am trying to build the deck. Is this the best way to do it. This is what I have at this point.

    Code:
    #ifndef gofish_h
    #define gofish_h
    
    
    class gofish
    {
    
    public:
    
    
    
    
    
    private: 
    
    
    char deck[52]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,
                31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52};
    
    
    1=AS;  8=8S;
    2=2S;
    3=3S;
    4=4S;
    5=5S;
    6=6S;
    7=7S;
               9=9S;
               10=10S;
               11=JS;
               12=QS;
               13=KS;
               14=AC;
               15=2C;
               16=3C;
               17=4C
    
    player_onehand[25];
    
    player_twohand[25];
    
    int P1_book;
    int P2_book;
    int P1_book;
    int P2_book;
    void int_deck(); // put cards in to deck
    void int_players_deck(); // put 7 cards in to two playrs hands
    
    
    };
    #endif

  2. #2
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,622
    Yeah a simple array of numbers from 1 to 52 is a great representation. As long as you can verify pairs, just about anything can be called "the best way to do it" though.

  3. #3
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,288
    Well first off, as you may no doubt know, this will not compile. The reasons being:
    You cannot initialise an array that is a member variable, like that. Instead you would need to use a constructor and a loop.
    You cannot redefine the numeric constants 1 through 17 to be some other things which are unparseable tokens. I.e all variable names must start with a letter or underscore.
    You cannot declare multiple varaibles with the same name within a class.

    Having said all that, the idea itself, of simply storing a numeric value from 1 to 52 to represent each card is fine.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Trying to make a deck of cards.
    By Jesse20ghet in forum C++ Programming
    Replies: 1
    Last Post: 11-07-2011, 02:44 PM
  2. Shuffling a deck?
    By Neo1 in forum C++ Programming
    Replies: 23
    Last Post: 07-16-2007, 01:21 AM
  3. Deck Shuffle
    By pjharris in forum C++ Programming
    Replies: 51
    Last Post: 01-06-2006, 03:59 PM
  4. Translators and Fish Farts
    By novacain in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 11-11-2003, 10:38 AM
  5. Evil Fish
    By RoD in forum A Brief History of Cprogramming.com
    Replies: 29
    Last Post: 07-10-2003, 10:27 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21