Пример #1
0
void SimonLogic::newUserInput(int input)
{
    //If user click right button, then move to next
    if(input==pattern[playerInputCount])
    {
        playerInputCount++;
        emit updateProgress((int)(playerInputCount*100/pattern.size()));
    }
    else
    {
        emit updateScore(0);
        //Else, emit the signal to indicate losing
        if(score>highScore)
            highScore=score;
        emit loss(highScore);
    }
    //Starting new round
    if(playerInputCount==pattern.size()){
        playerInputCount=0;
        score+=pattern.size()*100;
        //The flasing frequency would be faster in every new term
        if(frequency>300)
            frequency-=100;
        emit updateScore(score);

        addToPattern();
        emit newPattern(pattern,frequency);
    }

}
Пример #2
0
void SimonLogic::startGame()
{
    score=0;
    playerInputCount=0;
    frequency=1000;
    pattern.clear();
    addToPattern();//Add first pattern
    addToPattern();
    emit updateScore(score);
    emit newPattern(pattern, frequency);
}
Пример #3
0
// todo implement substitution
Object * parsePattern(Collector * c, Tokenizer * tt) {
	if (tokenizerNext(tt) != TOK_NUMBER) goto fail;
	double dcol = tt->c.number;
	if (tokenizerNext(tt) != TOK_COMMA) goto fail;
	if (tokenizerNext(tt) != TOK_NUMBER) goto fail;
	double drow = tt->c.number;
	if (tokenizerNext(tt) != TOK_RBRACKET) goto fail;

	if (!checkInteger(dcol)) goto fail;
	if (!checkInteger(drow)) goto fail;
	Object * pattern = (Object *) newPattern(c, (int) dcol, (int) drow);
	if (!pattern) goto fail;
	return pattern;

fail:
	return NULL;
}
Пример #4
0
/**
 * loadPattern
 * Loads a pattern from file filename
 * The format of the file is the format used by Rob Kassel
 * in his PhD-thesis: A comparison of Approaches to On-line
 * Handwritten Character Recognition
 **/
Pattern *
loadPattern( char *filename )
{
    FILE *fp;
    Point po;
    int lineno = 0, readingStroke = 0, foundAscii = 0, tmp;
    char line[80], ascii = 0, *ptr;
    Pattern *p = newPattern( 30, 'a' ), *tp;

    if ( p == NULL )
	return NULL;

    fp = fopen( filename, "r" );
    if ( fp == NULL )
	return NULL;
    
    while ( fgets( line, 80, fp ) != NULL )
    {
	lineno++;
	if ( strstr( line, ".COMMENT" ) != NULL && 
	     strstr( line, "Prompt" ) != NULL )
	{
	    ptr = strchr( line, '"' );
	    if ( ptr == NULL )
	    {
		fprintf( stderr, "Parse error in %s on line %d\n",
			 filename, lineno );
		continue;
	    }

	    ascii = ptr[1];
	    if ( ascii == '#' )
	    {
		sscanf( ptr + 2, "%d", &tmp );
		ascii = (char) tmp;
	    }
	    foundAscii = 1;
	}

	if ( !readingStroke )
	{
	    if ( strstr( line, ".PEN_DOWN" ) )
		readingStroke = 1;
	}
	else
	{
	    if ( strlen( line ) > 0 && !isdigit( line[0] ) )
		readingStroke = 0;
	    
	    if ( strlen( line ) > 0 && isdigit( line[0] ) )
	    {
		if ( sscanf( line, "%d %d", &po.x, &po.y ) != 2 )
		{
		    fprintf( stderr, "Parse error in %s on line %d\n",
			     filename, lineno );
		    continue;
		}   
		po.y = 3058 - po.y;
		addPoint( p, po );
	    }
	}
    }
    fclose( fp );
    if ( !foundAscii || p->nPoints == 0 )
    {
	deletePattern( p );
	p = NULL;
    }
    else
    {
	tp = apply( preprocessor, p );
	deletePattern( p );
	p = tp;
    	p->ascii = (unsigned char) ascii;
	calcSlopes( p );
    }
    return p;
}
Пример #5
0
/** 
Function to extract individual or a subset of file.

@internalComponent
@released

@param aData - ROM/ROFS image buffer pointer.
*/
void ImageReader::ExtractFileSet(char* aData)
{
	FILEINFOMAP fileInfoMap;
	string dirSep(DIR_SEPARATOR), backSlash("\\"), Pattern;
	TUint extfileCount = 0, noWcardFlag = 0, pos;

	//Get the filelist map
	GetFileInfo(fileInfoMap);

	//Check for wildcards
	pos = iPattern.rfind("\\");
	if(pos == string::npos)
	{
		pos = iPattern.rfind("/");
		if(pos == string::npos)
			pos = 0;
	}
	pos = iPattern.find_first_of("*?", pos);
	if(pos == string::npos)
	{
		noWcardFlag = 1;
	}

	//Process the map
	if(fileInfoMap.size() > 0)
	{
		FILEINFOMAP::iterator begin = fileInfoMap.begin();
		FILEINFOMAP::iterator end = fileInfoMap.end();

		// Replace all backslashes with forward slashes
		Pattern = iPattern;
		FindAndReplaceString(Pattern, backSlash, dirSep);

		// Insert root directory at the beginning if it is not there
		pos = Pattern.find_first_not_of(" ", 0);
		if(pos != string::npos)
		{
			if(Pattern.at(pos) != *DIR_SEPARATOR)
				Pattern.insert(pos, dirSep);
		}

		// Assign CWD for destination path if it is empty
		if(ImageReader::iZdrivePath.empty())
			ImageReader::iZdrivePath.assign(".");

		while(begin != end)
		{
			int status = 0;
			PFILEINFO pInfo = 0;
			string fileName = (*begin).first;
			pInfo = (*begin).second;

			// First match
			status = FileNameMatch(Pattern, fileName, (iDisplayOptions & RECURSIVE_FLAG));

			// If no match
			if((!status) && noWcardFlag)
			{
				string newPattern(Pattern);

				// Add * at the end
				if(newPattern.at(Pattern.length()-1) != *DIR_SEPARATOR)
				{
					newPattern.append(DIR_SEPARATOR);
				}
				newPattern += "*";
				status = FileNameMatch(newPattern, fileName, (iDisplayOptions & RECURSIVE_FLAG));

				// If it matches update the pattern and reset wildcard flag
				if(status)
				{
					Pattern = newPattern;
					noWcardFlag = 0;
				}
			}

			if(status)
			{
				// Extract the file

				// Separarate the path and file name
				string fullPath = fileName.substr(0, fileName.rfind(DIR_SEPARATOR));
				string file = fileName.substr(fileName.rfind(DIR_SEPARATOR)+1, fileName.length());
				FindAndReplaceString(fullPath, dirSep, backSlash);

				// Extract only those files exists in the image
				if(pInfo->iSize && pInfo->iOffset)
				{
					ExtractFile(pInfo->iOffset, pInfo->iSize, file.c_str(), fullPath.c_str() , 
						&ImageReader::iZdrivePath[0], aData);

					extfileCount++;
				}
			}

			if(pInfo)
				delete pInfo;
			++begin;
		}
		fileInfoMap.clear();
	}

	// Throw error if the extracted file count is zero
	if(!extfileCount)
	{
		throw ImageReaderException((char*)ImageReader::iImgFileName.c_str(), "No matching files found for the given pattern");
	}
}