File indexing completed on 2025-02-23 05:14:54
0001 // bjgc_playertable.h -*-C++-*- 0002 #ifndef INCLUDED_BJGC_PLAYERTABLE 0003 #define INCLUDED_BJGC_PLAYERTABLE 0004 0005 //@PURPOSE: Provide a mechanism to tabulate player expected values. 0006 // 0007 //@CLASSES: 0008 // bjgc::PlayerTable: table of player expected values 0009 // 0010 //@SEE_ALSO: bjgb_state, bjgc_dealertable 0011 // 0012 //@DESCRIPTION: This component defines a mechanism, 'bjgc::PlayerTable', TBD 0013 // 0014 /// Usage 0015 ///----- 0016 // This section illustrates intended use of this component. 0017 // 0018 // TBD 0019 0020 #include <bjgb_state.h> // 'k_NUM_STATES' 0021 #include <bjgb_types.h> // 'Double' 0022 0023 #include <iosfwd> 0024 0025 namespace bjgc { 0026 0027 // ================= 0028 // class PlayerTable 0029 // ================= 0030 0031 class PlayerTable { 0032 // This class defines a mechanism for tabulating blackjack player expected 0033 // values. 0034 0035 public: 0036 // CLASS DATA 0037 static const int k_NUM_CARD_VALUES = 10; // number of card values 0038 0039 private: 0040 // DATA 0041 bjgb::Types::Double d_exp[bjgb::State::k_NUM_STATES][1 + k_NUM_CARD_VALUES]; 0042 // table of player expected values; indexing: [hand][card value]; 0043 // 0th column is not used 0044 0045 public: 0046 // CREATORS 0047 PlayerTable(); 0048 // Create a player table and initialize all entries with a value that 0049 // is distinct from any valid player expected value. The initial value 0050 // of the entries is implementation defined. 0051 0052 PlayerTable(const PlayerTable&) = delete; 0053 0054 ~PlayerTable() = default; 0055 0056 // MANIPULATORS 0057 PlayerTable& operator=(const PlayerTable&) = delete; 0058 0059 constexpr bjgb::Types::Double& exp(int hand, int value); 0060 // Return a non-'const' reference to the entry in this player table 0061 // that is indexed by the specified 'hand' state and card 'value'. The 0062 // behavior is undefined unless '0 <= hand', 0063 // 'hand < bjgb::State::k_NUM_STATES', '1 <= value', and 'value <= 10'. 0064 0065 void clearRow(int hand); 0066 // Set all entries of the row in this player table that is indexed by 0067 // the specified 'hand' state to 0.0. The behavior is undefined unless 0068 // '0 <= hand' and 'hand < bjgb::State::k_NUM_STATES'. 0069 0070 void reset(); 0071 // Reset this player table to the default constructed state. 0072 0073 void setRow(int hand, bjgb::Types::Double value); 0074 // Set all entries of the row in this player table that is indexed by 0075 // the specified 'hand' state to the specified 'value'. The behavior 0076 // is undefined unless '0 <= hand' and 0077 // 'hand < bjgb::State::k_NUM_STATES'. 0078 0079 // ACCESSORS 0080 constexpr const bjgb::Types::Double& exp(int hand, int value) const; 0081 // Return a 'const' reference to the entry in this player table that is 0082 // indexed by the specified 'hand' state and card 'value'. The 0083 // behavior is undefined unless '0 <= hand', 0084 // 'hand < bjgb::State::k_NUM_STATES', '1 <= value', and 'value <= 10'. 0085 }; 0086 0087 // FREE OPERATORS 0088 std::ostream& operator<<(std::ostream& stream, const PlayerTable& table); 0089 // Write the value of the specified player expected-values 'table' to the 0090 // specified output 'stream', and return a reference to 'stream'. Note 0091 // that this human-readable format is not fully specified and can change 0092 // without notice. 0093 0094 // ============================================================================ 0095 // INLINE DEFINITIONS 0096 // ============================================================================ 0097 0098 // ----------------- 0099 // class PlayerTable 0100 // ----------------- 0101 0102 // CREATORS 0103 inline PlayerTable::PlayerTable() 0104 { 0105 reset(); 0106 } 0107 0108 // MANIPULATORS 0109 inline constexpr bjgb::Types::Double& PlayerTable::exp(int hand, int value) 0110 { 0111 assert(0 <= hand); 0112 assert(hand < bjgb::State::k_NUM_STATES); 0113 assert(1 <= value); 0114 assert(value <= k_NUM_CARD_VALUES); 0115 0116 return d_exp[hand][value]; 0117 } 0118 0119 // ACCESSORS 0120 inline constexpr const bjgb::Types::Double& PlayerTable::exp(int hand, int value) const 0121 { 0122 assert(0 <= hand); 0123 assert(hand < bjgb::State::k_NUM_STATES); 0124 assert(1 <= value); 0125 assert(value <= k_NUM_CARD_VALUES); 0126 0127 return d_exp[hand][value]; 0128 } 0129 0130 } // namespace bjgc 0131 0132 #endif