proj home

Files   Classes   Functions   Hierarchy  

deckpontoon Class Reference

A pontoon deck of cards. More...

#include <deckpontoon.h>

Inheritance diagram for deckpontoon:
Collaboration diagram for deckpontoon:

List of all members.

Public Member Functions

 deckpontoon ()
 Creates a deck of cards with 8 standard card decks.
uintc draw ()
 The deck is automatically reshuffled when it runs out.
void shuffle ()
 Shuffle all the cards.
bool const verifyTheDeck ()


Detailed Description

A pontoon deck of cards.

K Q J have a value of 10. Ace is 1 or 11 in value but represented uniquely as 1.

Definition at line 18 of file deckpontoon.h.


Constructor & Destructor Documentation

deckpontoon::deckpontoon (  ) 

Creates a deck of cards with 8 standard card decks.

Definition at line 19 of file deckpontoon.cpp.

00020 {
00021   // Ace Normal Cards    Jack Queen King
00022   // 1   2 3 4 5 6 7 8 9 10   10    10
00023 
00024   numberofdecks=8;
00025   decksize = 12*4*numberofdecks;
00026   v.resize(decksize);
00027 
00028   uint i,k,w;
00029   current=0;
00030 
00031   // Iterate through each deck.
00032   for (i=0; i<8; ++i)
00033   {
00034     // Iterate through each suit.
00035     for (k=0; k<4; ++k)
00036     {
00037       for (w=1; w<=10; ++w)
00038         v[current++] = w;
00039       v[current++] = 10;
00040       v[current++] = 10;
00041     }
00042 
00043   }
00044 
00045 }


Member Function Documentation

uintc deckpontoon::draw (  )  [virtual]

The deck is automatically reshuffled when it runs out.

Implements deck.

Definition at line 10 of file deckpontoon.cpp.

References shuffle().

Referenced by test01().

00011 {
00012   if (current==decksize)
00013     shuffle();
00014 
00015   return v[current++];
00016 }

void deckpontoon::shuffle (  ) 

Shuffle all the cards.

Definition at line 48 of file deckpontoon.cpp.

References generateRandomSeed().

Referenced by draw().

00049 {
00050   // This call randomizes the initial shuffle.
00051 
00052   srand(generateRandomSeed(10));
00053 
00054   // Perform the shuffle a few times to get a 
00055   //   good mix.
00056   uint imax = rand() % 10;
00057   for ( uint i=0; i<imax; ++i)
00058     random_shuffle( v.begin(), v.end() );
00059 
00060   srand(generateRandomSeed(10));
00061 
00062   current=0;
00063 }

bool const deckpontoon::verifyTheDeck (  ) 

Definition at line 65 of file deckpontoon.cpp.

Referenced by test01().

00066 {
00067   uint vmax = v.size();
00068 
00069   uint w[10];
00070   for (uint k=0; k<10; ++k)
00071     w[k] = 0;
00072 
00073   for (uint i=0; i<vmax; ++i)
00074   {
00075     ++w[v[i]-1];
00076   }
00077 
00078   for (uint k=0; k<9; ++k)
00079   {
00080     if (w[k]!=numberofdecks*4)
00081       return false;
00082   }
00083 
00084   if (w[10]!=numberofdecks*4*3)
00085     return false;
00086 
00087   return true;
00088 }


The documentation for this class was generated from the following files:

Generated on Fri Mar 4 00:49:55 2011 for Chelton Evans Source by  doxygen 1.5.8