File indexing completed on 2025-10-12 04:59:55
0001 // bjgb_shoeutil.cpp -*-C++-*- 0002 #include <bjgb_shoeutil.h> 0003 0004 #include <bjgb_rank.h> 0005 0006 #include <cassert> 0007 #include <iostream> // TBD TEMPORARY 0008 0009 namespace bjgb { 0010 0011 // --------------- 0012 // struct ShoeUtil 0013 // --------------- 0014 0015 // CLASS METHODS 0016 bool ShoeUtil::isUnused(const Shoe& shoe) 0017 { 0018 using namespace RankLiterals; 0019 0020 const int count = shoe.numCards(A_R); 0021 0022 assert(count >= 4); 0023 0024 if (0 != count % 4) { 0025 std::cout << "[unused: RETURN count = " << count << "]\n"; 0026 return false; 0027 } 0028 0029 for (Rank r = 2_R; r < T_R; ++r) { 0030 if (count != shoe.numCards(r)) { 0031 std::cout << "[unused: RETURN r = " << r << ", " << shoe.numCards(r) << "]\n"; 0032 return false; 0033 } 0034 } 0035 0036 if (count * 4 != shoe.numCards(T_R)) { 0037 std::cout << "[unused: RETURN 10: shoe.numCards(T_R)] = " << shoe.numCards(T_R) << "]\n"; 0038 return false; 0039 } 0040 0041 return true; 0042 } 0043 0044 void ShoeUtil::setTenRichness(Shoe *shoe, int n) 0045 { 0046 assert(shoe); 0047 assert(n <= 9); 0048 0049 using namespace RankLiterals; 0050 0051 for (Rank r = A_R; r < T_R; ++r) { 0052 shoe->setNumCardsOfRank(r, 9 - n); 0053 } 0054 0055 shoe->setNumCardsOfRank(T_R, 36); // 9 * 4 0056 } 0057 0058 Types::Double ShoeUtil::tenRichness(const Shoe& shoe) 0059 { 0060 using namespace RankLiterals; 0061 0062 int u = 0; // u == number of cards under 'T_R' 0063 0064 for (Rank r = A_R; r < T_R; ++r) { 0065 u += shoe.numCards(r); 0066 } 0067 0068 const int t = shoe.numCards(T_R); // t == number of 'T_R' cards 0069 0070 const int c = u + t; // c == total number of cards 0071 0072 assert(c == shoe.numCardsTotal()); 0073 0074 // t 4 0075 // - = ------ => (13 - n)t = 4c => 13t - nt = 4c => 13t - 4c = nt 0076 // c 13 - n 0077 // => 13t/t - 4c/t = n => n = 13 - 4c/t 0078 // 0079 0080 return 13 - 4.0 * c / t; 0081 } 0082 0083 } // namespace bjgb