Page 1 of 1

Card representation again...

Posted: Mon Jun 11, 2007 8:14 am
by Zacariaz
ive tryed askin before, now i try again.

This seems to be a good start: (need only to hold 7 cards)

Code: Select all

enum {S, H, D, C, A =1, J  10, Q = 11, K = 12};
struct {unsigned Color:2; unsigned Value:4;} Cards[7];
But still it seems a better way would be some sort of wraping array to sort out the buisness with the ace, but how?

any comments?

Posted: Mon Jun 11, 2007 8:37 am
by os64dev
well i'd represent a card as an object.

Code: Select all

class Card {
    enum Type { Diamond, Spades, Hearts, Clubs };
    enum Face { One=1, Two=2, Three=3 ... Jack = 10, Queen = 11, King = 12, Ace = 11; 
    Type    _type;
    Face    _face;

    int getValue(void) { return((int)_face); }
}

class Hand {
    Card[7]    _cards; //- better to use template btw instead of 7.
}

class Deck {
     Card[13*4]    _deck;
}

class Game {
    //- behavioural changes for each hand.
}
the behavour of the ace is different between games and should therefor be handled outside the card object. for instance if you want a total of your hand you could sum all the values of the cards and count the number of aces, then the possible totals are the sum and minus 10 for each chosen ace.

Posted: Mon Jun 11, 2007 9:27 am
by Zacariaz
ok, looks reasonable.

thanks