- Jul 6, 2001
- 2,740
- 0
- 0
Heres the story. I am simulating the game of Old maid with C with one computer player and a human player. Directions for those who doesn't know how to play old maid.
Okay heres what i accomplished. I generated a deck of 52 cards and stored into a array of structures. Heres the structure definition
typedef struct card
{
int suit;
int pip;
} CARD;
I already took out the queen, so now there are 51 cards, and i shifted the elements after the queen one element to the left.
Then i passed out two hands starting with the player, then the computer and named the arrays player[PlayCardCount], and
computer[CompCardCount].
Then i wrote a function that would take out all the pairs in each hand. so now my problem is shrinking the deck down to the correct size, removing all the blank spaces where the removed pairs used to be in. The computer and player deck should have no blank spaces between cards, making each card one after another. Heres what i did, but it does't appear to work.
void Shift(CARD deck[], int NumOfCards)
{
int i,j;
CARD blank;
blank.suit = 0;
blank.pip = 0;
for(i = 0;i < NumOfCards;i++)
{
if(deck.pip == 0)
{
for( j = i + 1;j < NumOfCards; j++)
{
if( deck[j] != 0)
{
deck = deck[j];
deck[j] = blank;
}
}
}
}
}
Okay heres what i accomplished. I generated a deck of 52 cards and stored into a array of structures. Heres the structure definition
typedef struct card
{
int suit;
int pip;
} CARD;
I already took out the queen, so now there are 51 cards, and i shifted the elements after the queen one element to the left.
Then i passed out two hands starting with the player, then the computer and named the arrays player[PlayCardCount], and
computer[CompCardCount].
Then i wrote a function that would take out all the pairs in each hand. so now my problem is shrinking the deck down to the correct size, removing all the blank spaces where the removed pairs used to be in. The computer and player deck should have no blank spaces between cards, making each card one after another. Heres what i did, but it does't appear to work.
void Shift(CARD deck[], int NumOfCards)
{
int i,j;
CARD blank;
blank.suit = 0;
blank.pip = 0;
for(i = 0;i < NumOfCards;i++)
{
if(deck.pip == 0)
{
for( j = i + 1;j < NumOfCards; j++)
{
if( deck[j] != 0)
{
deck = deck[j];
deck[j] = blank;
}
}
}
}
}