Homework/HW03/canfield.cc
void newGame()
{
    int i, card;
    int cardsLeft = NUM_CARDS;
    int newDeck[NUM_CARDS];

    // Empty all the data structures
    emptyAll();

    //Reset the score.
    score = 0;

    //Reset the flag that declares whether the player has won the game or not.
    playerHasWon = false;

    // Create a new deck and shuffle it
    newShuffledPack(newDeck);

    // Now place the cards in the data structures
    for (i=0; i<NUM_RANKS; i++)      // fill in the reserve with 13 cards
    {
        card = newDeck[--cardsLeft]; // use a card and decrease the total count
        reserve.push(card);
    }
    for (i=0; i<NUM_SUITS; i++)      // draw a card for each tableau
    {
        card = newDeck[--cardsLeft]; // use a card and decrease the
                                     // total count
        tableau[i].push(card);
    }
    for (i=0; i<NUM_SUITS; i++)      // Initialize the foundations with 0
        foundation[i].push(0);
    waste = newDeck[--cardsLeft];    // the card to play
    while (cardsLeft > 0)            // the remaining cards go into the deck
    {
        card = newDeck[--cardsLeft];
        deck.enqueue(card);
    }
}
// Starting a new game. It must reset all the data structures,
// generate a new set of 52 random cards and place them in the
// appropriate places in the game.
Starting a new game. It must reset all the data structures,
generate a new set of 52 random cards and place them in the
appropriate places in the game.
Starting a new game . It must reset all the data structures generate a new set of 52 random cards and place them in the appropriate places in the game .
void newGame()
{
    int i, card;
    int cardsLeft = NUM_CARDS;
    int newDeck[NUM_CARDS];
    emptyAll();
    score = 0;
    playerHasWon = false;
    newShuffledPack(newDeck);
    for (i=0; i<NUM_RANKS; i++)      
    {
        card = newDeck[--cardsLeft]; 
        reserve.push(card);
    }
    for (i=0; i<NUM_SUITS; i++)      
    {
        card = newDeck[--cardsLeft]; 
        tableau[i].push(card);
    }
    for (i=0; i<NUM_SUITS; i++)      
        foundation[i].push(0);
    waste = newDeck[--cardsLeft];    
    while (cardsLeft > 0)            
    {
        card = newDeck[--cardsLeft];
        deck.enqueue(card);
    }
}
void newGame ( ) { int i , card ; int cardsLeft = NUM_CARDS ; int newDeck [ NUM_CARDS ] ; emptyAll ( ) ; score = 0 ; playerHasWon = false ; newShuffledPack ( newDeck ) ; for ( i = 0 ; i < NUM_RANKS ; i ++ ) { card = newDeck [ -- cardsLeft ] ; reserve . push ( card ) ; } for ( i = 0 ; i < NUM_SUITS ; i ++ ) { card = newDeck [ -- cardsLeft ] ; tableau [ i ] . push ( card ) ; } for ( i = 0 ; i < NUM_SUITS ; i ++ ) foundation [ i ] . push ( 0 ) ; waste = newDeck [ -- cardsLeft ] ; while ( cardsLeft > 0 ) { card = newDeck [ -- cardsLeft ] ; deck . enqueue ( card ) ; } }
Starting a new game.
Starting a new game .
// Empty all the data structures //Reset the score. //Reset the flag that declares whether the player has won the game or not. // Create a new deck and shuffle it // Now place the cards in the data structures // fill in the reserve with 13 cards // use a card and decrease the total count // draw a card for each tableau // use a card and decrease the // total count // Initialize the foundations with 0 // the card to play // the remaining cards go into the deck