#include "cardlib.h"
#include "cardcount.h"
CardCount::CardCount()
{
Clear();
}
CardCount::CardCount(const CardStack &cs)
{
Init(cs);
}
void CardCount::Clear()
{
for(int i = 0; i < 13; i++)
count[i] = 0;
}
void CardCount::Add(const CardStack &cs)
{
for(int i = 0; i < cs.NumCards(); i++)
{
Card card = cs[i];
int val = card.LoVal();
count[val - 1]++;
}
}
void CardCount::Sub(const CardStack &cs)
{
for(int i = 0; i < cs.NumCards(); i++)
{
Card card = cs[i];
int val = card.LoVal();
if(count[val - 1] > 0)
count[val - 1]--;
}
}
void CardCount::Init(const CardStack &cs)
{
Clear();
Add(cs);
}
int CardCount::operator [] (size_t index) const
{
if(index < 1) return 0;
else if(index > 14) return 0;
else if(index == 14) index = 1;
return count[index - 1];
}
void CardCount::Dec(size_t index)
{
if(index < 1) return;
else if(index > 14) return;
else if(index == 14) index = 1;
index -= 1;
if(count[index] > 0)
count[index]--;
}