Example #1
0
void GUI::draw(sf::RenderTarget* renderer)
{
    sf::Texture* heartTex = ResourceManager<Sprite>::instance().get("heart")->tex();
    sf::Sprite heart(*heartTex); heart.setOrigin(25, 22);
    for (int life(0); life<_player->getLife(); ++life)
    {
        heart.setPosition(_width-29, _height-29*(life+1));
        renderer->draw(heart);
    }

    _text.setPosition(10, _height-100);
    _text.setString(numberToString(_player->getScore()));
    _text.setColor(sf::Color::White);
    renderer->draw(_text);

    _text.setPosition(10, _height-40);
    _text.setString(numberToString(_player->getAccuracy())+" %");
    _text.setColor(sf::Color::White);
    renderer->draw(_text);

    if (_paused)
    {
        sf::RectangleShape hide(sf::Vector2f(_width, _height));
        hide.setFillColor(sf::Color(0, 0, 0, 200));
        _text.setString("PAUSE");
        _text.setPosition(_width/2-_text.getGlobalBounds().width/2, 200);

        renderer->draw(hide);
        renderer->draw(_text);
    }
}
Example #2
0
int32 problem52() {
  // Number cannot start with any digit but 1 since six times a number starting
  // with 2 will lead to a number that is one digit longer, which will be invalid.
  // We can extend this to the 2nd, 3rd, and 4th digits and so on.
  int32 nextPower = 100;
  int32 i = 10;
  while (true) {
    while (6 * i < nextPower) {
      string candidate = numberToString(i);
      sort(candidate.begin(), candidate.end());
      bool successful = true;
      for (int32 multiplier = 2; multiplier <= 6; multiplier++) {
        string sorted = numberToString(i * multiplier);
        sort(sorted.begin(), sorted.end());

        if (sorted != candidate) {
          successful = false;
          break;
        }
      }

      if (successful) {
        return i;
      }

      i++;
    }

    i = nextPower;
    nextPower *= 10;
  }

  throw string("A number satisfying the conditions could not be found");
}
Example #3
0
    char *WorldDescription::strTotalTests( char *s ) const
    {
        char *p = numberToString( numTotalTests(), s );

        if ( numTotalTests() <= 1 )
            return s;

        unsigned n = numTotalTests();
        unsigned numFactors = 0;

        for ( unsigned factor = 2; (factor * factor) <= n; factor += (factor == 2) ? 1 : 2 ) {
            unsigned power;

            for ( power = 0; (n % factor) == 0; n /= factor )
                ++ power;

            if ( !power )
                continue;

            p = numberToString( factor, copyString( p, (numFactors == 0) ? " = " : " * " ) );
            if ( power > 1 )
                p = numberToString( power, copyString( p, "^" ) );
            ++ numFactors;
        }

        if ( n > 1 ) {
            if ( !numFactors )
                copyString( p, tracker().failedTests() ? " :(" : tracker().warnings() ? " :|" : " :)" );
            else
                numberToString( n, copyString( p, " * " ) );
        }
        return s;
    }
