File indexing completed on 2025-02-23 05:14:54
0001 // bjgc_playertableutil.h -*-C++-*- 0002 #ifndef INCLUDED_BJGC_PLAYERTABLEUTIL 0003 #define INCLUDED_BJGC_PLAYERTABLEUTIL 0004 0005 //@PURPOSE: Provide utilities operating on player expected-value tables. 0006 // 0007 //@CLASSES: 0008 // bjgc::PlayerTableUtil: utilities on tables of player expected values 0009 // 0010 //@SEE_ALSO: bjgc_dealertableutil 0011 // 0012 //@DESCRIPTION: This component defines a utility 'struct', 0013 // 'bjgc::PlayerTableUtil', TBD 0014 // 0015 /// Usage 0016 ///----- 0017 // This section illustrates intended use of this component. 0018 // 0019 // TBD 0020 0021 #include <bjgc_playertable.h> 0022 0023 #include <bjgc_dealertable.h> 0024 0025 #include <bjgb_rules.h> 0026 #include <bjgb_shoe.h> 0027 #include <bjgb_types.h> // 'Double' 0028 0029 // TBD most 'PlayerTableUtil' methods should probably be renamed 0030 0031 namespace bjgc { 0032 0033 // ====================== 0034 // struct PlayerTableUtil 0035 // ====================== 0036 0037 struct PlayerTableUtil { 0038 // TBD class-level doc 0039 0040 // CLASS METHODS 0041 static void copyPlayerRow(PlayerTable *pta, int hia, const PlayerTable& ptb, int hib); 0042 // Copy the respective values of the row at the specified 'hib' hand 0043 // index in the specified 'ptb' player table to those in the row at the 0044 // specified 'hia' hand index in the specified 'pta' player table. The 0045 // behavior is undefined unless '0 <= hia', 0046 // 'hia < bjgb::State::k_NUM_STATES', '0 <= hib', and 0047 // 'hib < bjgb::State::k_NUM_STATES'. 0048 0049 static bjgb::Types::Double eDouble(const bjgc::PlayerTable& p1t, int uc, int hv, bool sf); 0050 // Return the expected value of doubling a hand given the specified 0051 // player table for a player hitting a hand just once, 'p1t', the 0052 // specified dealer up card, 'uc', the specified *minimum* value of the 0053 // hand, 'hv', and the specified 'sf' flag indicating whether 'hv' is a 0054 // soft count. Note that not all casinos allow the player to double on 0055 // any two cards, e.g., some allow a double on 9, 10, or 11 only -- the 0056 // rules must be checked at the call sight. 0057 0058 static bjgb::Types::Double eHit1(const PlayerTable& pst, int uc, int hv, bool sf, const bjgb::Shoe& shoe); 0059 // Return the expected value of a player's hand given the specified 0060 // player table for standing on any two-card value, 'pst', the 0061 // specified dealer up card, 'uc', the specified *minimum* value of the 0062 // hand, 'hv', the specified 'sf' flag indicating whether 'hv' is a 0063 // soft count, and the specified 'shoe'. 0064 0065 static bjgb::Types::Double 0066 eHitN(const PlayerTable& pht, const PlayerTable& pst, int uc, int hv, bool sf, const bjgb::Shoe& shoe); 0067 // Return the expected value of a player's hand assuming they hit AT 0068 // LEAST once, given the specified current player table for hitting at 0069 // least once, 'pht', the specified player-stands table, 'pst', the 0070 // specified dealer up card, 'uc', the specified *minimum* value of the 0071 // hand, 'hv', the specified 'sf' flag indicating whether 'hv' is a 0072 // soft count, and the specified 'shoe'. 0073 0074 static bjgb::Types::Double eSplit(const PlayerTable& pdt, 0075 const PlayerTable& pht, 0076 const PlayerTable& p1t, 0077 const PlayerTable& pst, 0078 int uc, 0079 int hv, 0080 int n, 0081 const bjgb::Shoe& shoe, 0082 const bjgb::Rules& rules); 0083 // Return the expected value of a player's hand (assuming it can be 0084 // split) given the specified expected-value tables for doubling, 0085 // 'pdt', hitting at least once, 'pht', hitting once only, 'p1t', and 0086 // 'standing', 'pst', and the specified up card, 'uc', the specified 0087 // current value of the player's hand, 'hv', the specified remaining 0088 // number of times the hand can be split (often at most 3 on the first 0089 // [non-recursive] call, but typically 1 for Aces), 'n', the specified 0090 // 'shoe', and the specified 'rules'. Note that, with each split, the 0091 // bet is doubled. Also note that the 'shoe' is not currently affected 0092 // by repeated splits. (TBD We might consider reducing the number of 0093 // the split card for smaller shoes.) Also note that the rule of 1 0094 // card to a split Ace is separate from being allowed to re-split Aces; 0095 // hence, we need to pass 'rules' into this function and not rely 0096 // solely on the value of 'n', but it is up to the caller to inspect 0097 // the 'rules' and decide how many splits are allowed for cards: I.e., 0098 // we pass in 1 less than the maximum number of allowed hands. 0099 0100 static bjgb::Types::Double eStand(const DealerTable& t, int uc, int hv); 0101 // Return the expected value of a player's hand given the specified 0102 // dealer table, 't', the specified dealer up card, 'uc', and the 0103 // specified player hard-count value, 'hv'. 0104 0105 static bjgb::Types::Double 0106 evalShoeImp(const bjgb::Shoe& shoe, const PlayerTable& pt, const PlayerTable& pat, const bjgb::Rules& rules); 0107 // Return the expected value of the specified 'shoe', given the 0108 // specified (unadjusted) player table, 'pt', the specified adjusted 0109 // player table, 'pat', and the specified 'rules'. 0110 0111 static bool isSamePlayerRow(const PlayerTable& pta, int hia, const PlayerTable& ptb, int hib); 0112 // Return 'true' if the row at the specified 'hia' hand index in the 0113 // specified 'pta' player table holds the same values as the row at the 0114 // specified 'hib' hand index in the specified 'ptb' player table, and 0115 // 'false' otherwise. The behavior is undefined unless '0 <= hia', 0116 // 'hia < bjgb::State::k_NUM_STATES', '0 <= hib', and 0117 // 'hib < bjgb::State::k_NUM_STATES'. 0118 0119 static bjgb::Types::Double mx(int hi, int cd, const PlayerTable& t, const PlayerTable& q); 0120 // TBD the 'const PlayerTable&' arguments should be passed first 0121 // Return the maximum of the two entries in the specified 't' and 'q' 0122 // player tables that are indexed by the specified 'hi' hand index and 0123 // 'cd' raw card value. The behavior is undefined unless '0 <= hi', 0124 // 'hi < bjgb::State::k_NUM_STATES', '1 <= cd', 'cd <= 10', 0125 // '(bjgb::State::e_HOV == hi) != bjgb::Types::isValid(t.exp(hi, cd))' 0126 // and 'bjgb::Types::isValid(q.exp(hi, cd))'. 0127 0128 static bjgb::Types::Double mx3(int hi, int cd, const PlayerTable& x, const PlayerTable& y, const PlayerTable& z); 0129 // TBD the 'const PlayerTable&' arguments should be passed first 0130 // Return the maximum of the three entries in the specified 'x', 'y', 0131 // and 'z' player tables that are indexed by the specified 'hi' hand 0132 // index and 'cd' raw card value. The behavior is undefined unless 0133 // '0 <= hi', 'hi < bjgb::State::k_NUM_STATES', '1 <= cd', 'cd <= 10', 0134 // 'bjgb::Types::isValid(x.exp(hi, cd))', 0135 // 'bjgb::Types::isValid(y.exp(hi, cd))', and 0136 // 'bjgb::Types::isValid(z.exp(hi, cd))'. 0137 0138 static void populatePlayerTable(PlayerTable *pt, 0139 const PlayerTable& pxt, 0140 const PlayerTable& pht, 0141 const PlayerTable& pst, 0142 const bjgb::Rules& rules); 0143 // Populate the specified player table, 'pt', given the specified 0144 // player-splits table, 'pxt', the specified player-hits-many table, 0145 // 'pht', the specified player-stands table, 'pst', and the specified 0146 // 'rules'. 0147 0148 static void populateP1tab(PlayerTable *p1, const PlayerTable& ps, const bjgb::Shoe& shoe, const bjgb::Rules& rules); 0149 // Populate the specified player-hits-once table, 'p1', assuming that 0150 // the player always hits exactly once, given the specified 0151 // player-stands table, 'ps', the specified 'shoe', and the specified 0152 // 'rules'. 0153 0154 static void populatePdtab(PlayerTable *pd, const PlayerTable& p1); 0155 // Populate the specified player-doubles table, 'pd', assuming that the 0156 // player is allowed to double the hand, given the specified 0157 // player-hits-once table, 'p1'. Valid hands to double are 'e_SBJ', 0158 // S11-S02, and H20-H04. 0159 // TBD not sure what this means: 0160 // Note that we will need to pass in an adjusted table unless the 0161 // rules allow for a doubled hand to lose more than unit value. 0162 // Consult the rules. 0163 0164 static void populatePhtab(PlayerTable *ph, const PlayerTable& ps, const bjgb::Shoe& shoe, const bjgb::Rules& rules); 0165 // Populate the specified player-hits-many table, 'ph', assuming that 0166 // the player always hits while it is to the player's advantage to do 0167 // so, given the specified player-stands table, 'ps', the specified 0168 // 'shoe', and the specified 'rules'. 0169 0170 static void populatePstab(PlayerTable *ps, const DealerTable& dt, const bjgb::Shoe& shoe, const bjgb::Rules& rules); 0171 // Populate the specified player-stands table, 'ps', assuming that the 0172 // player always stands, given the specified dealer table, 'dt', the 0173 // specified 'shoe', and the specified 'rules'. 0174 0175 static void populatePxtab(PlayerTable *pxt, 0176 const PlayerTable& pdt, 0177 const PlayerTable& pht, 0178 const PlayerTable& p1t, 0179 const PlayerTable& pst, 0180 const bjgb::Shoe& shoe, 0181 const bjgb::Rules& rules); 0182 // Populate the specified player-splits table, 'pxt', assuming that the 0183 // player splits whenever it is allowed to do so, given the specified 0184 // player-doubles table, 'pdt', the specified player-hits-many table, 0185 // 'pht', the specified player-hits-once table, 'p1t', the specified 0186 // player-stands table, 'pst', the specified 'shoe', and the specified 0187 // 'rules'. 0188 }; 0189 0190 // ============================================================================ 0191 // INLINE DEFINITIONS 0192 // ============================================================================ 0193 0194 // ---------------------- 0195 // struct PlayerTableUtil 0196 // ---------------------- 0197 0198 } // namespace bjgc 0199 0200 #endif