2 // CardCount is a helper library for CardStacks.
4 // When you initialize a CardCount object with a
5 // cardstack, it keeps track of the number of cards
8 // e.g. CardCount count(cardstack);
12 // int num_fives = count[5]
14 // count.Add(cardstack2); - combine with another stack
16 // int num_aces = count[1] - aces low
17 // int num_aces = count[14] - aces high
21 #include "cardcount.h"
23 CardCount::CardCount()
28 CardCount::CardCount(const CardStack
&cs
)
33 void CardCount::Clear()
35 for(int i
= 0; i
< 13; i
++)
39 void CardCount::Add(const CardStack
&cs
)
41 for(int i
= 0; i
< cs
.NumCards(); i
++)
45 int val
= card
.LoVal();
50 void CardCount::Sub(const CardStack
&cs
)
52 for(int i
= 0; i
< cs
.NumCards(); i
++)
55 int val
= card
.LoVal();
57 if(count
[val
- 1] > 0)
62 void CardCount::Init(const CardStack
&cs
)
68 int CardCount::operator [] (size_t index
) const
70 if(index
< 1) return 0;
71 else if(index
> 14) return 0; //if out of range
72 else if(index
== 14) index
= 1; //if a "ace-high"
74 return count
[index
- 1];
78 // Decrement specified item by one
80 void CardCount::Dec(size_t index
)
83 else if(index
> 14) return; //if out of range
84 else if(index
== 14) index
= 1; //if a "ace-high"