Example #4
0
std::string
toHex2(uint64_t value, size_t nbits, bool show_unsigned_decimal, bool show_signed_decimal, uint64_t decimal_threshold) {
    assert(nbits>0 && nbits<=8*sizeof value);
    uint64_t sign_bit = ((uint64_t)1 << (nbits-1));

    // Hexadecimal value
    std::string retval;
    int nnibbles = (nbits+3)/4;
    char buf[64];
    snprintf(buf, sizeof buf, "0x%0*" PRIx64, nnibbles, value);
    buf[sizeof(buf)-1] = '\0';
    retval = buf;

    // unsigned decimal
    bool showed_unsigned = false;
    if (show_unsigned_decimal && value >= decimal_threshold) {
        retval = appendAsmComment(retval, numberToString(value));
        showed_unsigned = true;
    }

    // signed decimal
    if (show_signed_decimal) {
        if (0 == (value & sign_bit)) {
            // This is a positive value. Don't show it if we did already.
            if (!showed_unsigned && value >= decimal_threshold)
                retval = appendAsmComment(retval, numberToString(value));
        } else {
            // This is a negative value, so show it as negative.  We have to manually sign extend it first.
            int64_t signed_value = (value | (-1ll & ~(sign_bit-1)));
            retval = appendAsmComment(retval, numberToString(signed_value));
        }
    }
    return retval;
}
void sendFacialExpressionAnimation(SocketClient& sock, EmoStateHandle eState) {

	std::ostringstream output;

    IEE_FacialExpressionAlgo_t upperFaceType =
                            IS_FacialExpressionGetUpperFaceAction(eState);
    IEE_FacialExpressionAlgo_t lowerFaceType =
                            IS_FacialExpressionGetLowerFaceAction(eState);

	float upperFaceAmp = IS_FacialExpressionGetUpperFaceActionPower(eState);
	float lowerFaceAmp = IS_FacialExpressionGetLowerFaceActionPower(eState);

	if (IS_FacialExpressionIsBlink(eState)) {
		output << "B,";
	}

	if (IS_FacialExpressionIsLeftWink(eState)) {
		output << "l,";
	}

	if (IS_FacialExpressionIsRightWink(eState)) {
		output << "r,";
	}


	if (upperFaceAmp > 0.0) {
		switch (upperFaceType) {
			case FE_SURPRISE:	output << "b";	break;
			case FE_FROWN:    output << "f";  break;
			default:			break;
		}
		output << numberToString(static_cast<int>(upperFaceAmp*100.0f)) << ",";
	}

	if (lowerFaceAmp > 0.0) {
		switch (lowerFaceType) {
			case FE_CLENCH:	output << "G";	break;
			case FE_SMILE:		output << "S";	break;
			default:			break;
		}
		output << numberToString(static_cast<int>(lowerFaceAmp*100.0f)) << ",";
	}

	std::string outString = output.str();

	// Remove the last comma
	if (outString.length()) {
		outString.resize(outString.length()-1);
	}

	if (!outString.length()) {
		outString = std::string("neutral");
	}

	sock.SendBytes(outString);
}
Example #6
0
std::string IPEndpoint::V4::to_string () const
{
    std::string s;
    s.reserve (15);
    s.append (numberToString ((int)((*this)[0]))); s.push_back ('.');
    s.append (numberToString ((int)((*this)[1]))); s.push_back ('.');
    s.append (numberToString ((int)((*this)[2]))); s.push_back ('.');
    s.append (numberToString ((int)((*this)[3])));
    return s;
}
ParseBlock* TemporalConstrain::toBlock() const
{
  ParseBlock *ret = new ParseBlock;
  
  ret->setProperty("min_time", numberToString(min_time));
  ret->setProperty("max_time", numberToString(max_time));
  ret->setProperty("updraft_id", numberToString(updraft_id));
  
  return ret;
}
Example #8
0
QString PartialDate::asString() const
{
    if(!m_year)
    {
        return "????.??.??";
    }
    QString s = QString("%1.%2.%3")
            .arg(m_year, 4)
            .arg(numberToString(m_month))
            .arg(numberToString(m_day));
    return s;
}
Example #9
0
string 	
Convert::byteVectorToString(const vector<byte_t> &v) {
    if (v.empty())
        return "";
    else {
        string result;

        for (unsigned int i = 0; i < v.size() - 1; i++)
            result += "0x" + numberToString(v[i], 16, 2) + " ";
        result += "0x" + numberToString(v[v.size() - 1], 16, 2);

        return result;
    }
}
Example #10
0
std::string IPEndpoint::to_string () const
{
    switch (m_type)
    {
    case ipv4:
        {
            std::string s (m_v4.to_string());
            if (m_port != 0)
            {
                s.append (":");
                s.append (numberToString (m_port));
            }
            return s;
        }

    case ipv6:
        return m_v6.to_string();

    default:
    case none:
        bassertfalse;
        break;
    };
    return std::string();
}
Example #11
0
/**
 *  конвертировать длинную строку в список строк с переносом по словам, где длина каждой строки не больше max_string_length
 *  @param  max_string_length    максимальная длина каждой строки
 */
