File indexing completed on 2025-02-23 05:14:54

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