Пример #1
0
int CHandresetDetector::BitVectorFiringHandresetMethods() {
  int handresetmethods_fired = 0;
  // Build a bit-vector of handresetmethods that fire
  // Highest (9th) bit is for first method
  handresetmethods_fired |= (IsHandresetByDealerChair() ? 1 : 0);
  handresetmethods_fired <<= 1;
  handresetmethods_fired |= (IsHandresetByUserCards() ? 1 : 0);
  handresetmethods_fired <<= 1;
  handresetmethods_fired |= (IsHandresetByHandNumber() ? 1 : 0);
  handresetmethods_fired <<= 1;
  handresetmethods_fired |= (IsHandresetByCommunityCards() ? 1 : 0);
  handresetmethods_fired <<= 1;
  handresetmethods_fired |= (IsHandresetByPotsize() ? 1 : 0);
  handresetmethods_fired <<= 1;
  handresetmethods_fired |= (IsHandresetByNopponentsplaying() ? 1 : 0);
  handresetmethods_fired <<= 1;
  handresetmethods_fired |= (IsHandresetByIncreasingBalance() ? 1 : 0);
  handresetmethods_fired <<= 1;
  handresetmethods_fired |= (IsHandresetByChangingBlindLevel() ? 1 : 0);
  handresetmethods_fired <<= 1;
  handresetmethods_fired |= (IsHandresetByNewSmallBlind() ? 1 : 0 );
  // No shift-left after the last bit
  write_log(preferences.debug_handreset_detector(), "[CHandresetDetector] Methods firing this heartbeat: %s\n",
    IntToBinaryString(handresetmethods_fired, kNumberOfHandresetMethods));
  return handresetmethods_fired;
}
CString CParseTreeTerminalNodeNumber::EvaluateToString(bool log /* = false */) {
  double numerical_result = Evaluate(log);
  CString result;
  if (IsInteger(numerical_result) && EvaluatesToBinaryNumber()) {
    // Generqate binary representation;
    result.Format("%s", IntToBinaryString(int(numerical_result)));
  } else {
    // Generate floating-point representation
    // with 3 digits precision
    result.Format("%.3f", numerical_result);
  }
  return result;
}
Пример #3
0
//---------------------------------------------------------------------------
void IntToDecHexBinString(
        int iValue,      // [in] value to be converted
        int num_base,    // [in] 2=binary, 10=decimal, 16=hex
        int nDigits,     // [in] number of fixed digits, 
                         //      0=variable length without leading zeroes
        char *psz40Dest) // [out] string, expect up to 33(!) bytes
  // Converts an integer into a binary representation (string).
  // Beware: nDigits=0 means 'as many digits as necessary'.
  //         For a 32-bit integer, the binary representation (string) may
  //         be up to 32 characters long, plus one byte for the trailing zero !
  //   Thus, for safety, psz40Dest should be a buffer with up to 40 characters.
{
  char sz7Format[8] = "%d";
  switch( num_base )
   { case 2: // binary: not supported by printf.c : sprintf() -> tfp_format() 
        IntToBinaryString( iValue, nDigits, psz40Dest );
        return;
     case 10:
        if( nDigits>0 )
         { sprintf( sz7Format+1, "%dd", nDigits );
         }
        else
         { // default ("%d") already set
         }
        break;
     case 16:
        if( nDigits>0 )
         { sprintf( sz7Format+1, "0%dX", nDigits ); // note the leading ZERO
         }
        else
         { strcpy(  sz7Format+1, "%X" ); // note the absence of a leading zero
         }
        break;
     default:  // whatever the intention was, it's not supported here yet:
        sprintf( psz40Dest, "?base%d?", num_base );
        return;
   }
  // Arrived here ? Should be something supported by the
  //      small-footprint implementation of sprintf in printf.c  !
  sprintf( psz40Dest, sz7Format, iValue );
} // end IntToDecHexBinString()
Пример #4
0
void CHandresetDetector::CalculateIsHandreset() {
  // We work with bit-vectors here and not simple counters,
  // because we want to make sure that at least N *different*
  // fired during the last 3 heartbeats.
	
  // Last 2 heartbeats
  _methods_firing_the_last_three_heartbeats[2] = _methods_firing_the_last_three_heartbeats[1];
  _methods_firing_the_last_three_heartbeats[1] = _methods_firing_the_last_three_heartbeats[0];
  // This heartbeat
  _methods_firing_the_last_three_heartbeats[0] = BitVectorFiringHandresetMethods();
  // Composed result
  int total_methods_firing = _methods_firing_the_last_three_heartbeats[2]
    | _methods_firing_the_last_three_heartbeats[1]
    | _methods_firing_the_last_three_heartbeats[0];
  write_log(preferences.debug_handreset_detector(), "[CHandresetDetector] Methods firing last 3 heartbeat2: %s\n",
    IntToBinaryString(total_methods_firing));
  int number_of_methods_firing = bitcount(total_methods_firing);
  write_log(preferences.debug_handreset_detector(), "[CHandresetDetector] Number of methods firing last 3 heartbeat2: %i\n",
    number_of_methods_firing);
  if (number_of_methods_firing >= 2) {
    write_log(preferences.debug_handreset_detector(), "[CHandresetDetector] Handreset found\n");
    _is_handreset_on_this_heartbeat = true;
    ++_hands_played;
    if (p_symbol_engine_active_dealt_playing->nopponentsdealt() == 1) {
      // Last hand (data not yet reset) was headsup
      ++_hands_played_headsup;
    } else {
      _hands_played_headsup = 0;
    }
    // Clear data to avoid multiple fast handreset with already used methods, 
    // if casino needs several heartbeats to update table view.
    _methods_firing_the_last_three_heartbeats[0] = 0;
    _methods_firing_the_last_three_heartbeats[1] = 0;
    _methods_firing_the_last_three_heartbeats[2] = 0;
  } else {
    write_log(preferences.debug_handreset_detector(), "[CHandresetDetector] No handreset\n");
    _is_handreset_on_this_heartbeat = false;
  }
}
Пример #5
0
bool HuffmanCoder::GenerateLengthLimitedHuffman(unsigned int maxCodeLength, unsigned int numberOfWords) {
    if (mDebug > kInfo) std::cout << "INFO: Generating length-limited Huffman codes." << std::endl;

    if (!mHuffmanTableExists) {
        if (mDebug > kError) std::cerr << "ERROR: Can't generate length-limited Huffman table because no Huffman table exists." << std::endl;
        return false;
    }

    mLLMaxCodeLength = maxCodeLength;
    mLLNumberOfWords = numberOfWords;

    /*
     * To generate the length-limited Huffman codes, the so called package-merge algorithm is used.
     */


    // 1) fill map with (one-element) vectors containing the value of the Huffman codes,
    // sorted by their weight
    std::multimap<float, std::vector<int> > LengthLimitedHuffmanMap;
    for (std::map<unsigned int, HuffmanCode>::iterator it = mHuffmanTable.begin(); it != mHuffmanTable.end(); ++it) {
        std::vector<int> vec(1,it->second.value);
        LengthLimitedHuffmanMap.insert(std::pair<float,std::vector<int> >(it->second.weight, vec));
    }

    // Delete elements with the lowest weight from the map again until the the length of the map is
    // at the given limit. The weights are added for the marker.
    float weightOfRawDataMarker = 0;
    while (LengthLimitedHuffmanMap.size() >= mLLNumberOfWords) {
        weightOfRawDataMarker += LengthLimitedHuffmanMap.begin()->first;
        LengthLimitedHuffmanMap.erase(LengthLimitedHuffmanMap.begin());
    }
    std::vector<int> vec(1,-1);
    LengthLimitedHuffmanMap.insert(std::pair<float,std::vector<int> >(weightOfRawDataMarker, vec));
    int SizeOfSourceAlphabet = LengthLimitedHuffmanMap.size();

    // check wether the given alphabet fits into the given max. code range
    if (mLLMaxCodeLength < log(SizeOfSourceAlphabet)/log(2.)) {
        if (mDebug > kWarning) std::cout << "WARNING: The alphabet doesn't fit into the given maximum code length  of " << mLLMaxCodeLength << ". The max. code length has to be greater than / equal to " << log(SizeOfSourceAlphabet)/log(2.) << ". No length-limited Huffman table was generated." << std::endl;
        return false;
    }

    // 2) proceed with the actual package-merge algorithm
    std::multimap<float, std::vector<int> > mergedMap = PackageMerge(LengthLimitedHuffmanMap, mLLMaxCodeLength- 1);

    // calculate code lengths out of the occurence of the symbols according to the package-merge algorithm
    std::multiset<HuffmanCode,HuffmanCodeCompareCodelength> codeSet;
    for (int i = -1; i < (int) mHuffmanRange; i++) {
        int occurence = 0;
        std::multimap<float, std::vector<int> >::iterator it = mergedMap.begin();
        for (int set = 0; set < (2*SizeOfSourceAlphabet - 2); set++) {
            occurence += std::count(it->second.begin(), it->second.end(), i);
            ++it;
        }
        if (occurence == 0) continue;

        if (i < 0) {
            // raw data marker
            mLLRawDataMarkerSize = occurence;
        } else {
            // rest
            HuffmanCode hCode(i, occurence, mHuffmanTable[(unsigned int) i].weight, "");
            codeSet.insert(hCode);
        }
    }

    std::cout << mLLRawDataMarkerSize << std::endl;
    // manipulate the code lengths in order to allow to fix the length of the raw data marker
    if (mLLRawDataMarkerFixedSize != 0 || mLLRawDataMarkerMaxSize != 0) {

        // set the target size of the raw data marker
        unsigned int targetSize;
        if (mLLRawDataMarkerFixedSize != 0)
            targetSize = mLLRawDataMarkerFixedSize;
        else if (mLLRawDataMarkerSize > mLLRawDataMarkerMaxSize)
            targetSize = mLLRawDataMarkerMaxSize;
        else
            targetSize = mLLRawDataMarkerSize;

        if (targetSize != mLLRawDataMarkerSize) {

            // check if intended length is possible, if not, set it to a possible value
            if (targetSize < codeSet.begin()->length) {
                if (mDebug > kWarning) std::cout << "WARNING: Marker is too short. Instead of " << targetSize << " it is set to " << codeSet.begin()->length << std::endl;
                targetSize = codeSet.begin()->length;
            } else if (targetSize > mLLMaxCodeLength) {
                if (mDebug > kWarning) std::cout << "WARNING: Inserted marker size is longer than max code length of length-limited Huffman. It is set to the maximum length of " << mLLMaxCodeLength << std::endl;
                targetSize = mLLMaxCodeLength;
            }

            // until length is not reached, exchange the length of the marker with the length of and
            // element wich comes next in the direction to the intended length
            while (targetSize != mLLRawDataMarkerSize) {
                unsigned int lengthToFind =
                    (targetSize > mLLRawDataMarkerSize)
                    ? (mLLRawDataMarkerSize+1)	// increase the length
                    : (mLLRawDataMarkerSize-1);	// decrease the length

                //			std::multiset<HuffmanCode,HuffmanCodeCompareCodelength>::iterator lastInsertedElement = codeSet.end();
                bool parterFound = false;
                for (std::multiset<HuffmanCode,HuffmanCodeCompareCodelength>::iterator it = codeSet.begin(); it != codeSet.end(); ++it) {
                    // find partner to swap
                    if (it->length == lengthToFind) { // && it != lastInsertedElement) {
                        parterFound = true;

                        // make a copy and delete it from the set
                        HuffmanCode h_code = *it;
                        codeSet.erase(it);

                        // swap the lengths
                        h_code.length = mLLRawDataMarkerSize;
                        mLLRawDataMarkerSize = lengthToFind;

                        // insert the changed code back into the set and save a pointer to
                        // this element to avoid pushing the same element through the whole list
                        codeSet.insert(h_code);
                        //lastInsertedElement = codeSet.insert(h_code);

                        // stop the for loop
                        it = codeSet.end();
                        it++;
                    }
                }
                if (!parterFound) {
                    if (mDebug > kWarning) std::cout << "WARNING: Could not find another partner to swap, raw marker has now a length of " << mLLRawDataMarkerSize << std::endl;
                    break;
                }
            }
        }
    }

    // 3) generate actual Huffman codes out of the lengths of the codes
    bool processMarker = false;
    int length;
    int previousValue = -1;
    int previousCodeLength = -1;
    bool markerIncluded = false;
    for (std::multiset<HuffmanCode,HuffmanCodeCompareCodelength>::iterator it = codeSet.begin(); it != codeSet.end(); ++it) {
        if (it->length >= mLLRawDataMarkerSize && !markerIncluded) {
            it--;
            length = mLLRawDataMarkerSize;
            processMarker = true;
            markerIncluded = true;
        } else {
            length = it->length;
            processMarker = false;
        }
        if (previousCodeLength == -1) previousCodeLength = length;

        std::string code = IntToBinaryString((previousValue+1) << (length - previousCodeLength), length);
        if (processMarker) {
            mLLRawDataMarker = code;
        } else {
            HuffmanCode h_code = (*it);
            h_code.code = code;
            if (mLengthLimitedHuffmanTable.find(h_code.value) == mLengthLimitedHuffmanTable.end()) {
                mLengthLimitedHuffmanTable[h_code.value] = h_code;
            } else {
                if (mDebug > kWarning) std::cout << "WARNING: Huffman code for value " << h_code.value << " exists already in length-limited Huffman table" << std::endl;
            }
        }

        previousValue = (previousValue + 1) << (length - previousCodeLength);
        previousCodeLength = length;
    }

    mLengthLimitedHuffman = true;
    mMapToUse = &mLengthLimitedHuffmanTable;
    mMarkerToUse = mLLRawDataMarker;
    mMarkerLengthToUse = mLLRawDataMarkerSize;

    return true;
}