File indexing completed on 2025-10-12 04:59:55

0001 // bjgb_state.h                                                       -*-C++-*-
0002 #ifndef INCLUDED_BJGB_STATE
0003 #define INCLUDED_BJGB_STATE
0004 
0005 #include <bjgb_export.h>
0006 
0007 //@PURPOSE: Enumerate the unique states of a blackjack hand.
0008 //
0009 //@CLASSES:
0010 //  bjgb::State: enumeration of the unique states of a blackjack hand
0011 //
0012 //@SEE_ALSO: TBD
0013 //
0014 //@DESCRIPTION: This component defines an enumeration, 'bjgb::State', TBD
0015 //
0016 /// Usage
0017 ///-----
0018 // This section illustrates intended use of this component.
0019 //
0020 // TBD
0021 
0022 #include <cassert>
0023 
0024 namespace bjgb {
0025 
0026 // ============
0027 // struct State
0028 // ============
0029 
0030 struct BJGB_EXPORT State {
0031     // TBD class-level doc
0032 
0033     // TYPES
0034     enum Enum {
0035         // Soft counts (TBD explain 'e_S01')
0036         e_S01,
0037         e_S02,
0038         e_S03,
0039         e_S04,
0040         e_S05,
0041         e_S06,
0042         e_S07,
0043         e_S08,
0044         e_S09,
0045         e_S10,
0046         e_S11,
0047 
0048         // BlackJack ("natural" 21)
0049         e_SBJ,
0050 
0051         // 0-card hand (ZeRo count)
0052         e_HZR,
0053 
0054         // 1-card hands; lone Ace is soft ('S_'), other cards are hard ('H_')
0055         e_S_A,
0056         e_H_2,
0057         e_H_3,
0058         e_H_4,
0059         e_H_5,
0060         e_H_6,
0061         e_H_7,
0062         e_H_8,
0063         e_H_9,
0064         e_H_T,
0065 
0066         // Hard counts (TBD explain 'e_H02', 'e_H03'; bogus states?)
0067         e_H02,
0068         e_H03,
0069         e_H04,
0070         e_H05,
0071         e_H06,
0072         e_H07,
0073         e_H08,
0074         e_H09,
0075         e_H10,
0076         e_H11,
0077         e_H12,
0078         e_H13,
0079         e_H14,
0080         e_H15,
0081         e_H16,
0082         e_H17,
0083         e_H18,
0084         e_H19,
0085         e_H20,
0086         e_H21,
0087 
0088         // OVer (busted)
0089         e_HOV,
0090 
0091         // Pairs of identical cards (opportunity for player split)
0092         e_PAA,
0093         e_P22,
0094         e_P33,
0095         e_P44,
0096         e_P55,
0097         e_P66,
0098         e_P77,
0099         e_P88,
0100         e_P99,
0101         e_PTT
0102     };
0103 
0104     enum { k_NUM_STATES = e_PTT + 1 };
0105 
0106     // CLASS METHODS
0107     static constexpr int hard(int count);
0108     // Return the value of the enumerator in the range '[e_H02 .. e_H21]'
0109     // corresponding to the specified *hard* 'count'.  The behavior is
0110     // undefined unless '2 <= count' and 'count <= 21'.  Note that this
0111     // method maps integral values in the range '[2 .. 21]' to values in
0112     // the range '[e_H02 .. e_H21]'.
0113 
0114     static constexpr int soft(int count);
0115     // Return the value of the enumerator in the range '[e_S01 .. e_S11]'
0116     // corresponding to the specified *soft* 'count'.  The behavior is
0117     // undefined unless '1 <= count' and 'count <= 11'.  Note that this
0118     // method maps integral values in the range '[1 .. 11]' to values in
0119     // the range '[e_S01 .. e_S11]'.
0120 
0121     static constexpr int pair(int value);
0122     // Return the value of the enumerator in the range '[e_PAA .. e_PTT]'
0123     // corresponding to the specified card 'value'.  The behavior is
0124     // undefined unless '1 <= value' and 'value <= 10'.  Note that this
0125     // method maps integral values in the range '[1 .. 10]' to values in
0126     // the range '[e_PAA .. e_PTT]'.
0127 
0128     static constexpr int unus(int value);
0129     // Return the value of the enumerator in the range '[e_S_A .. e_H_T]'
0130     // corresponding to the specified card 'value'.  The behavior is
0131     // undefined unless '1 <= value' and 'value <= 10'.  Note that this
0132     // method maps integral values in the range '[1 .. 10]' to values in
0133     // the range '[e_S_A .. e_H_T]'.
0134 
0135     static const char *stateId2String(int stateId);
0136     // Return the compact string representation corresponding to the
0137     // specified 'stateId'.  The behavior is undefined unless
0138     // '0 <= stateId' and 'stateId < k_NUM_STATES'.  Note that this method
0139     // provides a unique 2-character "label" for each state to distinguish
0140     // them in output.
0141 };
0142 
0143 // ============================================================================
0144 //                              INLINE DEFINITIONS
0145 // ============================================================================
0146 
0147 // ------------
0148 // struct State
0149 // ------------
0150 
0151 // CLASS METHODS
0152 inline constexpr int State::hard(int count)
0153 {
0154     assert(2 <= count);
0155     assert(count <= 21);
0156 
0157     return count - 2 + e_H02;
0158 }
0159 
0160 inline constexpr int State::soft(int count)
0161 {
0162     assert(1 <= count);
0163     assert(count <= 11);
0164 
0165     return count - 1 + e_S01;
0166 }
0167 
0168 inline constexpr int State::pair(int value)
0169 {
0170     assert(1 <= value);
0171     assert(value <= 10);
0172 
0173     return value - 1 + e_PAA;
0174 }
0175 
0176 inline constexpr int State::unus(int value)
0177 {
0178     assert(1 <= value);
0179     assert(value <= 10);
0180 
0181     return value - 1 + e_S_A;
0182 }
0183 
0184 } // namespace bjgb
0185 
0186 #endif