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
23 #include "cardcount.h"
25 CardCount::CardCount()
30 CardCount::CardCount(const CardStack
&cs
)
35 void CardCount::Clear()
37 for(int i
= 0; i
< 13; i
++)
41 void CardCount::Add(const CardStack
&cs
)
43 for(int i
= 0; i
< cs
.NumCards(); i
++)
47 int val
= card
.LoVal();
52 void CardCount::Sub(const CardStack
&cs
)
54 for(int i
= 0; i
< cs
.NumCards(); i
++)
57 int val
= card
.LoVal();
59 if(count
[val
- 1] > 0)
64 void CardCount::Init(const CardStack
&cs
)
70 int CardCount::operator [] (size_t index
) const
72 if(index
< 1) return 0;
73 else if(index
> 14) return 0; //if out of range
74 else if(index
== 14) index
= 1; //if a "ace-high"
76 return count
[index
- 1];
80 // Decrement specified item by one
82 void CardCount::Dec(size_t index
)
85 else if(index
> 14) return; //if out of range
86 else if(index
== 14) index
= 1; //if a "ace-high"