Ejemplo n.º 1
0
/**
 * @brief  Step through the main stages in the code.
 * @return Void
 */
void md14_main() {
  switch(md14_next_state)
  {
    case MD14_STATE_INTRO:
    	PRINTF("In intro state\n\r");
    	play_mp3(MODE_FILESET, "WELC");
    	lang_fileset = "ENG_";
		mode_fileset = "MD14";
		md14_next_state = MD14_STATE_LVLSEL;
		srand(timer_rand());
		break;

	case MD14_STATE_LVLSEL:
        md14_last_dot = create_dialog("LVLS", (DOT_1 | DOT_2));
        switch (md14_last_dot) {

        	case NO_DOTS:
        		break;

        	case '1':
        		play_mp3(LANGUAGE, "EASY");
        		strings_to_wordlist(easy, ARRAYLEN(easy), &md14_dict);
				print_words_in_list(&md14_dict);
        		play_mp3(MODE_FILESET, "INST");
        		md14_next_state = MD14_STATE_GENQUES;
        		break;

        	case '2':
        		play_mp3(LANGUAGE, "HARD");
        		strings_to_wordlist(medium, ARRAYLEN(medium), &md14_dict);
				print_words_in_list(&md14_dict);
        		play_mp3(MODE_FILESET, "INST");
        		md14_next_state = MD14_STATE_GENQUES;
        		break;

        	// todo: add case 3; figure out too-long words

        	default:
        		play_mp3(LANGUAGE, "INVP");
        		PRINTF("Invalid entry.");
				break;
		}
		break;

	case MD14_STATE_GENQUES:
		PRINTF("In genques state\n\r");
		md14_curr_mistakes = 0;
		get_next_word_in_wordlist(&md14_dict, &md14_chosen_word);
		sprintf(dbgstr, "[MD14] Next word: %s\n\r", md14_chosen_word->name);
		PRINTF(dbgstr);
		md14_next_state = MD14_STATE_PROMPT;
	  	break;

	 case MD14_STATE_PROMPT:
	 	PRINTF("In prompt state\n\r");
	 	play_mp3(LANGUAGE, "SPEL");
	 	speak_word(md14_chosen_word);
	 	md14_next_state = MD14_STATE_INPUT;
	 	break;

	case MD14_STATE_INPUT:
		md14_cell = get_cell();
		if (md14_cell == NO_DOTS) {
			break;
		}
		md14_cell_pattern = GET_CELL_PATTERN(md14_cell);
		md14_cell_control = GET_CELL_CONTROL(md14_cell);
		switch (md14_cell_control) {
			case WITH_ENTER:
			md14_user_cell.pattern = md14_cell_pattern;
			md14_next_state = MD14_STATE_CHECK;
			PRINTF("[MD14] Checking answer\n\r");
			break;
			case WITH_LEFT:
			md14_next_state = MD14_STATE_REPROMPT;
			break;
			case WITH_RIGHT:
			stats();
			md14_next_state = MD14_STATE_GENQUES;
			break;
			case WITH_CANCEL:
			break;
		}
		break;

	case MD14_STATE_CHECK:
		get_next_cell_in_word(md14_chosen_word, &md14_curr_cell);
		sprintf(dbgstr, "In check state. Current cell: %x, user cell: %x.\n\r", md14_curr_cell.pattern, md14_user_cell.pattern);
		PRINTF(dbgstr);

		if (cell_equals(&md14_curr_cell, &md14_user_cell)) {
			md14_curr_mistakes = 0;
			if (md14_chosen_word->curr_letter == md14_chosen_word->num_letters - 1) { // done
				correct_answer();
			  	md14_next_state = MD14_STATE_GENQUES;
			}
			else {// correct but not done
				play_mp3(LANGUAGE, "GOOD");
				play_mp3(LANGUAGE, "NLET");
				md14_next_state = MD14_STATE_INPUT;
			}
		}
		else {// incorrect letter
			incorrect_answer(); // @todo mark invalid letters invalid
			md14_next_state = MD14_STATE_REPROMPT;
		}
		break;

	case MD14_STATE_REPROMPT:
		PRINTF("In reprompt state\n\r");

		if (md14_curr_mistakes >= MAX_INCORRECT_GUESS) {
			play_mp3(LANGUAGE, "PRSS");
			play_pattern(md14_curr_cell.pattern);
		}
		else {
			play_mp3(LANGUAGE, "SPEL");
	 		speak_word(md14_chosen_word);
	 		if (md14_chosen_word->curr_glyph > -1) {// not at beginning of word
	 			play_mp3(MODE_FILESET, "SPLS");
	 			speak_letters_so_far(md14_chosen_word);
	 		}
	 	}
	 	md14_next_state = MD14_STATE_INPUT;
	 	break;

	default:
		break;
  }
}
Ejemplo n.º 2
0
void main(void)
{
	Sys_Init();      			// System Initialization
	Port_Init();     			// Initialize ports 2 and 3
	Interrupt_Init();			//Initialize Interrupts
	Timer_Init();				//Initialize timer 0
	putchar(' ');    			// the quote fonts may not copy correctly into SiLabs IDE


		
 		BILED0=0;	//Turn OFF the BILED
		BILED1=0;
		printf("\r\nStart");
		while(1)	
		{	

			printf("\r\n\n Press any key to begin");	//get a number to randomize the random number even more
			keyinput=getchar();
			
			previous_num=keyinput%3;
			
			
			printf("\r\n This game will light 1 or both leds. Press the corresponding button to win.");	
			while (i<=9)
			{
					if(!SS)
					{
						TR0 = 1;			//start timer0
						TL0 = 0;			//clear low bits
						TH0 = 0;			//clear high bits
						Counts = 0;			//set the counts to 0
					random_num = random();					//create a random number. where random_num is a 
					while (random_num==previous_num)
					{
						random_num = random();
					}							//check to see if the random number was used before
					
						if (random_num==0)
						{						//light LED0 for 1 second
							Counts=0;
							LED0=0;					//turn it on
							while (Counts<338); 			//wait 1 second
							LED0=1; 				//turn it off
							if (PB1==0 && PB2==1)
							{
								correct_answer();		//store correct answer;
							}
							else
							{
								incorrect_answer();
							}
						}
						else if (random_num==1)
						{						//light LED1 for 1 second
							Counts=0;
							LED1=0; 				//turn it on
							while (Counts<338); 			//wait 1 second
							LED1=1; 				//turn it off
							if (PB1==1 && PB2==0)
							{
								correct_answer();
							}
							else
							{
								incorrect_answer();
							}	
						}
						else 						//this means that the random number is 2
						{						//light LED0 and LED1 for 1 second
							Counts=0;
							LED0=0;
							LED1=0;
							
							while (Counts<338);
							LED0=1;
							LED1=1;
							if (PB1==0 && PB2==0)
							{
								correct_answer();
							}
							else
							{
								incorrect_answer();
							}
						}
						

						previous_num=random_num;
						i++;									//increment i
					}
					else
					{
						TR0=0; //END
					}

			}
		
			TR0 = 0;								//turn off timer
			printf("\r\n Number of correct answers = %d", number_correct);		//display results
			while (!SS);							//wait until the switch is turned off and back on again to loop
		}	
}
// Runs program with input from test files in testFiles vector.
void TestSuite::runTests()
{
    int numCorrect = 0, numWrong = 0;
    int i;
    string name;
    string logName;
    string stored_dir;
    double rate;
    bool crit = false;
    string crit_string = "crit.tst";
    bool crit_passed = true;
    char buff[40];
    int chpid = 45;
	
    //Get directory of current program
    i = testProgram.rfind('.');
    testProgram = testProgram.substr(0, i);

    // Create log file.
    logName = testProgram + "-";
    logName += exeTime;
    logName += ".log";
    ofstream fout(logName.c_str());
    if (!fout)
    {
        return;
    }

    // Iterate over test files.
    vector<string>::iterator it;
    for ( it = testFiles.begin(); it != testFiles.end() ; it++ )
    {

        //Determine if this is a critical test
        if(it->find(crit_string) != string::npos)
        {
            crit = true;
        }

        // Get test file name without path.
        size_t pos = it->rfind("/");
        if(pos != std::string::npos)
        {
            name = it->substr(pos+1,it->length());
        }

        // Output test file name to log file.
        fout << name;


        // Run program with given test file.
        run_code(*it,name);

		//else, do a failed program log file i supposd

        // Determine corresponding answer file.
        string ans = *it;
        ans.replace(ans.end()-4, ans.end(),answerExtension);

        // Output results.
        if (correct_answer(ans))
        {
            numCorrect++;
            fout << ": PASS" << endl;
        }
        else
        {
            //If this was a crit test, they auto fail
            if(crit)
            {
                crit_passed = false;
            }
            numWrong++;
            fout << ": FAIL" << endl;
        }

    }



    //If all possible crit tests were passed
    if(crit_passed)
    {
        // Output pass and fail stats.
        rate = ( numCorrect / (double)(numCorrect + numWrong) ) * 100;
        fout << rate <<  "% CORRECT," << numCorrect << " PASSED," << numWrong << " FAILED";
        sprintf(buff, "  %f%% Correct\n", rate);
        i = testProgram.rfind('/');
        studentResults.push_back(testProgram.substr(i+1) + string(buff));
    }
    else
    {
        //If one or more were not passed
        fout << "Failed: Did not pass one or more acceptance tests (Labeled as crit)" << endl;
        i = testProgram.rfind('/');
        studentResults.push_back(testProgram.substr(i) + "  FAILED\n");
    }


    fout << "\n" <<  get_gcov(testProgram) << endl;
    fout.close();
    if(profiling)
        get_gprof(testProgram);
}