
#include <algorithm>
#include <iostream>
using namespace std;

#include <clockmisc.h>

#include <deckpontoon.h>

uintc deckpontoon::draw()
{
  if (current==decksize)
    shuffle();

  return v[current++];
}


deckpontoon::deckpontoon()
{
  // Ace Normal Cards    Jack Queen King
  // 1   2 3 4 5 6 7 8 9 10   10    10

  numberofdecks=8;
  decksize = 12*4*numberofdecks;
  v.resize(decksize);

  uint i,k,w;
  current=0;

  // Iterate through each deck.
  for (i=0; i<8; ++i)
  {
    // Iterate through each suit.
    for (k=0; k<4; ++k)
    {
      for (w=1; w<=10; ++w)
        v[current++] = w;
      v[current++] = 10;
      v[current++] = 10;
    }

  }

}


void deckpontoon::shuffle()
{
  // This call randomizes the initial shuffle.

  srand(generateRandomSeed(10));

  // Perform the shuffle a few times to get a 
  //   good mix.
  uint imax = rand() % 10;
  for ( uint i=0; i<imax; ++i)
    random_shuffle( v.begin(), v.end() );

  srand(generateRandomSeed(10));

  current=0;
}

bool const deckpontoon::verifyTheDeck()
{
  uint vmax = v.size();

  uint w[10];
  for (uint k=0; k<10; ++k)
    w[k] = 0;

  for (uint i=0; i<vmax; ++i)
  {
    ++w[v[i]-1];
  }

  for (uint k=0; k<9; ++k)
  {
    if (w[k]!=numberofdecks*4)
      return false;
  }

  if (w[10]!=numberofdecks*4*3)
    return false;

  return true;
}


