We help IT Professionals succeed at work.

# Card Game in Dev C++

on
Medium Priority
2,244 Views
Hi,

I'm developing a card game in Dev C++ with OpenGL support, which uses 310 cards [8 decks of cards]. I need to distribute 10 cards each to 7 players. Out of which , 6 are robots and one human player.
Also our card sets ony contain A,2,3,4,5,6,7, J,Q & K.[10 cards only]

40 cards in each deck and from one deck all the spades are removed.(320-10=310).

Our game has certain meld conditions [all minimum three cards]

S->spade, D ->diamond, C ->clubs , H ->hearts
1)same rank, same suit. eg [3S,3S,3S] , [JD,JD,JD] , [AC,AC,AC] etc.
2)Same rank different suit eg [3S,3C,3D] , [4S,4H,4D] etc.

The game has some rope conditions also

1) same suit and in sequence eg [AS,2S,3S] , [6D,7D,JD] , [2H,3H,4H] etc.
2) For the case of A and K, two cards of same suit and one or more from any suit.

I need to distribute 10 cards each to all the 7 players and keep the remaining cards in the "Muck."
The game allow each player to pull one card from the Muck or the player can take discarded card from the previous player, immediately after discard, if he can make a meld or rope with that card.
After taking the card he need to discard one card.

The win of game is to make all the 10 cards plus the last drawn card [total 11] to move to a meld zone[meld or rope conditions need to satisfy].
The game has many rounds , each round the player can take a card and discard another as said above.

Can you plz suggest a way to compare the meld and rope conditions if we are using an indexed arrays for 310 cards.

eg: GLCard[310] = {};// I dont know how to proceedu with

Players cards are of 10 in count - and 7 players.

its like P1[10],P2[10],P3[10],P4[10],P5[10],P6[10],P7[10] - TOTAL 70 cards

So card in Muck now is 310 - 70 = 240

How can I compare the cards in hand with total cards to find a meld or rope condition?
Once I found the condition, how do I move that cards from players hand array [P1,P2 etc] to meld zone?

Any help appreciated. I'll defenitely respond for each reply.

Thanks,
Kishore
NajSoft India Solutions

Comment
Watch Question

## View Solution Only

CERTIFIED EXPERT

Commented:
hi najsoftindia,

comparing cards is much more easy, if you have the players cards sorded. you need to introduce any kind of sorting mechanism, this could be easily done with a std::set or std::map, all you need to know is the card's-score.
you should create all the cards in a pool, where they are instanziated. then only use pointers to it. the "players hand" should be a array/container, which holds this pointers to the cards pool.
didn't really understand the game-rules, so i cant halp on that ...

good luck :)
ike
CERTIFIED EXPERT
Commented:
have a look at this:

>>>>>>>>> code begin >>>>>>>>>>>>

enum CardValue
{
// the ordering can be used to find cards-score, first has 0,
// second has 2 and so on, modify it for your specifications
CV_Ace, CV_2, CV_3, CV_4, CV_5, CV_6, CV_7, CV_Jack, CV_Queen, CV_King
};

enum CardColor
{
// the ordering can be used to find cards-score, first has 0,
// second has 2 and so on, modify it for your specifications
};

// display helpers
const char *GetCardColorAsString( CardColor c );
const char *GetCardValueAsString( CardValue v );

// THE CARD

struct Card
{
Card() {};
Card( CardColor c, CardValue v ) : color( c ), value( v ) {}

CardColor color;
CardValue value;

const char* GetColorAsString() const { return GetCardColorAsString( color ); }
const char* GetValueAsString() const { return GetCardValueAsString( value ); }

// compare two cards
bool operator<(Card const &c) const
{
if( color == c.color ) return value < c.value;
return color < c.color;
}
};

#include <set>
#include <vector>

using std::set;
using std::vector;

// needed by set to compare and sort the cards
struct CardComperator
{
// bool operator()(const Key& _xVal, const Key& _yVal);
bool      operator()( Card const *pCardA, Card const *pCardB )
{
return (*pCardA) < (*pCardB);
}
};

// the hand, cards are sorted here
typedef set< Card const*, CardComperator > Hand;

// as far as i can see, in deck the cards dont need to be sorted
typedef vector< Card const* > Deck;

// all cards are here, to move it to deck or hand move the pointer to its items ...
Card pool[310];

int main()
{
// array of 4 test-cards
Card pool[4] = { Card( Diamond, CV_5 ), Card( Spade, CV_7 ), Card( Clubs, CV_Ace ), Card( Spade, CV_2 ) };
Hand h;

// put cards into the hand
h.insert( &pool[0] );
h.insert( &pool[1] );
h.insert( &pool[2] );
h.insert( &pool[3] );

// as you can see from the output, the cards are sorted.
// to change the order, change the enum-values of CardValue and/or CardColor

// lets scroll through the hand
Hand::const_iterator it;
for( it = h.begin(); it != h.end(); ++it )
{
Card const *pCard = *it;
printf( "card: %s %s\n", pCard->GetColorAsString(), pCard->GetValueAsString() );
}
}

const char *GetCardValueAsString( CardValue v )
{
switch( v )
{
case CV_Ace:
return "Ace";
break;
case CV_2:
return "2";
break;
case CV_3:
return "3";
break;
case CV_4:
return "4";
break;
case CV_5:
return "5";
break;
case CV_6:
return "6";
break;
case CV_7:
return "7";
break;
case CV_Jack:
return "Jack";
break;
case CV_Queen:
return "Queen";
break;
case CV_King:
return "King";
break;
}
return NULL;
}

const char *GetCardColorAsString( CardColor c )
{
switch( c )
{
break;
case Diamond:
return "Diamond";
break;
case Clubs:
return "Clubs";
break;
case Hearts:
return "Hearts";
break;
}
return NULL;
}

<<<<<<<<< code end <<<<<<<<<<<<<<<

hope it helps :)
ike

Not the solution you were looking for? Getting a personalized solution is easy.

Commented:
Hi ike,

As far the help is pretty appreciable. I have some more doubts, shall I post as separete ? And immediately I can close this one.And accept this solution

Thanks,
Kishore
NajSoft India Solutions
CERTIFIED EXPERT

Commented:
that's up to you :))  what kind of doubts do you have?

Commented:
[that's up to you :))  what kind of doubts do you have?]

In your sample program its not checking rummies.

Commented:
I mean SA,SA,SA etc
CERTIFIED EXPERT

Commented:
right, the above code was intended to show a way, how to organize the data in the program, it was not the **full** program. the basis to analyze the hand, is to keep the hand sorted, the implementation is up to you ..

good luck :)
ike
##### Thanks for using Experts Exchange.

• View three pieces of content (articles, solutions, posts, and videos)
• Ask the experts questions (counted toward content limit)
• Customize your dashboard and profile