Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

cardcount.cpp

Go to the documentation of this file.
00001 //
00002 //    CardCount is a helper library for CardStacks.
00003 //
00004 //    When you initialize a CardCount object with a
00005 //  cardstack, it keeps track of the number of cards
00006 //    the stack contains.
00007 //
00008 //    e.g. CardCount count(cardstack);
00009 //
00010 //    Then you can do:
00011 //
00012 //        int num_fives = count[5]
00013 //
00014 //        count.Add(cardstack2);        - combine with another stack
00015 //
00016 //        int num_aces = count[1]        - aces low
00017 //        int num_aces = count[14]    - aces high
00018 //
00019 //        count.Clear();
00020 //
00021 #include "cardcount.h"
00022 
00023 CardCount::CardCount()
00024 {
00025     Clear();
00026 }
00027 
00028 CardCount::CardCount(const CardStack &cs)
00029 {
00030     Init(cs);
00031 }
00032 
00033 void CardCount::Clear()
00034 {
00035     for(int i = 0; i < 13; i++)
00036         count[i] = 0;
00037 }
00038 
00039 void CardCount::Add(const CardStack &cs)
00040 {
00041     for(int i = 0; i < cs.NumCards(); i++)
00042     {
00043         Card card = cs[i];
00044 
00045         int val = card.LoVal();
00046         count[val - 1]++;
00047     }
00048 }
00049 
00050 void CardCount::Sub(const CardStack &cs)
00051 {
00052     for(int i = 0; i < cs.NumCards(); i++)
00053     {
00054         Card card = cs[i];
00055         int val = card.LoVal();
00056 
00057         if(count[val - 1] > 0)
00058             count[val - 1]--;
00059     }
00060 }
00061 
00062 void CardCount::Init(const CardStack &cs)
00063 {
00064     Clear();
00065     Add(cs);
00066 }
00067 
00068 int CardCount::operator [] (size_t index) const
00069 {
00070     if(index < 1) return 0;
00071     else if(index > 14)  return 0;    //if out of range
00072     else if(index == 14) index = 1;    //if a "ace-high"
00073 
00074     return count[index - 1];
00075 }
00076 
00077 //
00078 //    Decrement specified item by one
00079 //
00080 void CardCount::Dec(size_t index)
00081 {
00082     if(index < 1) return;
00083     else if(index > 14)  return;    //if out of range
00084     else if(index == 14) index = 1;    //if a "ace-high"
00085 
00086     index -= 1;
00087 
00088     if(count[index] > 0)
00089         count[index]--;
00090 }

Generated on Thu Feb 9 04:59:25 2012 for ReactOS by doxygen 1.6.3

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.