text_t  
Convert::stringToFixedWideText(string &str_source, const size_t max_string_length) {
    if (max_string_length > 256)
        throw Exception(EXCEPTION_CONVERT_BAD_INDEX, "Wrong max string length " + numberToString(max_string_length));

    string word;
    string line;
    text_t result;

    for (size_t i = 0; i < str_source.size(); i++) {
        if (str_source[i] == ' '  &&  !word.empty()) {
            if (word.size() + line.size() > max_string_length) {
                result.push_back(line);
                line.clear();
            }
            line += word + " ";
            word.clear();

        } else
            word += str_source[i];
    }

    if (!line.empty())
        result.push_back(line);

    return result;
}
Example #12
0
/* This function will update the level and the text related to it */
void nextLevel(CLevel& level, CText& text) {
    level.setLevel(level.getLevel()+1);
    level.setLenWord(level.getLenWord()+1);
    level.setPoints(level.getPoints()+level.getPoints());
    level.setPtsToNext(level.getPtsToNext()+level.getPtsToNext());
    text.setString("Level: "+numberToString(level.getLevel()));
}
Example #13
0
/*
 * receive bytes from the I2C bus.
 *
 * This function reads "length" number of bytes from the register "RegisterAddress" and stores them into the "RxBuf". At success the function returns 1, on failure -1.
 * @param RegisterAddress Address of the register you want to read from
 * @param RxBuf Receive buffer. The read bytes will be stored in it.
 * @param length Amount of bytes that will be read.
 * @return success: 1, failure: -1
 */
