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
22 #include "cardcount.h"
24 CardCount::CardCount()
29 CardCount::CardCount(const CardStack
&cs
)
34 void CardCount::Clear()
36 for(int i
= 0; i
< 13; i
++)
40 void CardCount::Add(const CardStack
&cs
)
42 for(int i
= 0; i
< cs
.NumCards(); i
++)
46 int val
= card
.LoVal();
51 void CardCount::Sub(const CardStack
&cs
)
53 for(int i
= 0; i
< cs
.NumCards(); i
++)
56 int val
= card
.LoVal();
58 if(count
[val
- 1] > 0)
63 void CardCount::Init(const CardStack
&cs
)
69 int CardCount::operator [] (size_t index
) const
71 if(index
< 1) return 0;
72 else if(index
> 14) return 0; //if out of range
73 else if(index
== 14) index
= 1; //if a "ace-high"
75 return count
[index
- 1];
79 // Decrement specified item by one
81 void CardCount::Dec(size_t index
)
84 else if(index
> 14) return; //if out of range
85 else if(index
== 14) index
= 1; //if a "ace-high"