int i2cBus::receive(unsigned char RegisterAddress, unsigned char *RxBuf, int length){
    
	if (RxBuf == 0) {
		return errorMsg("Receive method received a null TxBuf pointer.\n");
    }
	if (length < 1) {
		return errorMsg("Receive method received an invalid buffer length.\n");
    }
	if (!file) {
		if (open_file() == -1) {
            return -1;
        }
    }
    
	error_flag=false;
    
	if (write(file, &RegisterAddress, 1) != 1) {
  		return errorMsg("i2c write error!\n");
    }
	if (read(file, RxBuf, length) != length) {
		return errorMsg("i2c read error! Address: " + numberToString(slave_address) + " dev file: " + devicefile + "\n");
    }
    
	return 1;
}
Example #14
0
void createLevel(CLevel& level, CText& levelText) {
    levelText.loadFont(FONT_PATH);
    levelText.setString("Level: "+numberToString(level.getLevel()));
    levelText.setCharacterSize(24);
    levelText.setColor(sf::Color::Magenta);
    levelText.setPosition(300,0);
}
char *charToString(unsigned long c, char *s)
{
    switch (c)
    {
    case '\\': return copyString(s, "\\\\");
    case '\"': return copyString(s, "\\\"");
    case '\'': return copyString(s, "\\\'");
    case '\0': return copyString(s, "\\0");
    case '\a': return copyString(s, "\\a");
    case '\b': return copyString(s, "\\b");
    case '\n': return copyString(s, "\\n");
    case '\r': return copyString(s, "\\r");
    case '\t': return copyString(s, "\\t");
    }
    if (c >= 32 && c <= 127)
    {
        s[0] = (char)c;
        s[1] = '\0';
        return s + 1;
    }
    else
    {
        s[0] = '\\';
        s[1] = 'x';
        if (c < 0x10)
        {
            s[2] = '0';
            ++ s;
        }
        return numberToString(c, s + 2, 16UL);
    }
}
Example #16
0
int main(int argc, char** argv)
{
	std::cout << "Largest palindrome product" << std::endl;
	std::cout << "--------------------------" << std::endl;

	int result = 0;
	int product = 0;
	std::pair<int, int> factors;
	for (int i = 999; i > 99; --i)
	{
		for (int j = 999; j > 99; --j)
		{
			product = i * j;
			if (isPalindrome(numberToString(product)))
			{
				if (product > result)
				{
					result = product;
					factors = std::make_pair(i, j);
				}
			}
		}
	}

	std::cout << "Largest palindrome product of two 3 digit numbers is :" << result << std::endl;
	std::cout << "The factors are: " << factors.first << ", " << factors.second << endl;

	return 1;
}
Example #17
0
String serializeForNumberType(double number)
{
    // According to HTML5, "the best representation of the number n as a floating
    // point number" is a string produced by applying ToString() to n.
    NumberToStringBuffer buffer;
    return String(numberToString(number, buffer));
}
Example #18
0
ParseBlock* GeneticConfig::toBlock() const
{
    ParseBlock *ret = resolution::CostConfig::toBlock();
    
    ret->setProperty("initializer_type", initializer_type);
    ret->setProperty("crossover_type", crossover_type);
    ret->setProperty("mutator_type", mutator_type);
    ret->setProperty("custom_evolution", boolToString(custom_evolution));
    ret->setProperty("search_ratio", numberToString(search_ratio));
    ret->setProperty("max_checks", numberToString(max_checks));
    ret->setProperty("mutation_probability", numberToString(pMutation));
    ret->setProperty("crossover_probability", numberToString(pCrossover));
    ret->setProperty("mutation_deviation", numberToString(mutation_dev));
    
    return ret;
}
Example #19
0
void ValueTraits<const double>::hugeNumber(double t) {
    char *s = doNegative(t);
    s = doubleToString(t, s, 0, 1);
    s = copyString(s, ".");
    s = doubleToString(t, s, 1, DIGITS_ON_RIGHT);
    s = copyString(s, "E");
    s = numberToString(requiredDigitsOnLeft(t) - 1, s);
}
Example #20
0
void ValueTraits<const double>::normalNumber( double t )
{
    char *s = doNegative( t );
    s = doubleToString( t, s );
    s = copyString( s, "." );
    for ( unsigned i = 0; i < DIGITS_ON_RIGHT; ++ i )
        s = numberToString( (unsigned)(t *= BASE) % BASE, s );
}
Example #21
0
std::string Problem013::getFirstNDigitsFromSumOfNumbers(int n, std::string nums) {
    std::vector<std::string> numbers = utils::split(nums, ' ');
    int carry = 0;
    std::string result = "";
    for (int i = 49; i >= 0; i--) {
        int count = 0;
        for (int j = 0; j < 100; j++) {
            count = count + (numbers[j][i] - '0');
        }
        result += (numberToString((carry + count) % 10));
        carry = (carry + count) / 10;
    }
    //Reverse the string
    result = std::string(result.rbegin(), result.rend());
    std::string answer = numberToString(carry);
    answer += (result);
    return answer.substr(0, n);
}
Example #22
0
void UIElement::setVolume(float f,float  current,string text)
{
	std::string temp = text + " " + numberToString(current*100) +"%";
	if (current >= 1)
	{
		AudioManager::instance()->resetVolume();
	}
	m_image = temp;
}
Example #23
0
text_t  
Convert::textToFixedWideText(const text_t &text_source, const size_t max_string_length) {
    if (max_string_length > 256)
        throw Exception(EXCEPTION_CONVERT_BAD_INDEX, "Wrong max string length " + numberToString(max_string_length));

    string str;

    for(size_t i = 0; i < text_source.size(); i++)
        str += text_source[i] + " ";

    return stringToFixedWideText(str, max_string_length);
}
Example #24
0
QString PartialDate::asShortString(int part) const
{
	if (!m_year)
		return QString();
	QString s;
	if (part & Year)
		s = numberToString(m_year, 4);
	if (!m_month)
		return s;
	if (part & Month) {
		if (!s.isEmpty()) s += '.';
		s += numberToString(m_month);
	}
	if (!m_day)
		return s;
	if (part & Day) {
		if (!s.isEmpty()) s += '.';
		s += numberToString(m_day);
	}
	return s;
}
void number_to_str(float number, char *str,int afterdecimal){
	if (number > 0){
		if (afterdecimal == 0){
			numberToString(number, str,0);
		}
		else{
			int nval = (int)number;
			float temp = (float)number - nval;
			int fval = multiply(temp, afterdecimal);
			numberToString(nval, str, 0);
			int l = length(str);
			str[l] = '.';
			numberToString(fval, str, l + 1);
		}
	}
	else{
		if (afterdecimal == 0){
			str[0] = '-';
			numberToString(number*-1, str, 1);
		}
		else{
			str[0] = '-';
			number *= -1;
			int nval = (int)number;
			float temp = (float)number - nval;
			int fval = multiply(temp, afterdecimal);
			numberToString(nval, str, 1);
			int l = length(str);
			str[l] = '.';
			numberToString(fval, str, l + 1);
		}
	}
}
Example #26
0
DMString& DMString::operator+(int number) {

	int targetLength = numberToString(number, number_string_buffer);

	if (this->max_length < this->used_length + targetLength) {
		this->resize(this->used_length + targetLength); //synchronous
	}

	reverse_memcpy(this->char_string + this->used_length, number_string_buffer, targetLength);
	this->used_length = this->used_length + targetLength;

	return *this;
}
Example #27
0
QString PartialDate::range(const PartialDate& d) const
{
	if (year() != d.year())
		return asShortString() + "-" + d.asShortString();
	QString result = numberToString(year());
	if (month() != d.month())
		return QString("%1.%2-%3").arg(year()).arg(asShortString(Month | Day))
				.arg(d.asShortString(Month | Day));
	else if (day() != d.day())
		return QString("%1.%2.%3-%4").arg(year()).arg(month())
				.arg(asShortString(Day)).arg(d.asShortString(Day));
	else return asShortString();
}
Example #28
0
string numberToString(int n){
	string r,t;

	if(n<0){
		t+='-';
		n*=-1;
	}
		
	if(n/10!=0) r=numberToString(n/10);
	t+=r;
	t+=(n-n/10*10+'0');

	return t;
}
Gnuplot::Gnuplot(Grid entry) {
	matrix vals = entry.get_values();
	fp = popen(GNUPLOT, "w");
	str = strStream.str();
	for (unsigned int y = 0; y < vals[0].size(); y++) {
		for (unsigned int x = 0; x < vals.size(); x++) {
			 datStream << vals[x][y].value << "	";
		}
		datStream << "\n";
	}
    data = datStream.str();
    int x_siz = vals.size() - 1;
    int y_siz = vals[0].size() - 1;
    double min = lowest_value(vals);
    double max = highest_value(vals);
    std::string s1 = std::string("set xrange [0:") + numberToString(x_siz) + std::string("]");
	add_command(s1);
	std::string s2 = std::string("set yrange [0:") + numberToString(y_siz) + std::string("]");
    add_command(s2);
    std::string s3 = std::string("set cbrange [") + numberToString(min) + std::string(":") + numberToString(max) + std::string("]");
    add_command(s3);

}
Example #30
0
YEP_PRIVATE_SYMBOL void yepJNI_ThrowSpecificException(JNIEnv *env, enum YepStatus errorStatus, jclass exceptionClass) {
	enum YepStatus status;
	YepSize bufferLength = BUFFER_SIZE - 1;
	char onStackBuffer[BUFFER_SIZE];
	status = yepLibrary_GetString(YepEnumerationStatus, errorStatus, YepStringTypeDescription, onStackBuffer, &bufferLength);
	if (status == YepStatusOk) {
		onStackBuffer[bufferLength] = '\0';
		(*env)->ThrowNew(env, exceptionClass, onStackBuffer);
		return;
	} else if (status == YepStatusInsufficientBuffer) {
		/* Dynamically allocate memory for string buffer */
#if defined(YEP_WINDOWS_OS)
		HANDLE heap = GetProcessHeap();
		char *heapBuffer = HeapAlloc(heap, 0, bufferLength + 1);
		if (heapBuffer != NULL) {
			status = yepLibrary_GetString(YepEnumerationStatus, errorStatus, YepStringTypeDescription, heapBuffer, &bufferLength);
			if (status == YepStatusOk) {
				heapBuffer[bufferLength] = '\0';
				(*env)->ThrowNew(env, exceptionClass, heapBuffer);
				HeapFree(heap, 0, heapBuffer);
				return;
			}
		}
#endif
	}
	/* Everything failed, but we don't */

	#if BUFFER_SIZE < 32
		#error "BUFFER_SIZE must be at least 32 to avoid buffer overflow"
	#endif
	/* A bit of junk code to avoid linking to LibC */
	onStackBuffer[0] = 'Y';
	onStackBuffer[1] = 'e';
	onStackBuffer[2] = 'p';
	onStackBuffer[3] = 'p';
	onStackBuffer[4] = 'p';
	onStackBuffer[5] = '!';
	onStackBuffer[6] = ' ';
	onStackBuffer[7] = 'e';
	onStackBuffer[8] = 'r';
	onStackBuffer[9] = 'r';
	onStackBuffer[10] = 'o';
	onStackBuffer[11] = 'r';
	onStackBuffer[12] = ' ';
	onStackBuffer[13] = '#';
	numberToString(&onStackBuffer[14], errorStatus);

	(*env)->ThrowNew(env, exceptionClass, onStackBuffer);
}